_2.Data_structures_and_algorithms
_2.Data_structures_and_algorithms
and Algorithms
Data Structures and Algorithms
2
2.2 Outline
Prototypical examples:
– Contiguous allocation: arrays
– Linked allocation: linked lists
Data Structures and Algorithms
4
2.2.1.1 Memory Allocation
Contiguous, adj.
Touching or connected throughout in an unbroken sequence.
Meriam Webster
1 2 3
4 5 6
Data Structures and Algorithms
13
2.2.1.3 Indexed Allocation
A
B
C
D
E
F
G
H
I
J
K
L
Data Structures and Algorithms
20
2.2.2.3 Linked Arrays
Once we have chosen a data structure to store both the objects and
the relationships, we must implement the queries or operations as
algorithms
– The Abstract Data Type will be implemented as a class
– The data structure will be defined by the member variables
– The member functions will implement the algorithms
Arbitrary
Front/1st Back/nth
Location
Find ? ? ?
Insert ? ? ?
Erase ? ? ?
Data Structures and Algorithms
23
2.2.3.1 Operations on Sorted Lists
Arbitrary
Front/1st Back/nth
Location
Find Good Okay Good
Insert Bad Bad Good* Bad
Erase Bad Bad Good
Arbitrary
Front/1st Back/nth
Location
Find Good Bad Good
Insert Bad Bad Good* Bad
Erase Bad Bad Good
However, for a singly linked list where we a head and tail pointer, we
have:
Arbitrary
Front/1st Back/nth
Location
Find Good Bad Good
Insert Good Bad Good
Erase Good Bad Bad
Data Structures and Algorithms
26
2.2.3.3 Operations on Lists
Arbitrary
Front/1st Back/nth
Location
Find Good Bad Good
Insert Good Good Good
Erase Good Good Bad
Data Structures and Algorithms
27
2.2.3.4 Operations on Lists
Arbitrary
Front/1st Back/nth
Location
Find Good Bad Good
Insert Good Good Good
Erase Good Good Good