0% found this document useful (0 votes)
24 views39 pages

Chapter 0

The document outlines a course on Data Structures and Algorithms (DSA) aimed at teaching students the fundamental techniques for designing and analyzing efficient algorithms and utilizing various data structures. Key topics include complexity analysis, sorting, searching algorithms, and practical applications through lectures, demonstrations, and projects. Students will learn to design algorithms to solve real-life problems while considering efficiency and resource constraints.

Uploaded by

hithere1234
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views39 pages

Chapter 0

The document outlines a course on Data Structures and Algorithms (DSA) aimed at teaching students the fundamental techniques for designing and analyzing efficient algorithms and utilizing various data structures. Key topics include complexity analysis, sorting, searching algorithms, and practical applications through lectures, demonstrations, and projects. Students will learn to design algorithms to solve real-life problems while considering efficiency and resource constraints.

Uploaded by

hithere1234
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 39

DSA

Today

▪ Course information
▪ Lecture 0
– Introduction to data structures and algorithms

2
Course Information

05/23/2025 3
Course Objective

▪ This course aims to introduce you some


basic data structures and algorithms
which are to be used as tools in designing
solutions to problems.

4
Learning Outcome

▪ At the end of this course students are expected to:


– Explain the basic techniques for the design and analysis of
efficient Algorithm;
– Determine when and how to use the various data
structures including Linked lists, Queues, Stacks, Binary
trees and Search trees.
– Design algorithms to solve real-life problems using the
tools introduced, analyze your solution and efficiently
implement your solution.
– Apply data structures and algorithms that are frequently
used in information processing

5
Course Contents

1. Review of C++ concepts


2. Complexity analysis
3. Sorting and Searching algorithm
4. Linked Lists
5. Stack and Queues
6. Recursion
7. Binary Trees
8. Hashing
6
Teaching Strategy

▪ The course will be delivered in the form of


– Lectures
– Demonstration
– Student presentations
– Group discussions, and
– Individual and group project works.

7
Tentative Assessment Criteria
Assessment Forms % of Given Submissio
credit week n week
allotted
Lecture 100%

 Participation and Attendance 5 - -


 Quizzes (All the quizzes will be 15 - -
unannounced and there will be no
makeup quizzes) 10 10 14
 Assignments 20 7 -
 Test 50 16 -
 Final examination
Practice 100%

 Participation and Attendance 5 - -


8
 Lab assignment 25 4,9 7,11
Required SW/HW

▪ 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

▪ Program is written in order to solve a problem


▪ A solution to a problem(program) actually
consists of two things:
– A way to organize data (data structures)
– Sequence of steps needed to solve the problem
(Algorithm)

▪ A famous quote:
– Program = Algorithm + Data Structure.

12
Example Program

▪ Read two integers and output their sum


#include <iostream>
using namespace std;
int main()
{
int i, j;
cin >> i >> j;
cout << i+j << endl;
Return 0;
}
13
Data structures

▪ Variables i and j are used to represent


integers
– They form the data structure
– int data type is available as part of the C++
programming language
– A data structure is also called a data type in a
programming language
– The data type of a variable defines
▪ its possible values and
▪ the operations that can be performed on it
14
Algorithm

▪ The main function defines the algorithm


– This uses the built-in operation + for adding
int variables
– It also uses functions defined in the iostream
library for reading and printing int variables
– Many commonly required data structures and
algorithms are available as built-in types or as
part of libraries

15
Questions

▪ Will this program correctly add two integers


always?
– If not, under what conditions is it guaranteed to
work correctly?
▪ What are other possible built-in data
structures that could have been used in this
program?

16
What will you learn from this course

▪ As we said, in this course, we will study:


– Algorithms
▪ Sequence of steps the needs to be followed to solve problems
– Data structures
▪ A means for efficiently storing, accessing, and modifying data

▪ Specifically, you are going to learn


1. A collection of more commonly used data structures and
algorithms-”programmers’ basic toolkit”
2. Tradeoffs associated with data structures and algorithms preferred
▪ Usually, done by comparing space and time required by each DS and AL
3. How to measure quality of a given data structure and algorithms
▪ Allow you to judge the merits of new data structures that you or others might invent
17
Computer program design goals

▪ There are two basic design goals(sometimes conflicting)


1. To design algorithm that is easy to understand, code and
debug
2. To design algorithm that makes efficient use of the computer’s
resources
▪ “Elegant program” satisfies both of the above goals

