2.02.data Structures and Algorithms
2.02.data Structures and Algorithms
Data Structures
and Algorithms
Douglas
Douglas Wilhelm
Wilhelm Harder,
Harder, M.Math.
M.Math. LEL
LEL
Department
Department of of Electrical
Electrical and
and Computer
Computer Engineering
Engineering
University
University of
of Waterloo
Waterloo
Waterloo,
Waterloo, Ontario,
Ontario, Canada
Canada
ece.uwaterloo.ca
ece.uwaterloo.ca
dwharder@alumni.uwaterloo.ca
dwharder@alumni.uwaterloo.ca
©
© 2006-2013
2006-2013 by
by Douglas
Douglas Wilhelm
Wilhelm Harder.
Harder. Some
Some rights
rights reserved.
reserved.
Data Structures and Algorithms
2
2.2 Outline
Prototypical examples:
– Contiguous allocation: arrays
– Linked allocation: linked lists
Data Structures and Algorithms
4
Contiguous, adj.
Touching or connected throughout in an unbroken sequence.
Meriam Webster
2.2.1
2.2.1.1 Contiguous Allocation
1 2 3
4 5 6
Data Structures and Algorithms
13
2.2.2.2 Trees
2.2.2.2 Trees
2.2.2.2 Graphs
2.2.2.2 Arrays
A
B
C
D
E
F
G
H
I
J
K
L
Data Structures and Algorithms
20
The Unix inode was used to store information about large files
– The first twelve entries can reference the first twelve blocks (48 KiB)
Data Structures and Algorithms
22
The Unix inode was used to store information about large files
– The next entry is a pointer to an array that stores the next 1024 blocks
The Unix inode was used to store information about large files
– The next entry has two levels of indirection for files up to 4 GiB
Data Structures and Algorithms
24
The Unix inode was used to store information about large files
– The last entry has three levels of indirection for files up to 4 TiB
Data Structures and Algorithms
25
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
2.2.3 Operations
Arbitrary
Front/1st Location Back/nth
Find Good Okay Good
Insert Bad Bad Good* Bad
Erase Bad Bad Good
*
only if the array is not full
Data Structures and Algorithms
28
Arbitrary
Front/1st Location Back/nth
Find Good Bad Good
Insert Bad Bad Good* Bad
Erase Bad Bad Good
*
only if the array is not full
Data Structures and Algorithms
29
However, for a singly linked list where we a head and tail pointer, we
have:
Arbitrary
Front/1st Location Back/nth
Find Good Bad Good
Insert Good Bad Good
Erase Good Bad Bad
Data Structures and Algorithms
30
– Note, this requires a little bit of trickery: we must modify the value
stored in the kth node
– This is a common co-op interview question!
Data Structures and Algorithms
31
Arbitrary
Front/1st Location Back/nth
Find Good Bad Good
Insert Good Good Good
Erase Good Good Good
Data Structures and Algorithms
32
Following Classes
Following Classes
Summary
References
Wikipedia, https://en.wikipedia.org/wiki/Data_structure
These slides are provided for the ECE 250 Algorithms and Data Structures course. The
material in it reflects Douglas W. Harder’s best judgment in light of the information available to
him at the time of preparation. Any reliance on these course slides by any party for any other
purpose are the responsibility of such parties. Douglas W. Harder accepts no responsibility for
damages, if any, suffered by any party as a result of decisions made or actions based on these
course slides for any other purpose than that for which it was intended.