Lectuer 1-Algo
Lectuer 1-Algo
Text book
Introduction to Algorithms, 2009, Third Edition
by
Thomas H. Cormen, Charles E. Liserson, Ronald L. Rivest, Clif Ord
Stein
2
References
Chapter 1
Introduction to Algorithms, 2009, Third Edition
by
Thomas H. Cormen
Charles E. Liserson
Ronald L. Rivest
Clifford Stein
http://www.mathsolutions.com/documents/978-1-935099-01-
7_CH4.pdf
https://en.wikipedia.org/
These slides contain material from the above resources.
3
Algorithms
An 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.
4
Computational procedure
A computational procedure is a series of steps or actions
what we use when operating on numbers.
5
Sorting
Sorting is a fundamental operation in computer science
The number that we wish to sort are also known as the keys.
6
Sorting
Example:
7
What kinds of problems are solved by
algorithms?
Practical applications of algorithms are ubiquitous, for example:
Human Genome Project.
8
Which is the best algorithm?
Which algorithm is best for a given application depends on:
10
Algorithms vs. Data Structure
Algorithm: method for solving a problem.
11
Why study algorithms?
“ For me, great algorithms are the poetry of computation. Just
like verse, they can be terse, allusive, dense, and even
mysterious. But once unlocked, they cast a brilliant new light
on some aspect of computing”.
— Francis Sullivan
12
Why study algorithms?
13
Insertion sort vs. Merge sort [1]
Insertion sort, takes time roughly equal to c1n2 or c1n.n to
sort n items, where c1 is a constant that does not depend on
n.
14
Insertion sort vs. Merge sort [2]
For example:
When n = 1000
log1000 = 6.9078 (approximately)
15
Analysis of algorithms
The theoretical study of computer-program performance and
resource usage.
16
Million vs. Billion
A million (10 lacs or 10 lakhs) is 106, or 1,000,000.
17
Example: Insertion sort vs. Merge sort
[1]
A faster computer, named computer A running insertion sort.
19
Example: Insertion sort vs. Merge sort
[3]
To sort 1 million numbers, computer A take
𝟐𝐧𝟐 2. 106 2 instuctions
= = 2000 seconds
1 billion 𝐢𝐧𝐬𝐭𝐮𝐜𝐭𝐢𝐨𝐧𝐬/𝐬𝐞𝐜𝐨𝐧𝐝𝐬 109 instuctions/seconds
20
Suggested readings
1.1 Algorithms
1.2 Algorithms as a technology
21