Basic Data Structures and Heaps
David Kauchak
•
Sorting demo (http://math.hws.edu/TMCM/java/xSortLab/)
•
Data structures
What is a data structure?
Way of storing data that facilitates particular operations.
We’ll talk about mostly about operations on a dymanic set:
Operations
:
For a set
S
–
Search
(
S,x
) - Does
x
exist in
S
?
–
Insert
(
S,x
) - Add
x
to
S
.
–
Delete
(
S,x
) - Given a pointer/reference to an element
x
, delete
it from
S
–
Minimum
(
S
) - Return the smallest element from
S
–
Maximum
(
S
) - Return the largest element from
S
•
Array
Sequential locations in memory in linear order. Element are accessed
via their index.
Read/write application of particular indices occur in Θ(1) time. In-
sert, delete, and most set operations (e.g.
Maximum
) occur in Θ(
n
)
time.
Representation
–
Search
- Iterate over elements until element is found -
O
(
n
)
1
This
preview
has intentionally blurred sections.
Sign up to view the full version.
–
Insert
- Create new array of size n+1. Copy elements and insert
new element - Θ(
n
)
–
InsertIndex
- Insert element and shift over all remaining ele-
ments - Θ(
n
)
–
Delete
- Delete element and shift down remaining elements -
Θ(
n
)
–
Minimum
- Search every element for the minimum - Θ(
n
)
–
Maximum
- Search every element for the maximum - Θ(
n
)
Uses?
•
Double Linked list
Objects are arranged linear. An element in the list points to the next
and previous element in the list.
Deletion of particular element occurs in Θ(1) time. Most other oper-
ations occur in Θ(
n
) time.
Representation
–
Search
- Iterate over elements by following links until element
is found - Θ(
n
)
–
Insert
- Add element to the beginning of the linked list and
update the head - Θ(1)
–
InsertIndex
- Iterate over elements until index is found and
insert element by updating links - Θ(
n
)
–
Delete
- Delete element and update pointers of previous and
next element - Θ(1)
–
Minimum
- Search every element for the minimum - Θ(
n
)
–
Maximum
- Search every element for the maximum - Θ(
n
)
Uses?
•
Stack
LIFO (last in first out)
Picture the stack of plates at a buffet
Can be implemented using an array or a linked list.

This is the end of the preview.
Sign up
to
access the rest of the document.
- Summer '09
- Algorithms, Data Structures, Sort, Binary heap, binomial heap, Priority queue
-
Click to edit the document details