Chapter 0
Chapter 0
Today
▪ Course information
▪ Lecture 0
– Introduction to data structures and algorithms
2
Course Information
05/23/2025 3
Course Objective
4
Learning Outcome
5
Course Contents
7
Tentative Assessment Criteria
Assessment Forms % of Given Submissio
credit week n week
allotted
Lecture 100%
▪ Hardware
– Desktop Computer or Laptop
▪ Software
– Code Blocks C++ compiler or other C++ compilers
9
References
▪ Textbook
– “Data Structures and Algorithms in C++” by A.
Drozdek (Brooks/Cole, 2001)
▪ Other
– “Data Structures and Algorithms with Object-Oriented
Design Patterns in C++” by B. R. Preiss.
– Any related Data Structures and Algorithms books.
10
Lecture 0: Introduction to
data structures and
algorithms
Introduction to DSA
▪ A famous quote:
– Program = Algorithm + Data Structure.
12
Example Program
15
Questions
16
What will you learn from this course
18
Efficiency
▪ Cost:
– The mount of resources that the solution consumes such as time and
memory space
▪ However, that does not mean we always strive for the most
efficient program.
– If the program works well within resource constraints, there is no19benefit
to making it faster or smaller.
A philosophy of data structures
22
How to select a good data
structure ?
23
Steps to select data structure
1. Analyze your problem to determine the basic
operations that must be supported. Examples
– inserting a data item into the data structure,
– deleting a data item from the data structure, and
– finding a specified data item etc…
▪ 2. Quantify the resource constraints for each operation.
– Such as Time
▪ 3. Select the data structure that best meets these
requirements.
– the “simplest” that meets requirements
▪ Note:-Resource constraints on key operations such
24 as
Abstract Data types-Definitions
▪ Integer ADT
– Values are …., -3, -2, -1, 0, 1, 2, 3, …..
– Operations are +, -, *, /, % …
▪ The abstract data type Integer is an infinite set
▪ The built-in data structure int is a particular
implementation of the abstract data type
Integer (4Byte)
▪ Another built-in data structure long int also
implements the same abstract type (8Byte)
27
Data structure Vs File structure
28
Problems, Algorithms and Programs
29
Algorithm
30
Algorithm Design
33
Example
• Two algorithms for computing the Factorial
• Which one is better?
• 2)
The one that takes less CPU time and memory space to run
1) int factorial (int n)
int factorial (int n)
{
{
if (n<=1) return 1;
if (n <= 1) return 1;
else {
else
fact = 1;
return n * factorial(n-1);
for (k=2; k<=n; k++)
}
fact *= k;
return fact;
}
34
Properties of Algorithm
▪ Finiteness:
– Algorithm must complete after a finite number of steps.
▪ Definiteness:
– Each step must be clearly defined, having one and only one interpretation. At
each point in computation, one should be able to tell exactly what happens next.
▪ Sequence:
– Each step must have a unique defined preceding and succeeding step. The first
step (start step) and last step (halt step) must be clearly noted.
▪ Feasibility:
– It must be possible to perform each instruction.
▪ Correctness:
– It must compute correct answer for all possible legal inputs.
▪ Language Independence:
– It must not depend on any one programming language.
35
Cont…
▪ Completeness:
– It must solve the problem completely.
▪ Efficiency:
– It must solve with the least amount of computational resources
such as time and space.
▪ Generality:
– Algorithm should be valid on all possible inputs.
▪ Input/Output:
– There must be a specified number of input values, and one or
more result values.
36
Program
37
Exercise
38
Next Time!!
Ch1:Review of C++