Algorithms (AS)
Algorithms (AS)
Basics of Algorithms
- Algorithm: Defined as a step-by-step process for a specific task. It acts as a blueprint for any computational task.
- Deterministic Algorithm: An algorithm where for a given input, the same output is produced each time.
- Non-deterministic Algorithm: An algorithm where even for the same input, the output can change.
- Parallel Algorithm: This algorithm splits a problem into several similar, smaller sub-problems that can be solved at the same time.
- Sequential Algorithm: In contrast to parallel algorithm, this algorithm solves one sub-problem at a time.
Complexity of Algorithms
- Time Complexity: Indicates the amount of time an algorithm takes to run, in terms of the size of the input.
- Space Complexity: Denotes how much memory an algorithm needs to run successfully.
- Big O Notation: Used to describe the worst-case scenario for an algorithm’s running time or space usage.
Types of Algorithms
- Search Algorithm: This class of algorithm is used to locate specific items within larger collections.
- Sort Algorithm: Used to rearrange a given sequence of items, often into non-decreasing or non-increasing order.
- Graph Algorithm: These algorithms have a wide range of applications, from social network graph analysis to routing protocols in networking.
Properties of Algorithms
- Correctness: An algorithm is considered correct if it produces the right outputs for each given set of inputs.
- Efficiency: Efficiency of an algorithm is measured by looking at the resources it consumes (time and space) while solving a problem.
- Clarity: An algorithm should be easy to understand and implement.
- Generality: A general algorithm can solve all problems of a particular class.
- Robustness: An algorithm’s ability to handle unexpected input values or fluctuating operational environment is known as its robustness.
Designing and Implementing Algorithms
- Stepwise Refinement: This is a method of design where an algorithm is refined in successive steps, each expanding on a single aspect of the algorithm.
- Pseudocode: A method of writing an algorithm that uses annotations resembling high-level programming language.
- Flowchart: A graphic representation of algorithms, where each step is shown in a box and flow lines indicate the order of steps.
- Debugging: The process of identifying and fixing errors in an algorithm.
- Testing: The process of running the implemented algorithm with different test cases to ensure it works as expected.