Beruflich Dokumente
Kultur Dokumente
Priority Queues
PQ-Sort
Selection Sort
Insertion Sort
Quadratic Probing
Double Hashing
D. S. R. Murthy DSA-5 Basic Data Structures (Contd…) 2
Priority Queues
Key
Object assigned to an element as a specific attribute
for that element.
Used to identify rank / weight of the element.
Assigned to an element by user or application.
Priority queue
Container of elements.
Each element has an associated key provided at the
time of insertion.
Elements are inserted and removed based on the
keys.
Sorting
Arranging the given list in ascending / descending
order, with respect to a given key field.
D. S. R. Murthy DSA-5 Basic Data Structures (Contd…) 3
Heap
Kj ≤ Ki for 2 ≤ j ≤ n and i = j/2.
Heap sort
Construction phase (Up-Heap Bubbling)
Construction Phase
Inserting a new element in a tree structure.
Traversal Phase
Trace of the traversal phase of the heap for the elements
42, 23, 74, 11, 65, 58, 94, 36, 99, 87.
D. S. R. Murthy DSA-5 Basic Data Structures (Contd…) 5
Computer Dictionary
Similar to Paper Dictionary of words.
Users can assign keys to elements and then use later
to look up or remove elements.
Hash code
Mapping the key k to an integer.
Compression map
Mapping the hash code to an integer within the
range of indices of an array.
Linear Probing
To insert an item (k, e) into a slot
If A[i] is already occupied, where i = h(k)
then try next at A[(i+1) mod N].
If A[(i+1) mod N] is also occupied,
then try A[(i+2) mod N]
and so on
until an empty slot in A is found
and insert the item (k, e).
Quadratic Probing
Involves iteratively trying the slots
A[(i + f(j)) mod N], for j = 0, 1, 2, …,
where f(j) = j2
until finding an empty slot.
Double Hashing
Choose a secondary hash function h’.
if h maps some key k to a slot A[i], with i = h(k),
that is already occupied
then iteratively try the slots
A[(i +f(j) mod N] next, for j = 1, 2, 3, …,
where f(j) = j.h’(k).