In programming world, algorithms are the essentials to solving problems with code, whether you’ve decided to learn Java, C++, or Python, these algorithms are part of your daily programming life. I’ll go over some of the algorithms and data structures we should all get familiar with. we’ll go over the algorithms and their types as well as their uses. This is to give you an idea of what all you can accomplish using different algorithms.
- Sort algorithms.
Some may say this is the most popular algorithm, for it is used to arrange a list of items in a certain order. an example would be sorting items by popularity, or by size. here’s a list of sort algorithm types.
Insertion sort: takes takes a list elements and insert them one by one into their correct position.
Selection sort: starts with the smallest element and swaps it with the first element. Finds the second remaining smallest, swaps it with the second element, and so on.
Merge sort: divides the elements into equal halves, and then combines them to solve the problem.
- Search Algorithm. to many programs, search algorithm plays an important part. this algorithm makes it possible to for example search for a file in the IRS database, or searching for a specific song from a list of songs.
Linear Search: This is the algorithm used for short lists, since its simple and requires minimal code to implement. Linear Search scans one item at a time, from the beginning till the desired value or element is found.
Binary Search: Mainly used for large databases with records ordered by numerical key, an example would be the IRS which is ordered by the social security number. Binary search starts at the middle, then either continues with the upper half or or the lower half depending on your target number. The process repeats cutting database into half until target is found.
- Dynamic algorithms: this algorithm stores the results of a sub problem so that we don’t have to re-compute. It uses recursion to solve the sub problems recursively, and memorization to store the solutions of these sub problems so that we do not have to solve them again.
examples of dynamic algorithms include the Fibonacci Series, where the current number is the sum of previous two numbers. The Nth Catalan Number, which form as a sequence of natural numbers that occur in various counting problems.
- Recursive Algorithms: Call themselves with simpler input values, their base case define how the recursion ends. An example would be the Factorial, Exponential, and the Greatest Common Divisor.
- String Algorithm: Used to carry out and manipulate diverse operations. Examples include the kNuth-Morris-pratt, the Finite Automa, and the Rabin-Karp.
- Greedy Algorithm: build up a solution piece by piece, always choosing the next piece that offers the most immediate and obvious benefit. Examples are Huffman Coding, Shortest Path, also the Activity Selection.
You’ll find it that the word “Algorithm” is the most overused word in the programming industry, and its for a good reason. You see, this is how you accomplish tasks, and solve problems. I hope you had a good read, please leave a comment and share the post, thank you.
Also, don’t forget to take this short quiz on OOP and see how you did!