Lec01 AF
Lec01 AF
01
Data Structures
M. Affan Aleem
Data Structures
Prepares the students for (and is a
prerequisite for) the more advanced
material students will encounter in later
courses.
Cover well-known data structures such as
arrays, linked lists, stacks, queues, tree
and graphs.
Implement data structures in C++/c#
Grading
Hourly 02 20%
Quizzes06 10%
Assignments 03 5%
Lab Exam 01 5%
Projects01 20%
Final Exam 01 40%
Data Structures
In computer science, a data structure is a
particular way of storing and organizing
data in a computer so that it can be used
efficiently.
AL
AL
AL
AL
AL
Array
Linked List
Stack
Queue
AL
10
Example
i. Tree
ii. Graph
AL
11
Traversing
Searching
Inserting
Deleting
Sorting
Merging
12
Organizing Data
Any organization for a collection of records
that can be searched, processed in any
order, or modified.
The choice of data structure and algorithm
can make the difference between a
program running in a few seconds or many
days.
Efficiency
A solution is said to be efficient if it solves
the problem within its resource constraints.
Space
Time
Arrays
A linear array is a list of a finite number n
of homogenous data elements (i.e. data
elements of the same type) such that:
a) The elements of the array are
AL
17
Arrays contd
b) The elements of the array are stored
respectively in successive memory
locations.
The number n of elements is called the
length or size of the array.
Length = UB LB + 1
AL
18
Example
Let DATA be a 4-element linear array of
integers such that
DATA[1] = 247,
DATA[3] = 249,
DATA[2] = 56,
DATA[4] = 87
DATA
247
2
56
249
87
19
Arrays contd
Array Layout
Array cells are
contiguous in
computer memory
The memory can be
thought of as an
array
x[0]
x[1]
x[2]
x[3]
x[4]
x[5]
Dynamic Arrays
23
Dynamic Arrays
AL
25
26
27
Example
Consider the array AUTO an ARRAY, which
records the number of automobiles, sold each year
from 1932 through 1984. Base(AUTO) = 200, and
w = 4 words per memory cell for AUTO,
Then LOC(AUTO[1932]) = 200,
LOC(AUTO[1933]) = 204 The address of the array
element for the year K = 1965 can be obtained
AL
28
Example contd
LOC(AUTO[1965]) = Base(AUTO) +
w(1965 lower bound)
LOC(AUTO[1965]) = 200 + 4(1965
1932)
LOC(AUTO[1965]) = 332
AL
29
Example
Consider an integer ARRAY A, which records
the integer numbers. The index of the array
from 1 to 62 and base(A) = 150. Find the
memory location of LOC(A[38]) ?
AL
30