Introduction to Algorithms!

Written By: Saniya Kalamkar

As computer science is the study of algorithms, algorithms are an important concept to understand. One definition is that algorithms are an ordered sequence of instructions guaranteed to solve a problem. Though used in computer science, algorithms are found everywhere in our daily lives. For example, cake recipes and the process of washing dishes can all be algorithms. An algorithm for making peanut butter jelly sandwiches might look like this:

  1. Take two slices of bread, peanut butter, and jelly out.

  2. Put jelly on one slice of bread

  3. Put peanut butter on the other slice of bread

  4. Put the two slices together, so that peanut butter and jelly are on the inside of the sandwich.

While this is a basic example of a real life algorithm, you’ll find that once broken down, most algorithms are very simple and easy to understand. This is largely due to pseudocode. Pseudocode represents algorithms. While algorithms could be written in natural language or in code, both would be hard to understand. In natural language (the way I am writing this article), algorithms would become hard to understand and unstructured. On the other hand, writing in code would mean that programmers not familiar with the language would not be able to understand the algorithm. Pseudocode represents a middle ground between the two, in which there are no formal rules. The PB&J algorithm written above is an example of pseudocode.


The following is a list of important and well-known types of algorithms:


1. Divide and conquer algorithms

  • In a divide and conquer algorithm, a problem is divided into two subparts, and is worked on separately until both parts become more simple. Examples of divide and conquer algorithms include binary searches, in which a value in a sorted list is searched for by repeatedly dividing the list.

2. Dynamic programming algorithms

  • In a dynamic programming algorithm, previous calculations are remembered in order to find new results. Examples of recursive algorithms include the Fibonacci Sequence.

3. Greedy algorithms

  • In greedy algorithms, the solution is split into parts. Each part is chosen on the basis of potential optimization.

4. Brute Force algorithms

  • In a brute force algorithm, every single possible solution to a problem is considered one by one. Brute force algorithms often take a lot of time. An example of this algorithm would be a four digit numerical password, in which the computer would try every possible combination, starting with 0000.

5. Backtracking algorithms

  • In a backtracking algorithm, problems are solved recursively and one at a time. If a solution fails, the algorithm backtracks and restarts to find a solution.

58 views0 comments

Recent Posts

See All