Lecture 01
Lecture 01
Algorithms
Data Structures and
Content • ADTs
• Stacks
• Queues
• Lists
3
10/9/2020
What is a Data Structure?
• Data structure is a representation of data and the operations allowed on that
data.
• A data structure is a way to store and organize data in order to facilitate
the access and modifications.
• Data Structures are the method of representing of logical relationships
4
10/9/2020
Basic Data Structures
Basic Data Structures
5
e
tre e
queu
k
stac
y
list
arra
Linked
7
10/9/2020
Types of Data Structures
❑ Linear: In Linear data structure, values are arranged in a linear
fashion.
▪ Array: Fixed-size
8
10/9/2020
Types of Data Structures
❑ 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
▪ Graph: A more general branching structure, with less strict connection conditions than for a
tree
9
10/9/2020
Type of Data Structures
❑ Homogenous: In this type of data structures, values of the same types
of data are stored.
▪ Array
▪ Structures
▪ Classes
10
10/9/2020
Abstract Data Types and Data Structures
❑ Definition:
▪ Abstract Data Types (ADTs) stores data and allow various operations on the
data to access and change it.
▪ 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
11
10/9/2020
Abstract Data Types
▪ ADTs support abstraction, encapsulation, and information
hiding.
12
10/9/2020
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
13
“No single data structure works well
for all purposes, and so it is
important to know the strengths
and limitations of several of them”
14
10/9/2020
Stacks
• Collection with access only to the last element inserted
• Last in first out
• insert/push
• remove/pop
• top/peek
• make empty
Data3
Data2
Data1
15
10/9/2020
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
16
10/9/2020
List
• A Flexible structure, because can grow and shrink on demand.
Elements can be:
▪ Inserted
▪ Accessed
▪ Deleted
last
first
17
10/9/2020
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
18
Stacks
❑ A stack is a list in which insertion and deletion take place at the same
end
▪ This end is called top
▪ The other end is called bottom
❑ Stack Underflow
▪ When there is no element in the stack, the status of stack is known as stack
underflow.
❑ Static Implementation
▪ Stacks have fixed size, and are implemented as arrays
▪ It is also inefficient for utilization of memory
Textbooks
• Introduction to Data Structures in C by Ashok N. Kamthane
• Data Structures and Algorithms by A. V. Aho, J. E. Hopcroft, J. D. Ullman
27
10/9/2020
“The secret of getting ahead is getting
started. The secret of getting started is
breaking your complex overwhelming
tasks into small manageable tasks, and
28