Professional Documents
Culture Documents
sidra.malik@ciitlahore.edu.pk
Course Information
Textbooks
Classic Data Structures
D. Samanta
2
Grading
Theory
Quizzes (3) ---------------15%
Assignments (3)---------10%
S-1 ------------------------ 10%
S-2 ------------------------ 15%
Final-------------------- 50%
Labs
Assignments/Exercises ---------- 15%
S1 and S2---------------------------- 25%
Final----------------------------------- 50%
3
What is Data Structure?
Data structure is a representation of data and the
operations allowed on that data.
5
Basic Data Structure
Basic Data Structures
6
array
Linked list
queue
tree stack
7
Selection of Data Structure
The choice of particular data model depends on
two consideration:
It must be rich enough in structure to represent the
relationship between data elements
The structure should be simple enough that one can
effectively process the data when necessary
8
Types of Data Structure
Linear: In Linear data structure, values are arrange in linear
fashion.
Array: Fixed-size
Linked-list: Variable-size
Stack: Add to top and remove from top
Queue: Add to back and remove from front
Priority queue: Add anywhere, remove the highest
priority
9
Types of Data Structure
Non-Linear: The data values in this structure are not
arranged in order.
Hash tables: Unordered lists which use a hash function to insert
and search
Tree: Data is organized in branches.
Graph: A more general branching structure, with less strict
connection conditions than for a tree
10
Type of Data Structures
Homogenous: In this type of data structures, values of the
same types of data are stored.
Array
11
Abstract Data Type
Definition:-
Abstract Data Types (ADTs) stores data and allow various
operations on the data to access and change it.
12
Abstract Data Type vs. Data Structure
A mathematical model, together with various operations defined on
the model
An ADT is a collection of data and associated operations for
manipulating that data
Data Structures
Physical implementation of an ADT
data structures used in implementations are provided in a language
(primitive or built-in) or are built from the language constructs (user-
defined)
13
Abstract Data Type
ADTs support abstraction, encapsulation, and
information hiding.
14
Abstract Data Type vs. Data Structure
Examples
List in ADT
Supporting Data Structures are matrix, linear list, tree, graph.
If we place list in ADT , users should not be aware of structure we use
As long as they can insert and retrieve data
15
The Core Operations of ADT
Every Collection ADT should provide a way to:
add an item
remove an item
find, retrieve, or access an item
16
Which Data Structure to Use?
17
List
A Flexible structure, because can grow and
shrink on demand.
Arrays and Link List
Elements can be:
Inserted
Accessed
Deleted
At any position
last
first
18
Linked Lists Vs Arrays
Advantage of Linear Linked Lists over Arrays
No need to shift elements in order to make room or to
remove an element
Easy insertion and deletion
19
Stacks
Collection with access only to the last element inserted
Last in first out
Data4 Top
insert/push
remove/pop Data3
top Data2
make empty
Data1
20
Queues
Collection with access only to the item that has been
present the longest
Last in last out or first in first out
enqueue, dequeue, front
priority queues and dequeue
Front Back
21
Tree
A Tree is a collection of elements called nodes.
One of the node is distinguished as a root, along with a
relation (parenthood) that places a hierarchical structure
on the nodes.
Root
22
Algorithms
An algorithm is a procedure for solving a problem in finite
number of steps
24
Analysis of Algorithms
Why need algorithm analysis?
Just writing a syntax-error-free program is not enough. We need to
know whether the algorithm is correct or not, i.e. whether it can
give correct answers for the inputs.
If the program is run on a large data set, the running time becomes
an issue. We want to know how the algorithm performs when the
input size is large. The program may be computationally inefficient,
or may need lots of memory. We analyze the resources that the
algorithm requires: memory, and computation time. We can also
compare algorithms without implementations.
25
Analysis of Algorithms
Analysis of Algorithm refers to calculating or guessing
resources needful for the algorithm.
Resources means computer memory, processing time
etc.
In all these factors, time is most important because the
program developed should be fast enough.
26
Analysis of Algorithms
Analysis of Algorithm refers to calculating or guessing
resources needful for the algorithm.
Resources means computer memory, processing time
etc.
In all these factors, time is most important because
the program developed should be fast enough.
27