Lecture 1
1
Design and Analysis of Algorithms
Adnan Rashid
Adnan Rashid
CS-251: Design and
Analysis of Algorithms
(Spring 2023)
Email: adnan.rashid@seecs.edu.pk
Web: http://save.seecs.nust.edu.pk/adnanrashid/
Outline
▪ Course Objectives
▪ Introduction
▪ Assessment Plan
▪ What is an algorithm?
▪ About us
▪ General Instructions
2
Design and Analysis of Algorithms
Adnan Rashid
▪ Algorithm vs Program
▪ Properties of Algorithms
Lecture’s Content
Introduction to Algorithms (4th Edition) by
Thomas H. Cormen et al.
Section 1.1 (Page 28 onwards)
3
Design and Analysis of Algorithms
Adnan Rashid
Objectives of Course
Objective 1: Understand the operation, implementation
and performance of fundamental algorithms and data
structures, and the relative merits and suitability of each
for various applications
4
Design and Analysis of Algorithms
Adnan Rashid
Objective 2: Ability to model and implement efficient
software solutions for various application areas using
appropriately selected algorithms and data structures
Objective 3: Ability to analyze data structures and
algorithms, to compare and evaluate them with respect to
time and space requirements, in order to make the most
appropriate design choices when solving real-world problems
Algorithm Definition
▪ An algorithm is a step-by-step procedure for solving a
particular problem in a finite amount of time
▪ More generally, an algorithm is any well-defined
computational procedure that takes collection of elements
as input and produces a collection of elements as output
5
Design and Analysis of Algorithms
Adnan Rashid
Input
X
Some mysterious
processing
Output
Y = F(X)
ALGORITHM
F: X→Y
Algorithm: Examples
6
Design and Analysis of Algorithms
Adnan Rashid
▪ Repairing a lamp
▪ Matrix multiplication
▪ Calling a friend on the phone
▪ The rules of how to play a game
▪ Directions for driving from A to B
▪ A car repair manual
▪ Human brain project
▪ Internet and communication links (Graphs)
▪ A cooking recipe
Algorithm vs Program
▪ A computer program is an instance, or concrete representation,
for an algorithm in some programming language
▪ Set of instructions, which the computer follows to solve a problem
Problem
High Level
Language
Program
Algorithm: A sequence of
instructions describing
how to do a task
7
Design and Analysis of Algorithms
Adnan Rashid
Solving Problems
8
Design and Analysis of Algorithms
Adnan Rashid
When faced with a problem:
1. First clearly define the problem
2. Think of possible solutions
3. Select the one that seems the best under the prevailing
circumstances
4. And then apply that solution
5. If the solution works as desired, fine; else go back to
Step 2
Solving Problems:
General Solution-Algorithm
9
Design and Analysis of Algorithms
Adnan Rashid
▪ It is quite common to first solve a problem for a
particular case
▪ Then for another
▪ And, possibly another
▪ And watch for patterns and trends that emerge
▪ And to use the knowledge from these patterns and
trends in coming up with a general solution
▪ And this general solution is called an algorithm
One Problem, Many
Algorithms
10
Design and Analysis of Algorithms
Adnan Rashid
Problem
▪ The statement of the problem specifies, in general
terms, the desired input/output relationship
Algorithm
▪ The algorithm describes a specific computational
procedure for achieving input/output relationship
▪ Sorting a sequence of numbers into non-decreasing order
Example
▪ Various algorithms e.g., merge sort, quick sort, heap
sorts etc.
Algorithms
Problem Instances
11
Design and Analysis of Algorithms
Adnan Rashid
▪ An input sequence is called an instance of a Problem
▪ A problem has many particular instances
▪ An algorithm must work correctly on all instances of
the problem it claims to solve
▪ Many interesting problems have infinitely many
instances
▪ Since computers are finite, we usually need to limit the
number and/or size of possible instances in this case
▪ This restriction doesn’t prevent us from doing analysis
in the abstract
Properties of Algorithms
12
Design and Analysis of Algorithms
Adnan Rashid
▪ It must be composed of an ordered sequence of precise
steps
▪ It must have a finite number of well-defined instructions
/steps
▪ The execution sequence of instructions should not be
ambiguous
▪ It must be correct
▪ It must terminate
Syntax and Semantics
13
Design and Analysis of Algorithms
Adnan Rashid
An algorithm is “correct” if
its:
▪ Semantics are correct
▪ Syntax is correct
Semantics:
▪ The concept embedded in
an algorithm (the soul!)
Syntax:
▪ The actual representation
of an algorithm (the body!)
WARNINGS:
1. An algorithm can be
syntactically correct,
yet semantically
incorrect – dangerous
situation!
2. Syntactic
correctness is easier
to check as compared
to semantic
correctness
Algorithm Summary
14
Design and Analysis of Algorithms
Adnan Rashid
▪ Problem Statement
▪ Relationship between the input and output
▪ Algorithm
▪ Procedure to achieve the relationship
▪ Definition
▪ A sequence of steps that transform the input to output
▪ Instance
▪ The input needed to compute solution
▪ Correct Algorithm
▪ For every input it halts with correct output
About Us
▪ Instructor
▪ Dr. Adnan Rashid (A-226, Faculty Block, SEECS)
▪ Contact: adnan.rashid@seecs.edu.pk
▪ Telephone: +92 51 9085 2176
▪ Web: http://save.seecs.nust.edu.pk/adnanrashid/
https://seecs.nust.edu.pk/faculty/adnan-rashid/
15
Design and Analysis of Algorithms
Adnan Rashid
Course Updates
▪ Updates (on LMS, Email):
▪ Updates and Discussions (on WhatsApp):
https://tinyurl.com/yckj3x52
16
Design and Analysis of Algorithms
Adnan Rashid
Assessment Plan
(Tentative)
21
Compiler Construction
Adnan Rashid
▪ 40% Final Exam (Closed Books, Closed Notes, Comprehensive)
▪ 30% Mid Term (Closed Books, Closed Notes, Comprehensive)
▪ 10% Quizzes (Minimum 05, Surprise!)
▪ 10% Project
▪ 10% Assignments (Minimum 03)
Homework/Assignment
Policy
22
Compiler Construction
Adnan Rashid
▪ All homework assignments must be done individually
or as directed
▪ May also require uploading a soft-copy on LMS (for
plagiarism check)
▪ Cheating
▪ Helping others, getting help, looking up websites for
solutions etc.
▪ Late Submissions
▪ Late submission will get a –20% penalty up to one day
▪ -40% penalty up to 2 days (No acceptation after 2
days from deadline)
Homework/Assignment
Policy
23
Compiler Construction
Adnan Rashid
▪ Any deviation from the above rule will be considered
cheating and will be subject to the SEECS academic
dishonesty policy
▪ Contact instructor at least 03 days before the
deadline in case of emergency
http://seecs.nust.edu.pk/Internal/downloads/downloads/SE
ECS_Plagiarism_Policy_Dec2010_v1.0.pdf
Lecture Basics
24
Compiler Construction
Adnan Rashid
▪ Classes will mainly involve Slides
▪ Lectures (pdf) will be available on LMS
▪ However, no scribes from the class will be made
available
▪ Therefore, take your own notes in the class
▪ For latest/updated slides, download before each use
▪ As I might update/correct slides at any stage