Advance algorithm
Advance algorithm
ALGORITHM ANALYSIS
LECTURE 1
Dr.Sadaqat Ali
Algorithms
◦ What is an Algorithms ?
◦ A step-by-step method for solving a problem or doing a task
Input List
↓
Algorithm
↓
Output List
Algorithm Concepts
What is Data Structure?
◦ A data structure is a systematic way of organizing and accessing data.
Some basic data structure as follows.
◦ Array
◦ Link
◦ List
◦ Stacks
◦ Queues
◦ Trees
What is Program?
◦ Program is an implementation of an algorithm in some programming language.
Data structure + Algorithm = Program
Design & Analysis of Algorithms
1. The "design" pertains to
I. The description of algorithm at an abstract level by means of a pseudo language, and
II. Proof of correctness that is, the algorithm solves the given problem in all cases.
2. The analysis" deals with performance evaluation (complexity analysis).
Problem, Solution and Tools
◦ A computer does not solve problems; it's just a tool that I can use to implement my plan for solving
the problem.
◦ A computer program is a set of instructions for a computer. These instructions describe the steps
that the computer must follow to implement a plan.
◦ An algorithm is a plan for solving a problem.
◦ A person must design an algorithm.
◦ A person must translate an algorithm into a computer program.
Algorithm Development Process
What is a good algorithm?
Good algorithm is an efficient algorithm.
◦ What does efficient means?
Efficient is something, which has small running time and takes (spaced used) less memory.
1. We would be spending more time on analyzing the running time of an algorithm.
2. We will also spend some time on analyzing the space. Efficiency of algorithms is as a function of
input size.
How to Calculate Running Time
analyze running time in the best case (usually useless) worst case (we focus on the
worst case running time)
average case (very useful but often difficult to determine)
Theoretical Analysis of Running Time
► Uses a pseudo-code description of the algorithm instead of an implementation
► Characterizes running time as a function of the input size, n
► Takes into account all possible inputs
► Allows us to evaluate the speed of an algorithm independent hardware/software environment
Pseudocode
In this course, Example:
find max element of an
we will mostly use pseudocode to describe an array
algorithm Algorithm arrayMax(A, n)
Pseudocode is a high- level description of an Input: array A of n integers
Output: maximum element
algorithm
of A
More structured than English prose
Less detailed than a program currentMax ← A[0] for i 1
to n - 1 do if A[i] >
Preferred notation for describing currentMax then
algorithms Hides program currentMax ← A[i] return
currentMax
Pseudocode Details
Control flow
if ... then [else...]
while ... Do
repeat until
for ... do Indentation replaces braces
Method declaration
Algorithm method (arg, arg...) Input Output
Method call
var.method (arg [, arg...])
Return value
return expression
Expressions
← Assignment (like = in Java) =/Equality testing (like == in Java) m² superscripts and other mathematical formatting allowed
Real-World Applications
Hardware design:
VLSI chips
Compilers Computer graphics
movies
video games
Routing messages in the Internet
Searching the Web
Distributed file sharing
Computer aided design and manufacturing
Security: e-commerce, voting machines
Multimedia: CD player, DVD, MP3, JPG, HDTV
DNA sequencing, protein folding and many more!
Some Important Problem Types
Sorting a set of items
Searching among a set of items
String processing text, bit strings, gene sequences
Graphs model objects and their relationships
Combinatorial find desired permutation, combination or subset
Geometric - graphics, imaging, robotics
Numerical continuous math: solving equations, evaluating functions
Algorithm Design Techniques
Brute Force & Exhaustive Search