# Programming Algorithms

An algorithm is a series of well-defined instructions for solving a certain problem in computer programming. It takes a collection of inputs and outputs the desired result. As an example, An algorithm for adding two numbers is as follows:

*Take two number inputs(third variable for output)**Add numbers using the + operator**Display the result*

## Real-world example

you are in a Library, you want to read the book ** “The Art of Computer Programming”** published: 2019, Author: Donald Knuth

*note: Books are arranged year wise*

You give yourself a set of instructions to find the book:

- Take the book one after the other.
- If the title of the book is
*The Art of Computer Programming,**Pick the book and exit.* - If the title of the book is not
*The Art of Computer Programming,**Repeat Step 01.*

This set of instructions is the so-called **Algorithm. **You may question but why is an algorithm important? Because the best-chosen algorithm makes sure the computer will do the given task in the best possible manner.

Here we use the **Linear Searching Algorithm** (It sequentially checks each element of the list until a match is found or the whole list has been searched) to find the book,

*this works fine and efficiently, but what if there are 100s or 1000s of books? it won’t be efficient enough.*

That is where need an alternative Algorithm to make it efficient.

Let's check the **Binary Search Algorithm**(which is a search algorithm that finds the position of a target value within a sorted array) As the books are arranged in the order of years that can be used as an index, *assuming there is only one book for each year(for simplification)*

- Take the center book of the stack
- If the year of the book is less than 2019 go to the right stack and repeat step 1
- If the year of the book is greater than 2019 go to the right stack and repeat step 1
- If the year of the book is equal to 2019 exit

Binary Search Algorithm may involve in extra sorting process but when dealing with huge data queries it retrieves data much faster than Linear Search Algorithm.

*“When efficiency matters a proper algorithm is really vital to be used.”*

## Qualities of Good Algorithms

- Input and output must be well specified.
- Each stage of the algorithm should be simple and straightforward.
- Algorithms should be the most effective method of solving a problem out of a variety of options.
- Computer code should not be included in an algorithm. Rather, the algorithm should be designed in a way that allows it to be utilized in a variety of programming languages.

## Top 07 Algorithms Programmers should know

- Sort Algorithms
- Search Algorithms
- Hashing
- Dynamic Programming
- Binary Exponentiation
- String Parsing & Matching
- Primality Testing

*Reference: **https://www.programiz.com/dsa*