DSA - Week 1
DSA - Week 1
Week 1
(Lecture 1 – 3)
BS(Computer Science)
3rd Semester
Lecturer: Mah Gul Bizanjo
[email protected]
Computer Systems Engineering & Sciences Department
LECTURE OUTLINE
Course Learning outcome
Course Details
Introduction to Data Structure
Why Do We Study DSA?
Illustration of DS
Data Structure Operations
Examples and Applications
COURSE LEARNING OUTCOMES
(THEORY + PRACTICAL)
Source: Higher Education Commission Pakistan. (2023). Revised curriculum of Higher Education Pakistan
2023 https://nceac.org.pk/Documents/Curriculums/BS%20Curriculm%20Computing%20Disciplines-2023.pdf
COURSE DETAILS
▪ Course Title: Data Structures
▪ Pre-requisites: Programming Fundamentals
▪ Course Code: CSC-212
▪ Semester: 3rd BS(Computer Science)
▪ Credit Hours (Theory): 03
▪ Lab Credit Hours (Lab) : 01
▪ Total Credit Hours : 3+1 = 04
MARKS BREAKDOWN
The goal is not to code only, but the goal is to code efficiently
Efficiency of a program:
✓ A program which takes least time to execute
✓ Which occupies minimum memory
✓ How much battery consumption it has?
✓ How much use of system buses ? etc.
ILLUSTRATION OF
DATA STRUCTURES
▪ For building a home you need
certain building blocks, wooden
planks and other raw material. On
the top of that you apply building
instructions and you get a home.
▪ Similarly, to build a software, you
need raw building blocks (Data
Structures) like array, linked list
graphs. On the top of that you
apply code instructions, which
operates on those data structures
and as result you get a software
application.
To be a good programmer, it’s a
compulsion to have a good
understanding of DS.
To build a window, you need
wooden planks but not bricks.
Similarly for a particular
program requirement, you need
the right type of data structure.
“USE THE RIGHT DATA
STRUCTURE FOR THE RIGHT
PROBLEM”
DATA STRUCTURE SPECIFIES
THE FOLLOWING FOUR THINGS:
1. Organization of data
2. Accessing methods of data
3. Degree of association
4. Processing methods
DATA STRUCTURE OPERATION
▪ The data appearing in our data structures are processed by means of
certain operations.
▪ There are multiple kinds of operations, among them most common
are given below basic operations:
1. Data Traversal
2. Data Searching
3. Data Insertion
4. Data Deletion
5. Data Sorting
6. Data Merging
7. Data Indexing
8. Concatenation
9. Finding Length
10. Etc.
DATA TRAVERSAL
Accessing or visiting each element of a data structure is called data traversal.
Purpose: Data traversal operation ensures that every item or element is visited,
enabling operations like searching, sorting, or modifying/updating data.
Example: 0 1 2 3
A 10 20 30 40
A 10 20 30 40
A 10 20 55 30 40
DATA DELETION
Removing or erasing an element from a data structure is called data
deletion
Example: 0 1 2 3
A 10 20 30 40
0 1 2
10 20 40
A
DATA SEARCHING
Finding the location of the desired node with a given key value, is called
data searching.
Example: 0 1 2 3
A 10 20 30 40
0 1 2 3
Unsorted Array/List : A 60 80 10 50
0 1 2 3
Sorted Array/List: 10 50 60 80
A
(Ascending order)
DATA MERGING
Combining two or more datasets of same type together into a single
unified data structure is called merging operation.
Two sorted arrays can be merged into a single sorted array using a two-
pointer approach.
Example:
A 10 20 30 40 B 60 50 70 80
0 1 2 3 0 1 2 3
C 10 20 30 40 50 60 70 80
REVIEW STRINGS
Example:
Length(“BUETK”)
Answer = 5
Length(“BALOCHISTAN”)
Answer = ?
Answer = 11
String
SUBSTRING
A substring is a small part of a string. It
can be accessed from a given string, by
using the substring operation.
Formula:
SUBSTRING=(string, initial position,
length)
Example:
Str = “diversification”
Substring(Str, 4, 9)
Answer = ? Sub Strings
DATA INDEXING
Finding the position of a substring in a sting is called data indexing. It locates the
starting position of the substring first, then locates the complete substring
concatenated with it.
Just like a book-index helps locate topics quickly,
Formula: INDEX(Text, Pattern) string indexing helps access characters efficiently
in programming
Example:
String1 = “University”
Find the index of substring “sity”
Solution:
INDEX (String1, “sity”)
Returned value = 7
DATA CONCATENATION
Joining two or more strings (or other
data structures), together, end-to-
end, without altering their internal
order, is called concatenation. It is
primarily used in strings.
Example:
String1 = “Happy”
String2 = “Learning”
Result= “HappyLearning”
CLASS TASK
Suppose T is the Text: “WeAreGoodStudents”,
Apply the following String operations on T.
1. SUBSTRING(T,1,4) = ?
2. LENGTH(SUBSTRING(T,1,4)) = ?
3.INDEX(T,”Good”) ?
EXAMPLE
A company contains employee file in
which each record contain the data for
a given employee. [Name, Address,
age, gender]. Write the operation
name for the following statement.
▪ Suppose a new person joins the
company.
▪ Suppose an employee dies.
▪ Suppose the company wants to
announce bonus for employees
greater than 40 years old.
THANK YOU
Lecturer:
Mah Gul Bizanjo
[email protected]