Week 01 - Introdutcion To Data Structures and ADT
Week 01 - Introdutcion To Data Structures and ADT
Week 01 - Introdutcion To Data Structures and ADT
(Week 01)
2
Computer Science Department
What is Data?
Data
• “facts and statistics collected together for reference or
analysis.” – Google
Types of data
• Textual, numeric, audio, video
Importance of data?
• primary purpose of computer programs is to store
and retrieve information, usually as fast as possible
3
Computer Science Department
Computer Program
• To exactly know, what is data structure? We must know:
-What is a computer program?
Computer Program
Solution
Problem
Process
Input (Algorithm) Output
(DS) (DS)
(Algorithm)
5
Computer Science Department
Basic Data Structures
Basic
Data Structures
Linear Non-Linear
Data Structures Data Structures
Linked Hash
Arrays Stacks Queues Trees Graphs
Lists Tables
6
Computer Science Department
array
Linked list
queue
tree stack
7
Computer Science Department
Data Structures Operations
Traversing: Accessing each record exactly once so that each data
items in the record is traversed (or visited)
Searching: Finding the location of the record with the given key
value or finding the location of all records which satisfy one or more
conditions
9
Computer Science Department
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
10
Computer Science Department
Type of Data Structures
• Homogenous: In this type of data structures, values of
the same types of data are stored.
– Array
11
Computer Science Department
Selection of Data Structure
- Each data structure has costs and benefits
(Rarely is one data structure better than another in
all situations)
- A data structure requires:
1: space for each data item it stores
2: time to perform each basic operation
3: programming effort
- Each problem has constraints on available time and
space (only after a careful analysis of problem
characteristics can we know the best data structure for
the task) 12
Computer Science Department
Selection of Data Structure
13
Computer Science Department
Characteristics of Data Structure
14
Computer Science Department
Characteristics of Data Structure
15
Computer Science Department
Characteristics of Data Structure
“I will, in fact, claim that the difference between a bad programmer and a
good one is whether he considers his code or his data structures more
important. Bad programmers worry about the code. Good programmers worry
about data structures and their relationships.”
16
Computer Science Department
Abstract Data Type (ADT) and
Data Structures
Abstract Data Type Data Structures
• ADT stores data and allow various • Physical implementation of an
operations on the data to access and ADT
change it • Data structures used in
• A mathematical model, together with implementations are provided in
various operations defined on the a language (primitive or built-in)
model or are built from the language
• An ADT is a collection of data and constructs (user-defined)
associated operations for • Each operation associated with
manipulating that data the ADT is implemented by one or
more subroutines in the
implementation
17
Computer Science Department
Abstract Data Type
• ADT is a way of looking at a data structure focusing on
what it does and ignoring how it does its job
• E.g. A stack is an ADT supporting push, pop and
isEmpty operations
• ADTs support abstraction, encapsulation, and
information hiding.
• Abstraction is the structuring of a problem into well-
defined entities by defining their data and operations.
• The principle of hiding the used data structure and to
only provide a well-defined interface is known as
encapsulation.
18
Computer Science Department
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
19
Computer Science Department
Some frequently used DS.
20
Computer Science Department
Stacks
• Collection with access only to the last
element inserted
• Last in first out Data4 Top
• insert/push Data3
• remove/pop Data2
• top Data1
• make empty
21
Computer Science Department
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
23
Computer Science Department
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
24
Computer Science Department