▪ The codes we write for this course needed to be elegant


but our primary concern is goal 2 (i.e. efficiency).
– Goal 1 is primarily the concern of software engineering

18
Efficiency

▪ A solution is said to be efficient if it solves the problem within


its resource constraints or less cost
▪ Constraints:
– Space (typical for many programs )
– Time (specially for real time systems)
– Bandwidth etc…

▪ 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

▪ Question: -processor speed and memory size still


continue to improve, will not today’s efficiency
problem be solved by tomorrow’s hardware ?
– The answer is no, our history proved it.

▪ Reasons:- as we develop more powerful computers,


that addition is being used to tackle more complex
problems
– More sophisticated user interface
– Bigger problem sizes
– New problems previously deemed unfeasible
20
What is Data structure?

▪ A data structure is any data representation and its


associated operations.
– Example int and float can be viewed as simple data structures
– Operations: support similar operations +,*,/,% etc
▪ Commonly, people use the term “data structure”
to mean an organization or structuring of
collection of data items
– Example, List of integers stored in array
▪ Data can be represented in computer using different
data structures
– Example, list of integers can be represented using array
21
or
another data structure called linked list
Types of Data Structures

22
How to select a good data
structure ?

▪ There are different ways to organize data in computer


– In other words, Data structures

– And, there is no ultimate data structure that fits to


every problem
– Each data structure has associated costs and benefits(trade-
offs)

▪ The choice to use a particular data structure depends


on our requirements

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

▪ A type is a collection of values.


– Example
▪ Boolean type consists of values true and false

▪ Simple type is a type/values that contains no sub parts


– Example, int, float,…

▪ Aggregate/composite type: its value has subparts.


– Example student type has parts like name, idno, gpa…

▪ A data item is a member of a type.


▪ A data type is a type together with a collection of operations
to manipulate the type.
– Example, int variable is a member of the integer data type and addition
is example operation on int data type 25
Abstract Data Type (ADT)

▪ An abstract data type (ADT) is the


specification/definition of a data type within some
language, independent of an implementation.
– An ADT doesn’t specify how the data type is implemented
– Rather it only specifies a set of values and a set of operations on
that data type
– Each ADT operation is implemented by a function/method.

▪ A data structure is the implementation of an ADT.


▪ In OOP languages, an ADT and its implementation
together makes up a class.
26
– Each operation of ADT is implemented by the member methods.
Example

▪ 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

▪ Data structure: usually refers to an


organization for data in main memory.
▪ File structure: an organization for data on
peripheral storage, such as a disk drive or tape.

28
Problems, Algorithms and Programs

▪ Problem is a task to be performed.


– Best thought of as inputs and matching outputs.
▪ Example given id, find the detail of students

– Problem definition may include constraints on the


resources that may be consumed by any acceptable
solution.
▪ The search algorithm Shall return in less than 2 seconds

29
Algorithm

▪ Algorithms are steps that need to be followed


to solve a problem.
– A recipe
▪ An algorithm takes the input to a problem and
transforms it to the output.
– A mapping of input to output

30
Algorithm Design

▪ You have a problem to solve


– Analyze the problem and identify the
requirements
– Design an efficient algorithm
▪ Use good data structures
– Show that your algorithm works!
▪ Prove its correctness
– Study the efficiency of your algorithm
▪ Run time
▪ Storage required
31
Algorithm Design

▪ Algorithm can be represented in different ways


▪ The common once are
– Pseudo code - a much natural language like representation
– Flow chart – diagrammatic representation using different
symbols
Problem − Design an algorithm to add two
numbers and display the result.
step 1 − START
step 2 − declare three integers a, b &
c
step 3 − define values of a & b
step 4 − add values of a & b
step 5 − store output of step 4 to c
step 6 − print c
step 7 − STOP
32
Algorithm Design

▪ For a problem given, we might come up with different algorithms

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

▪ A computer program is an instance, or concrete


representation, for an algorithm in some
programming language.
– We frequently interchange use of “algorithm” and
“program” though they are actually different concepts

37
Exercise

▪ Define abstract data type BankAccount


– AccNo, Name, Balance
▪ Define all operations on BankAccount object
– Deposit, Withdraw, CheckBalance
▪ Build a data structure for implementing this
abstract type

38
Next Time!!
Ch1:Review of C++

You might also like