2_Introduction to Algorithms
2_Introduction to Algorithms
An algorithm is a set of instructions that are followed to complete a task or solve a problem.
Set of rules to
obtain expected
Input Output
output from
given input
Applications
Computer Science: Computer programming, Artificial intelligence and Machine learning etc.
Mathematics: Optimal solution to a system of linear equations or the shortest path in a graph.
Data Science: Analyze, Process, and Extract insights from large amounts of data in fields such as
Time Complexity: Refers to the amount of time required by the algorithm to execute and get
the result.
T(P) = C + V
◦ Constant Time Part (C): Any instruction that is executed just once comes in this part.
◦ Variable Time Part (V): Any instruction that is executed more than once, say n times, comes in
this part.
Complexity Analysis Cont’d
Space Complexity: Refers to the amount of memory required by the algorithm to store the
variables and get the result.
S(P) = C + V
◦ Fixed Part (C): The space that is required by the algorithm.
◦ Variable Part (V): The space that can be different based on the implementation of the algorithm.
For example, temporary variables, dynamic memory allocation, recursion stack space, etc.
Advantages vs Disadvantages
Advantages:
◦ Easy to understand
◦ Serve as a blueprint
◦ Simple to debug
◦ Not dependent on programming language
Disadvantages:
◦ Time-consuming
◦ Space and time complexity
◦ Branching and Looping statements are difficult to show in Algorithms
Thank You