Let us say the problem of preparing a cup tea. To prepare a cup of tea, we follow the steps given below: 1) Get the kettle and boil the water in the kettle. 2) Get the milk. a. Do we have milk? i. If yes, put it in the kettle. ii. If no, do we want to buy milk? 1. If yes, then go out and buy. 2. If no, we can terminate. 3) Turn on the stove and put the kettle on the stove. etc…..
What we are doing is, for a given problem (preparing a cup of tea), we provide step-by-step instructions The process of solving it. The formal definition of the algorithm can be expressed as
Algorithms are clear, step-by-step instructions to solve specific problems.
Note : – For the same problem , we can design more than one algorithm.
In mathematics and computer science, algorithms are well-defined, a finite sequence of computer-implementable instructions, usually used to solve a class of problems or perform calculations. Algorithms are always clear and are used as a specification for performing calculations, data processing, automatic reasoning and other tasks.
Algorithm can also be describe in visual format using Flow-Chart Method.
Types of Algorithm
There are two types of algorithm:
1 : Iterative Algorithm
2 : Recursive Algorithm.
Iterative Algorithm
This type of algorithm contains iterative statement or nested statement.iterative algorithm is good as compare to the Recursive algorithm
because iterative algorithm does not requires more system resources specially memory to complete the execution of the task.
Example :
In Above Example, There is only iterative statement.
Recursive Algorithm
This type of algorithm contains at least one recursive statement .recursive algorithm is not a good approach to implement an algorithm as compare to the Iterative algorithm,because recursive algorithm requires more system resources specially memory to complete the execution of the task.Recursive means an statement or a block which is calling itself.
Example :
In Above Example, MyFunction() is calling itself.
Characteristics of Algorithms:
- Well-Defined Steps: Algorithms are characterized by a precise sequence of steps that must be followed to achieve the desired result. Each step should be unambiguous and clearly articulated.
- Input and Output: Every algorithm takes input, processes it according to its instructions, and produces an output. The quality of the input and the efficiency of the processing directly influence the algorithm’s performance.
- Finiteness: Algorithms must be finite, meaning they should eventually halt after a finite number of steps. This ensures that the algorithm will reach a conclusion or produce an output within a reasonable timeframe.
- Feasibility: The steps outlined in an algorithm must be feasible and executable. In other words, they should be practical and achievable using the resources available to the computer.
Why Algorithms Matter:
- Problem Solving: Algorithms are instrumental in solving complex problems efficiently. They provide systematic approaches to address challenges, making it easier to devise solutions in various domains, such as mathematics, data analysis, and artificial intelligence.
- Efficiency and Optimization: Efficient algorithms contribute to faster and more resource-friendly software. Optimized algorithms ensure that computing resources are utilized judiciously, enhancing overall system performance.
- Consistency and Reproducibility: Algorithms bring a level of consistency to computing tasks. By providing a standardized set of instructions, algorithms enable the reproduction of results across different systems, fostering reliability in computational processes.
- Innovation and Advancements: Many technological advancements and innovations are rooted in the development and refinement of algorithms. From cryptography to machine learning, algorithms drive progress in diverse fields.
Important Points
1- Every Recursive algorithm can also be solved by Iterative algorithm.
2- We can not write Recursive version of every Iterative algorithm.
Nice content 😊