L01-02 - 30.09.2018 and 01.10.2018 - Introduction To Algorithm
L01-02 - 30.09.2018 and 01.10.2018 - Introduction To Algorithm
L01_30.09.2018_Introduction
Instructor Teaching Assistant
Md. Sabir Hossain
Abdullah 1
Lecturer
Id: 1604
Dept. of CSE, CUET
Abdullah 2
Mobile: 01737143868
Email: [email protected] Id: 1604
Acknowledgment: Most of the content of this slide is adopted from the book: Introduction to Algorithms, Third Edition
(International Edition), Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein, ISBN-13: 978-0262033848 and
Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne, Addison-Wesley Professional, 2011, ISBN 0-321-57351-X.
Today’s Target
• Expected Outcomes of CSE-243
• Topics Covered in Data Structure Course
• Text and Reference Books
• Introduction & definition
• Why Study Algorithm?
• Algorithms categories & types
• Pseudo-code
• Designing an algorithm
– Example: Max
• Analysis of algorithms
• Running time (Kind of Analysis)
Expected Outcomes of CSE-243
• Student will able to
– Design Algorithms to solve any Computational Problems (by class
lectures and performing assignments)
– Analyze the proposed Algorithms by Standard Way
(Mathematically) (by class lectures and assignments)
– Compare alternative solutions to any specific problems to
select the best one (by class lectures)
– Implement Algorithms to solve Competitive Programming
Challenges (by practice and contest lab)
– Discover new era of Algorithmic implementation (by doing capstone
projects)
– Modify/Improve/Propose effective and efficient algorithms to
existing ones (by research work)
Prerequisites: CSE-241 : Data Structure
array, Recursion,
Trees,
Lecture slides.
Download code.
Summary of content.
http://algs4.cs.princeton.edu
1920s
1930s
1940s
1950s
1960s
1970s
1980s
1990s
2000s
Md. Sabir Hossain, CSE, CUET
Why study algorithms?
F RO M T H E
E D I T O RS
“ For me, great algorithms are the poetry of computation. Just like Francis Sullivan, AssociateEditor-in-Chief
verse, they can be terse, allusive, dense, and even mysterious. Computational algorithms are probably as old as civilization. mysterious. But once unlocked, they cast a brilliant new light
Sumerian cuneiform, one of the most ancient written records, on some aspect of computing. A colleague recently claimed
consists partly of algorithm descriptions for reckoning in base that he’d done only 15 minutes of productive work in his
60. And I suppose wecould claim that the Druid algorithm for whole life. He wasn’t joking, because he was referring to the
estimating the start of summer is embodied in Stonehenge. 15 minutes during which he’d sketched out a fundamentalop- (That’s
really hard hardware!) timization algorithm. He regarded the previous years of Like
so many other things that technology affects, algo- thought and investigation as a sunk cost that might or might
rithms have advanced in startling and unexpected ways in the not have paid off.
20th century—at least it looks that way to us now. The algo- Researchers have cracked many hard problems since 1 Jan- rithms
we chose for this issue have been essential for progress uary 1900, but we are passing some even harder ones on to the in
communications, health care, manufacturing, economics, next century. In spite of a lot of good work, the question of weather
“ Algorithms: a common language for nature, human, and computer. ” — Avi Wigderson
• https://code2flow.com/app
Tools: Flow Chart to Pseudo Code
Example:
Input: 8 2 4 9 3 6
Output: 2 3 4 6 8 9
Example of insertion sort
8 2 4 9 3 6
Example of insertion sort
8 2 4 9 3 6
Example of insertion sort
8 2 4 9 3 6
2 8 4 9 3 6
Example of insertion sort
8 2 4 9 3 6
2 8 4 9 3 6
Example of insertion sort
8 2 4 9 3 6
2 8 4 9 3 6
2 4 8 9 3 6
Example of insertion sort
8 2 4 9 3 6
2 8 4 9 3 6
2 4 8 9 3 6
Example of insertion sort
8 2 4 9 3 6
2 8 4 9 3 6
2 4 8 9 3 6
2 4 8 9 3 6
Example of insertion sort
8 2 4 9 3 6
2 8 4 9 3 6
2 4 8 9 3 6
2 4 8 9 3 6
Example of insertion sort
8 2 4 9 3 6
2 8 4 9 3 6
2 4 8 9 3 6
2 4 8 9 3 6
2 3 4 8 9 6
Example of insertion sort
8 2 4 9 3 6
2 8 4 9 3 6
2 4 8 9 3 6
2 4 8 9 3 6
2 3 4 8 9 6
Example of insertion sort
8 2 4 9 3 6
2 8 4 9 3 6
2 4 8 9 3 6
2 4 8 9 3 6
2 3 4 8 9 6
2 3 4 6 8 9 done
Insertion sort
INSERTION-SORT (A, n) ⊳A[1 . . n]
for j ← 2 to n
do key ← A[ j]
i←j–1
“pseudocode” while i > 0 and A[i] > key
do A[i+1] ← A[i]
i←i–1
A[i+1] = key
Insertion sort
INSERTION-SORT (A, n) ⊳A[1 . . n]
for j ← 2 to n
do key ← A[ j]
i←j–1
“pseudocode” while i > 0 and A[i] > key
do A[i+1] ← A[i]
i←i–1
A[i+1] = key
1 i j n
A:
key
sorted
Running time