1 Lecture 1
1 Lecture 1
Algorithm
Lecture 1
Dr. Sadia Basar
Objective of this Course
• Design and Analysis of modern algorithms
• Different varients
• Accuracy
• Efficiency
• Comparing efficiencies
• Motivation thinking new algorithms
• Advanced designing techniques
• Real world problems will be taken as examples
What is an Algorithm?
• An algorithm is a set of rules for carrying out calculation
either by hand or on a machine.
• An algorithm is a finite step-by-step procedure to achieve a
required result.
• An algorithm is a sequence of computational steps that
transform the input into the output.
• An algorithm is a sequence of operations performed on data
that have to be organized in data structures.
• An algorithm is an abstraction of a program to be executed on
a physical machine (model of Computation).
What is an Algorithm?
Problem
algorithm
• Generality
• Finiteness
• Non-ambiguity
• Efficiency
Generality
Example:
Let’s consider the problem of increasingly sorting a
sequence of values.
For instance:
(2,1,4,3,5) (1,2,3,4,5)
input data result
Generality (cont’d)
Method:
Description:
Example
Step1: Assign 1 to x;
Step2: Increase x by 2;
Step3: If x=10 then STOP;
else GO TO Step 2
Step1: Assign 1 to x;
Step2: Increase x by 2;
Step3: If x>=10
then STOP;
else Print x; GO TO Step 2
Efficiency
• The need to design efficient algorithms
• What is efficiency?
• Example
• Sequential search Vs. Binary Search
Algorithm Analysis
• How to analyze an algorithm?
• Predicting the resources that the algorithm requires.
• Machine
• Operating system
• Programming languages
• Compiler, etc.
Running Time
the input size. 80
difficult to determine. 40
• Problem
• Strategy
• Algorithm
• Input
• Output
• Steps
Problem Solving Process
• Analysis
• Correctness
• Time & Space
• Optimality
• Implementation
• Verification
Algorithm Analysis
• Running Time
• We need a measure that is independent of
computer, programming language and the
programmer.
• Concept of basic operation
• In sorting comparison is a basic operation.
Algorithm Analysis
• What are the constructs / Keywords.
• Time for each construct
• Total Time
• Total time as a function of input size
Important Designing Techniques
• Decrease-and-Conquer
• Reduces the problem size step by step.
• Example: Binary search, where the search space is halved at
each step.
• Transform-and-Conquer
• Modifies the problem to make it easier before solving.
• Example: Changing data representation or preprocessing for
optimization.
• Space and Time Tradeoffs
• Uses additional memory to speed up computations.
• Example: Caching, dynamic programming, or lookup tables.