In this chapter we shall learn about:
1.1 what is an algorithm in generic way?
1.2 what is algorithm in terms of computer science?
1.3 Now let us understand the importance of algorithms?
1.4 What are the characteristics of a good algorithm?
1.5 What are different types of algorithms?
1.5.1 Brute force approach
1.5.2 Recursive approach
1.5.3 Dynamic Programming [DP]
1.5.4 Backtracking Algorithm
1.5.5 Greedy Approach
1.5.6 Divide and Conquer
When we think of algorithm, we think of a computer program that solves a problem. But, in day to day life we come across many things that might define an algorithm. It might be your daily routine when you go to college, or how you plan your weekends.
1.1 So now, what is an algorithm in generic way?
An algorithm can be defined as a finite step by step instructions to perform an operation.
For example:
Daily we follow below set of steps like:
- Getting up
- Getting ready
- Go to school/office
- Have lunch
- Come back to home have dinner
- Go to sleep
The above steps can be considered as an algorithm.
1.2 But what is algorithm in terms of computer science?
In computer science an algorithm might be defined as a finite step by step instructions to solve a computational problem in an efficient way.
If you take an example of ride sharing service, how does the system deicide that a cab near to you should be allocated, or how does google maps will calculate the time take for you to reach your destination accurately?
The solutions for all the above problems can be solved by using algorithms.
1.3 Now let us understand the importance of algorithms?
- Algorithms will help you to solve a computational problem efficiently by applying different methods.
- It will help you to make your program run faster.
- It will help you to clear interviews.
- It will help you to become good at competitive programming.
In the series of chapters, we shall be looking at different types of algorithms and data structures, that will help you to understand and able to solve different types of problems.
1.4 What are the characteristics of a good algorithm?
- Finite steps: An algorithm should have finite number of steps.
- Clear: An algorithm should be clear and easy to understand.
- Efficient: An algorithm should be efficient in utilizing CPU resources.
- An algorithm should avoid repetitive code by using recursion or dynamic programming.