Shark fin or tail fin
Shark fin in Formula 1 or tail fin in other classes provides more space for advertising (!), but performance wise it is said to make the rear of the car (diffuser) and rear wing more effective by proving a barrier to stop air crisscrossing from one side of the engine cover to the another, acts as a flow straightener, by aligning the airflow towards the rear wing reducing turbulent air off the back of the airbox unit, and therefore 'cleaning' the air that enters the rear wing area, making the wing much more effective. That's why shark fin will provide stability at the rear when going through high speed corners. Device also acts like a wind vane and its side surface area prevents yaw (tail slide), which helps with stability into turns. It doesn't really do anything to the aero at low speed corners. Furthermore, they don't in themselves make the cars more stable during cornering, but under braking they do reduce yaw and thus increase stability. It better manages airflow close to the engine cover, and in particular reduces turbulence generated by spillage from the engine air inlets (more about air spillage from the airbox you can learn here).
Shark fins gained popularity a couple of years ago, initially in 2009 with the reduction in downforce from the new aero rules and then in 2010 when the shark fin contained the F-duct airpipe. During this period teams extended the fin to join with the rear wing, creating both a larger surface area and a more direct path for the air to the rear wing. With the ban on F-ducts the FIA chose to create an exclusion area for bodywork ahead of the rear wing. This prevented the fin reaching the rear wing. In 2011 two teams tried truncated fins, Red Bull launched with one, but soon dropped their fin, while HRT chose to run the fin for much of the year.
But anyway, the aero benefits are not very clear. Some teams running the fin say it helps to clean up the air flow over the rear wing, some others say it helps the balance of the car, some say it does not bring as much benefit as some other say. All depends on implementation and sync with the rest of the car. One thing most people agree on however is that the fin shaped engine cover provides nice advertising space.
The shark fin supposedly makes the car more streamlined, but Mercedes saw it as unnecessary extra weight. During tests in the wind tunnel they found that the shark fin design also split the air and can cause 3% of the center of the rear wing to become redundant, meaning that the rear wing wouldn't create as much downforce as it could without the extended shark fin making the car heavily unstable in certain areas of the track. That’s why some teams have shark fin detached from rear wing (short shark fin), and others connected with rear wing (full length shark fin).
A problem with the shark fin is that presumably handling will be changed if there was a cross wind. It could make the car unstable and the driver forced to make usually unnecessary steering adjustments to keep his car on the track. As you know wind does affect F1 cars and if a wind is side on it can cause the opposite of desired effect destabilizing the rear. The fin will make the car sensitive to side winds and if the car does start to yaw then the rear wing will be partially masked by the fin and may result in loss of downforce and a spin.
Full shark fin was banned from Formula 1 on the end of 2010 season. As you can see on Ferrari picture above, they start to use shark fin with inside ducting to feed F-Duct. To prevent such controversy, FIA decided to ban shark fins connected with the rear wing.
The Mercedes 2012 iteration of the fin is much like the 2011 RBR\HRT design, with the fin reaching the maximum allowable height and extending as far back as allowed. So despite the belief amongst many fans that the fin was made illegal, this truncated version remains perfectly legal. One additional benefit bearing in mind the Drag Reduction Device (DRS) they have also tested, is the flow straightening effect will especially useful to ensure the airflow to the rear wing is correctly aligned. To a lesser extent the shark fin will improve rear downforce due to the straightened flow aimed at the rear wing, also if the rear end has moving about on corner entry, the lateral scrub can overwork the tyres, which the fin will help prevent. So both potential benefits of the fin will be useful for the team.
Its not only Formula one in love with some fancy stuff like this. You can see it in other classes too. Here on the picture you can see Audi R18 LMP prototype car from 2011. They are using it from same reasons as F1, as they explained, for added stability in high speed corners and reduced sensibility on yaw during the braking.