An algorithm is a series of steps that you follow to do something. An instruction manual or a recipe are good examples of algorithms. We translate algorithms into code when we are programming.
There are a series of very famous algorithms in computer science. Most of the Turing Award winners won for algorithms that they wrote. Tony Hoare won for his QuickSort algorithm, Dijkstra for his networking algorithms, Hamming for his Hamming Code algorithms and many more.
These are the key aspects of a great algorithm:
Big-Oh is the way that we say how fast a program runs. We don’t like to use seconds or milli-seconds because different computers run different speeds. Instead we measure in terms of the number of elements in the array or n.
A sequence of times from fastest to slowest:
Here are some basic lengths of things in terms of big-oh:
| Piece of Code |
Time |
| Assignment Statement |
O(1) |
| Single For Loop Through an Array |
O(n) |
| Nested For Loop Through an Array |
O(n2) |
| If |
O(1) |
4321
3421
3241
3214
2314
2134
1234
4321342132413214312413241234
432113241234
4321342123411234
1234422113
1’s = 3
2’s = 3
3’s = 2
4’s = 21112223344