Wajid DAA
Wajid DAA
Design and Analysis of Algorithms Dr. Wajid Arshad Abbasi, Department of CS&IT
History
Procedures for solving geometric and arithmetic problems were formulated
by ancient Greeks
Some two thousands years ago, the celebrated procedure for finding
greatest common divisor (gcd) was discovered by Euclid
The word algorithm comes from the name of the 9th century Persian
mathematician Abu Abdullah Muhammad ibn Musa al-Khwarzimi
Design and Analysis of Algorithms Dr. Wajid Arshad Abbasi, Department of CS&IT 2
Algorithms today
The word originally referred only to the rules of performing
arithmetic
Design and Analysis of Algorithms Dr. Wajid Arshad Abbasi, Department of CS&IT 3
Definition
An algorithm is an orderly step-by-step procedure, which has the
characteristics:
Design and Analysis of Algorithms Dr. Wajid Arshad Abbasi, Department of CS&IT 4
Applications
Algorithms have been developed to solve an enormous variety of problems in
many application domains. Some broad categories of algorithms are listed
below.
Sorting Algorithms
Searching Algorithms
String Processing (Pattern matching, Compression, Cryptography)
Image Processing (Compression, Matching, Conversion)
Mathematical Algorithms (Random number generator, matrix operations)
Design and Analysis of Algorithms Dr. Wajid Arshad Abbasi, Department of CS&IT 5
Applications…
Some applications do not explicitly require algorithmic content at the
application level
Design and Analysis of Algorithms Dr. Wajid Arshad Abbasi, Department of CS&IT 6
Analysis of Algorithms
Analyzing an algorithm has come to mean predicting the resources that it
requires
Time efficiency
Performance in terms of running times for different input sizes
Space utilization
Requirement of storage to run the algorithm
Correctness of algorithm
Results are trustworthy, and algorithm is robust
Design and Analysis of Algorithms Dr. Wajid Arshad Abbasi, Department of CS&IT 7
Algorithm Efficiency
Time efficiency remains an important consideration when developing
algorithms
Design and Analysis of Algorithms Dr. Wajid Arshad Abbasi, Department of CS&IT 8
Algorithm Efficiency…
Design and Analysis of Algorithms Dr. Wajid Arshad Abbasi, Department of CS&IT 9
Algorithm Efficiency…
Another comparison in terms of algorithm execution time
Design and Analysis of Algorithms Dr. Wajid Arshad Abbasi, Department of CS&IT 10
Approaches to Analysis
Basically three approaches can be adopted to analyze algorithm
running time in terms of input size:
Empirical Approach
Running time measured experimentally
Analytical Approach
Running time estimated using mathematical modeling
Visualization
Performance is studied through animation for different data sets
Design and Analysis of Algorithms Dr. Wajid Arshad Abbasi, Department of CS&IT 11
Empirical Approach
The running time of algorithm is measured for different data sizes and time
estimates are plotted against the input. The graph shows the trend.
Design and Analysis of Algorithms Dr. Wajid Arshad Abbasi, Department of CS&IT 12
Limitations
Running time critically depends on:
Hardware resources used
(CPU speed, IO throughput, RAM size)
Software environment
(Compiler, Programming Language)
Design and Analysis of Algorithms Dr. Wajid Arshad Abbasi, Department of CS&IT 13
Analytical Approach
We want a measure that is independent of the computer, programming
language, and complex details of the algorithm
Design and Analysis of Algorithms Dr. Wajid Arshad Abbasi, Department of CS&IT 14
Algorithm Specification
Plain natural language
High level description
Pseudo Code
Low level to facilitate analysis and implementation
Design and Analysis of Algorithms Dr. Wajid Arshad Abbasi, Department of CS&IT 15
Specification Using Natural Language
Preorder Tree Traversal Algorithm
Step1. Push tree root to stack
Step2. Pop the stack. If stack is empty exit, else process the node
Step3. Travel down the tree following the left most path, and
pushing each right child onto the stack
Step4. When leaf node is reached, go back to step 2.
Design and Analysis of Algorithms Dr. Wajid Arshad Abbasi, Department of CS&IT 16
Pseudo Code Convention
Design and Analysis of Algorithms Dr. Wajid Arshad Abbasi, Department of CS&IT 17
Example
Design and Analysis of Algorithms Dr. Wajid Arshad Abbasi, Department of CS&IT 18
Algorithm Design
There are many approaches to designing algorithms:
Divide-and-Conquer
Greedy
Dynamic Programming
Brute Force
Approximation
Design and Analysis of Algorithms Dr. Wajid Arshad Abbasi, Department of CS&IT 19
Take home task
1. Read first chapter “The Role of Algorithms in
Computing” of Introduction to Algorithms
Design and Analysis of Algorithms Dr. Wajid Arshad Abbasi, Department of CS&IT 20
End of lecture
Design and Analysis of Algorithms Dr. Wajid Arshad Abbasi, Department of CS&IT 21