Skip to content

Latest commit

 

History

History
18 lines (12 loc) · 1.26 KB

What are Algorithms.markdown

File metadata and controls

18 lines (12 loc) · 1.26 KB

What are algorithms and data structures?

An algorithm is a recipe for making the computer do something. If you know how to cook, you understand algorithms!

Here's a recipe for pancakes:

  1. In a large bowl, sift together flour, baking powder, salt and sugar.
  2. Pour in the milk, egg, and melted butter.
  3. Mix until smooth.
  4. Heat a frying pan over medium heat.
  5. Scoop the batter into the pan, using approximately 1/4 cup for each pancake.
  6. Brown the pancake on both sides.

The recipe consists of a series of steps that you perform one after the other. An algorithm is just like that, except that it contains instructions for a computer to perform, not for a cook.

The ingredients -- flour, milk, eggs, butter -- are the data that the algorithm works on. The data goes into the algorithm in one form (raw, separate ingredients) and comes out in another (delicious pancakes!).

So what are the data structures? They are the containers that hold the data while the algorithm works on it. In the pancake recipe, the data structures are the bag that holds the flour, the mixing bowl where you combine everything, the frying pan that browns the pancake, and finally the plate used to serve the finished pancake.