What is an algorithm?
Algorithms are simply a set of instructions that solve a problem. They can be found and created for everything we do.
For example, given the problem of making a sandwich - a possible algorithm could be:
- locate a slice of bread
- if no bread is found, go buy bread, eat something else or give up
- locate some butter
- if no butter is found, go buy butter, eat something else or give up
- locate some peanut butter
- if no peanut butter is found, go buy peanut butter, eat something else or give up
- locate a plate
- if no plate is found, give up
- locate a butter knife
- if no knife is found, give up
- place the slice of bread on the plate
- use the knife to scoop a teaspoon-sized blob of butter
- using the knife, spread the butter onto the bread, covering the entire slice with the butter
… you get the idea 😬
In programming, an algorithm is a murder on instructions (that’s the collective noun for a group of instructions, look it up 😅) that, when executed, solve a specific problem. We usually want the most efficient algorithm, both in terms of performance - time complexity - as well as resource usage - space complexity.
There are a few established algorithms for common programming problems such as searching, sorting, hashing etc. Here we will discuss as many as we can.
Search Algorithms
Linear/Simple Search
- An article talking about Linear Search with examples in:
Binary Search
- An article talking about Binary Search with examples in:
Sorting Algorithms
Selection Sort
- An article talking about Selection Sort with examples in: