Lecture 1_ Introduction (1)
Lecture 1_ Introduction (1)
❖Algorithm
is any well-defined computational procedure that
takes some value, or set of values, as input and
produces some value, or set of values, as
output.
is thus a sequence of computational steps that
transform the input into the output.
is a tool for solving a well - specified
computational problem.
Any special method of solving a certain kind of
problem (Webster Dictionary)
2
Why do we study Algorithms?
4
Deterministic Algorithms
❖A deterministic algorithm
Returns the same answer no matter how many
times it is called on the same data.
Always takes the same steps to complete the
task when applied to the same data.
5
Non-Deterministic Algorithms
❖ A non-deterministic algorithm
Can exhibit different behaviour, for the same
input data, on different runs.
6
Data structure
7
Applications and Data Structures
8
What is a problem?
10
Problem instances
13
Algorithm Design Paradigms?
❖Importance:
Efficiency
Scalability
Clarity in code
14
Algorithm Design Paradigms
❖Brute-Force
❖Divide-and-Conquer
❖Dynamic Programming
❖Greedy Algorithms
❖Randomization Approach
❖Approximation Approach
❖Backtracking
❖Branch and Bound
15
Divide and Conquer
❖Concept:
Break a problem into smaller subproblems
Solve each subproblem independently
Combine solutions for the final answer
❖Examples:
Merge Sort
Quick Sort
Binary Search
16
Greedy Algorithms
❖Concept:
Make the locally optimal choice at each stage
Aim for a global optimum
❖Characteristics:
Efficient but not always optimal
❖Examples:
Activity Selection
Huffman Coding
Minimum Spanning Tree (Prim’s and Kruskal’s
algorithms)
17
Dynamic Programming
❖Concept:
Solve problems by breaking them down into simpler
subproblems
Use previously computed results to avoid redundant
calculations
❖ Key Techniques:
Memoization (Storing results to avoid redundant
calculations.)
Tabulation
❖ Examples:
Fibonacci Sequence
Knapsack Problem
❖ Advantages:
Can provide good average-case performance
❖ Examples:
QuickSort (randomized version)
19
Approximation Approach
❖Concept:
Used for NP-hard problems where finding an exact
solution is impractical
Provides solutions that are close to the optimal solution.
❖ Characteristics:
Often involves heuristics or specific algorithms designed
Knapsack Problem
20
Applications and Algorithmic Techniques
21
What is meant by Algorithm Analysis?
22
What do we analyze about them?
❖Correctness
Does the input/output relation match algorithm
requirement?
❖Amount of work done (complexity)
Basic operations to do task
❖Simplicity, clarity
Verification and implementation.
❖Optimality
Is it impossible to do better?
23
Why Analysis of Algorithms is important?
❖ To predict the behaviour of an algorithm without
implementing it on a specific computer.
❖ It is much more convenient to have simple measures for
the efficiency of an algorithm than to implement the
algorithm and test the efficiency every time a certain
parameter in the underlying computer system changes.
❖ It is impossible to predict the exact behaviour of an
algorithm. There are too many influencing factors.
❖ More importantly, by analysing different algorithms, we
can compare them to determine the best one for our
purpose.
24
Desired properties of algorithms
25
Correctness
❖Time
How fast does an algorithm run?
❖Space
Does an algorithm require additional memory?
28
Efficiency Analysis
30
Analysing computation time
33