Intro To Algorithms
Intro To Algorithms
Algorithms
Muzaffar Iqbal Farooqi
Assistant Professor
Department of Computer Science
COMSATS University Islamabad
1
Course Description
2
Course Description…
3
Pre-Requirements
• Basic understanding of mathematics (must)
• Basic understanding of programming (must)
• Data Structures (recommended)
• Object Oriented Programming (recommended)
• Discrete Structures (recommended)
4
Course Objectives
• The course has two basic objectives.
1. Familiarize students with existing algorithms
2. To equip the students with the necessary tools, techniques,
and confidence required in solving a non- textbook problem
5
Recommended Books
1. Introduction to the Design and Analysis of Algorithms,
Levitin, A., 3rd Edition (2012), Pearson.
2. Introduction to Algorithms, Cormen, T. H.,Leiserson, C.E.,
Rivest, R.L.& Stein, C., 3rd Edition
(2009), MIT Press.
3. An Introduction to the Analysis of Algorithms, Sedgewick,
R.& Flajolet, P., 2nd Edition (2012),
Addison-Wesley.
4. Foundation of Algorithms Using C++ Pseudocode,
Neapolitian, R., 6th Edition (2013), Jones &
Bartlett Learning .
6
Assessment Plan
7
Major Topics To Be Covered
• The concept and properties of algorithms
• Fundamentals of algorithmic problem solving
• Brute-Force Algorithms
• Asymptotic Notation
• Different algorithms of sorting
• Different algorithms of searching
• The Iteration and Recursion Methods
• Greedy Algorithms
• Graphs
• Heuristics
8
Origin of word: Algorithm
• The word Algorithm comes from the
name of the muslim author Abu Ja’far
Mohammad ibn Musa al-Khowarizmi.
• He was born in the eighth century at
Khwarizm (Uzbekistan)
• Originally, the word algorism was
used for the rules for performing
arithmetic using decimal notation.
• Much of al-Khwarizmi’s work was
written in a book titled al Kitab al-
mukhatasar fi hisab al-jabrwa’l-
muqabalah 9
Origin of word: Algorithm …
• Al-Khowarizmi wrote a paper in 825 AD, on calculation with
Hindu Numerals.
• It was translated into Latin in the 12th century as Algoritmi de
numero Indorum (al-Daffa 1977), which title was likely
intended to mean "Algoritmi on the numbers of the Indians“.
• It is from the titles of his writings and his name that the words
algebra and algorithm are derived.
• Al-Khwarizmi is regarded as the most outstanding
mathematician of his time
10
Algorithm: Informal Definition
• An algorithm is any well-defined (computational) procedure
that …
• takes some values, or set of values, as input
• produces some value, or set of values, as output
• An algorithm is thus a sequence of computational steps that
transforms the input into output.
11
Algorithms: Informal Introduction
Recipe for baking a cake….
Ingredients: Input
2 sticks butter
2 cups flour
1 cup sugar
4 eggs
1 cup milk
1 tsp baking powder
Cocoa powder (1/2 pound)
Procedure: Method
Mix the sugar, baking powder and flour, mix in beaten
eggs, melted butter and bake at 325F for 40 mins.
Result: Output
What is algorithm?
• What is binary equivalent of decimal integer 75?
• 1001011
• How can we convert this number into its binary
equivalent?
• We have a procedure for this.
• Let us see how we can convert 75 into binary
13
Convert 75 to binary
2 75 remainder
2 37 1
2 18 1
2 9 0
2 4 1
2 2 0
2 1 0
0 1
1001011
Procedure for Decimal to Binary conversion
1. Write the decimal number
• What is it?
• A procedural solution to given problem
• Briefly speaking, algorithms are procedural solutions to
problems
• Algorithms are not answers, but rather precisely defined
procedures for getting answers. (e.g., sorting 3 numbers)
What is Algorithm?
• Algorithm is a well defined computational procedure
that takes some value, or set of values (collection of
elements) as input and produces some value, or set
of values(collection of elements) as output.
17-Sep-19
problem
algorithm
17
Example: Largest integer among five integer
Is there a
relationship
between input
and output?
Defining actions in FindLargest algorithm
L
o
g
i
c
20
Why Study Algorithms?
• This course is all about …
• What are the established well known algorithms?
• How to design good algorithms?
• This is not really an independent issue.
• Designing good/efficient algorithms requires understanding of some
other areas.
• The fact is that many of the courses in computer science deal with
efficient algorithms and data structures.
• These are applied to various applications like…
• Compilers
• Operating Systems
• Databases
• Artificial Intelligence
• Computer Graphics 21
• Networks and many more
Why Study Algorithms…
• A good understanding of algorithm design is central element
to a good understanding of computer science and computer
programming.
• Another reason for studying algorithms is their usefulness in
developing analytical skills. After all, algorithms can be seen as
special kinds of solutions to problems
22
Brief Course Outline
• This course will broadly consist of the following major
sections.
1. Sorting… this will focus on different established algorithms
for sorting and use this problem as a case study to
understand different techniques.
2. Collection of different algorithmic problems and solution
techniques: dynamic programming, greedy strategy, graphs
etc.
3. Theory of NP-completeness. NP-complete problems are
those for which no efficient algorithms are known. Even no
one may know it for sure that efficient solutions might exist.
23
QUESTIONS
?
24