Introduction To Analysis of Algorithms: Al-Khowarizmi
Introduction To Analysis of Algorithms: Al-Khowarizmi
Introduction To Analysis of Algorithms: Al-Khowarizmi
LECTURE 1
An algorithm, named after the ninth century scholar Abu Jafar Muhammad Ibn Musu
Al-Khowarizmi.
What is Algorithm?
An algorithm is a step-by-step procedure for performing some task in a finite amount of time.
What is the difference between an Abstract Data Type (ADT) and a Data Structure?
Abstract Data Type (ADT) Data Structure
ADT is the logical picture of the data and the Data structure is the actual representation of
operations to manipulate the component the data during the implementation and the
elements of the data. algorithms to manipulate the data elements.
Program:
Program is an implementation of an algorithm in some programming language.
Data structure + Algorithm = Program
Model of Computation:
An abstract sequential computer, called a Random Access Machine or RAM. Uniform cost
model.
What is efficient?
Efficient is something, which has small running time and takes (spaced used) less memory.
Experimental Study
Write a program that implements the algorithm?
Run the program with data sets of varying size and composition.
Use a method like System. CurrentTimesMillis() to get an accurate measure of actual
running time.
Uses a high-level description of the algorithm instead of testing one of its implementations.
Takes into account all possible inputs
Allows one to evaluate the efficiency of any algorithm in a way that is independent of the
hardware and software environment
Pseudo-Code
A mixture of natural language and high-level programming concepts that describes the
main ideas behind a generic implementation of a data structure or algorithm
It is more structured than usual prose but less formal than a programming language
Expressions:
o Use standard mathematical symbols to describe numeric and Boolean expressions
o Use for assignment (“-“ in Java)
o Use = for the equality relationship (“= =” in Java)
Method Declarations:
o Algorithm name (param1. param2)
Programming Constructs:
o decision structures: if ... then ... [else
o while-loops. while ... do
Prepared by: Engr. M. Nadeem Page 3
CS5613- Advanced Analysis of Algorithms MS(CS) - MAJU
Methods:
o calls: object method(args)
o returns: return value
Primitive Operation:
Primitive Operation: Low-level operation Independent of programming language. Can be
identified in pseudo-code for example:
o Data movement (assign)
o Control (branch, subroutine call, return)
o Arithmetic an logical operations (e.g. addition, comparison)
By inspecting the pseudo-code, we can count the number; primitive operations executed by
an algorithm.
Time complexity
Design of Algorithm
Implementing
Testing
Analysis of Algorithm
Time Complexity
Asymptotic Analysis:
Problem: Searching a key in a set A = {a1, a2, a3 . . . an} => (Linear searching in array)
Conclusion:
Best case => Minimum No. of comparison (Not much use) => 1 comparison
Worst case=> Maximum No. of comparison (Most Important) => n comparison
Average case=> Average No. of comparison =>n/2 comparison
Note: Sometime difficult to find average case