Define an algorithm. What are the properties of an algorithm? What are the types of algorithms?An algorithm is a series of steps or methodology to solve a problem.
Properties of an algorithm:-
- It is written in simple English.
- Each step of an algorithm is unique and should be self explanatory.
- An algorithm must have at least one input.
- An algorithm must have at least one output.
- An algorithm has finite number of steps.
Types of algorithms are categorized based on the context they are spoken about. Some commonly used:
Brute force:- An extremity raw method that aims to finds variety of solutions and which ones the best.
Reduction:- Tries and converts the given problem to a simpler and a better known problem whose complexity is not dominated by the resulting reduced algorithm's. Linear programmings, Graphs, random are the other types of algorithms.
Define an algorithm. What are the properties of an algorithm? What are the types of algorithms?Algorithm: A step by step process to get the solution for a well defined problem.
Properties of an algorithm:
- Should be written in simple English
- Should be unambiguous, precise and lucid
- Should provide the correct solutions
- Should have an end point
- The output statements should follow input, process instructions
- The initial statements should be of input statements
- Should have finite number of steps
- Every statement should be definitive
Types of algorithms:
– Simple recursive algorithms. Ex: Searching an element in a list
– Backtracking algorithms Ex: Depth-first recursive search in a tree
– Divide and conquer algorithms. Ex: Quick sort and merge sort
– Dynamic programming algorithms. Ex: Generation of Fibonacci series
– Greedy algorithms Ex: Counting currency
– Branch and bound algorithms. Ex: Travelling salesman (visiting each city once and minimize the total distance travelled)
– Brute force algorithms. Ex: Finding the best path for a travelling salesman
– Randomized algorithms. Ex. Using a random number to choose a pivot in quick sort).