Lecture - 01 - Introduction to Algorithms
Lecture - 01 - Introduction to Algorithms
3
Class Introduction
• Why are you here…?
• Ambitions
• What is PhD / MSCS (M.Phil)…?
• Any Particular point to start with ?
• Spare of thought
• Any research background…?
4
Course Information
Textbook
Introduction to Algorithms, Cormen, T. H., Leiserson, C.E.,
Rivest, R.L. & Stein, C., MIT Press, 2022
Text Book
Introduction to the Design and Analysis of Algorithms, Levitin,
A., Pearson, 2017
5
Objectives of This Course
Major objectives of this course are:
• Design and analysis of modern algorithms
• Different variants
• Accuracy
• Efficiency
• Comparing efficiencies
• Motivation thinking new algorithms
• Advanced designing techniques
• Real world problems will be taken as examples
• To create feelings about usefulness of this course
6
Expected Outcome
On successful completion, students will be able to
• Argue and prove correctness of algorithms
• Derive and solve mathematical models of problems
• Reasoning when an algorithm calls certain approach
• Analyse average and worst-case running times
• Integrating approaches in dynamic and greedy algos.
• Use of graph theory in problems solving
• Advanced topics such as
• Computational geometry, number theory etc.
• Several other algorithms such as
• String matching, NP completeness, approximate algorithms etc.
7
Course Evaluation
• Assignments
• Quizzes
• Term paper / Report
• Midterm
• Final Exam
8
Key to Success
• Attendance
• Listen to lectures and keep extra notes
• Ask questions
• Effort
• Do homework on your own. It’s ok to discuss with others but make your
own effort.
• Consistency
• Keep up with reading and homework.
9
Plagiarism Policy
• According to this policy, a student's submitted work must be the
student's own. In this course, this policy will be applied to all work
submitted for grade including exams, quizzes, homework, and
projects.
10
Origin of word: Algorithm
• The word Algorithm comes from the name of the Muslim author Abu Ja’far
Mohammad ibn Musaal-Khowarizmi. He was born in the eighth century at Khwarizm
(Kheva), a town south of river Oxus inpresent Uzbekistan. Uzbekistan, a Muslim
country for over a thousand years, was taken over by the Russians in 1873.
• His year of birth is not known exactly. Al-Khwarizmi parents migrated to a place
south of Baghdad when he was a child. It has been established from his
contributions that he flourished under Khalifah Al-Mamun at Baghdad during 813 to
833 C.E. Al-Khwarizmi died around 840 C.E.
• Much of al-Khwarizmi’s work was written in a book titled al Kitab al-mukhatasar fi
hisab al-jabrwa’l-muqabalah (The Compendious Book on Calculation by Completion
and Balancing). It is from the titles of these writings and his name that the words
algebra and algorithm are derived. As a result of his work, al-Khwarizmi is regarded
as the most outstanding mathematician of his time.
11
Design and Analysis of Algorithms
• The “design” pertain to
• The description of algorithm at an abstract level by means of a pseudo language, and
• Proof of correctness that is, the algorithm solves the given problem in all cases
• The “analysis” deals with performance evaluation (complexity analysis)
12
Algorithm
• An algorithm is a set of rules for carrying out calculation either by hand or on
a machine.
• An algorithm is a finite step-by-step procedure to achieve a required result.
• An algorithm is a sequence of computational steps that transform the input
into the output.
• An algorithm is a sequence of operations performed on data that have to be
organized in data structures.
• An algorithm is an abstraction of a program to be executed on a physical
machine (model of Computation).
• An algorithm is a sequence of computational steps that transform the input
into the output
13
Algorithm
• An algorithm is a sequence of computational steps that transform the input
into the output.
• Example:
• Sorting Problem
• Input: A sequence of n numbers
• Output: A permutation (reordering) of the input sequence
14
Algorithm
Problem
Algorithm
Input Output
15
Important Problem Types
• Sorting
• Searching
• String Processing
• Graph Problems
• Combinatorial Problems
• Geometric Problems
• Numerical Problems
16
Sorting
• The sorting problem asks us to rearrange the items of a given list in ascending
order.
• Why would we want a sorted list?
• It makes many questions about the list easier to answer.
• It is used as an auxiliary step in several important algorithms in other areas,
e.g., greedy algorithms, geometric algorithms.
• There is no sorting algorithm that would be the best solution in all situations.
17
Sorting
• Two special properties of sorting algorithms
• Stable
• In place
• A sorting algorithm is called stable it preserves the relative order of any two
equal elements in its input.
• An algorithm is said to be in place if it does not require extra memory, except
possibly, for a few memory units.
18
Searching
• The Searching Problem deals with finding a given value, called a search key,
in a given set.
• There is no single algorithm that fits all situations best.
19
String Processing
• A string is a sequence of characters from an alphabet.
• Strings of particular interest are
• Text strings
• Bit strings
• Gene sequences
• String Matching I.e. searching of a given word in a text get a special attention
from researchers.
20
Graph Problems
• A graph is a collection of points called vertices, some of which are connected
by line segments called edges.
• Graphs can be used for modeling a wide variety of real-life applications, like
• Transportation and communication networks
• Project Scheduling
• Games
21
Graph Problems
• Basic graph algorithms include
• Graph traversal algorithms
• Shortest path algorithms
• Topological sorting for graphs with directed edges
• Some graph problems are computationally very hard like
• Traveling salesperson problem
• Graph coloring problem
22
Combinatorial Problems
• These are problems that ask (explicitly or implicitly) to find a combinatorial
object-such as
• A permutation
• A combination
• Or a subset
• That satisfies certain constraints and has some desired property.
• E.g.
• Traveling Salesperson problem
• Graph Coloring problem
23
Fundamental Data Structures
Review (Linear Data Structures)
• Arrays
• Sequence of n items of same data type
• Stored contiguously in computer memory
• Each item is made accessible by specifying the value of the array’s index.
• Each and every array element can be accessed in the same constant amount
of time.
24
Fundamental Data Structures
Review (Linear Data Structures)
• Linked List
• Sequence of zero or more elements called nodes.
• Each node contains
• Some data and
• One or more links called pointers to other nodes of the linked list.
• Singly Linked List
• a node has a pointer only to its successor node
• Doubly Linked List
• a node has a pointer to both its successor and its predecessor
25
Fundamental Data Structures
Review (Linear Data Structures)
• List
• A finite sequence of data items
• Implement by using
• Arrays or
• Linked lists
• Special kinds of lists
• Stack &
• Queue
26
Fundamental Data Structures
Review (Linear Data Structures)
• Stack
• Only one end is used both for insertion and deletion
• Operates in LIFO fashion
• Queue
• One end is used for insertion and other end is used for deletion
• Operates in FIFO fashion
27
Algorithms Analysis Framework Introduction
• How to analyze an algorithm?
• Predicting the resources that the algorithm requires.
• Memory
• Communications Bandwidth
• Logic gates etc
• Computational time
28
Algorithms Analysis Framework Introduction
• Two parameters of measuring algorithm’s efficiency
1. Time Efficiency
◼ How fast an algorithm in question runs
2. Space Efficiency
◼ It deals with the extra space the algorithm requires
29