You are on page 1of 6

LECTURE NOTES

COMP6601 – Data Structures

Week 9
Heap and Deap

COMP6601 – Data Structures


LEARNING OUTCOMES

1. Analyze the usage of data structure in application

2. Design a proper data structure needed in application

OUTLINE MATERI (Sub-Topic):

1. Pointer and Array Review


2. Types of Data Structures
3. Abstract Data Type
4. Structure Declaration
5. Structure Assignments
6. Nested Structure
7. Array of Structure

COMP6601 – Data Structures


ISI MATERI

1. Definition of HEAP
HEAP is a specialized tree-based data structure that satisfies the heap property: if “B” is
a child node of “A”, then key(“A”) ≤ key(“B”).
This implies that an element with the smallest key is always in the root node, and so such
a heap is sometimes called a min-heap. (Alternatively, if the comparison is reversed, the
greatest element is always in the root node, which results in a max-heap.)
The several variants of heaps are the prototypical most efficient implementations of the
abstract data type priority queues. Besides that, a heap is a complete binary tree, which
leads to the idea of storing it using an array. By utilizing array-based representation, we
can reduce memory costs while tree navigation remains quite simple.
A heap is stored in array level by level. The topmost level contains root only. It is mapped
to the first element of an array (with index 0).
Root's children are mapped to the second and third elements and so on. A heap is a
complete binary tree, which guarantees, that heap's nodes take up places in the array
compactly, making the mapping quite efficient.
Assume that the data inputted in Heap are 1, 5, 10, 13, 15, 18 and 11. Then, the heap will
look like

COMP6601 – Data Structures


Mapping formula:

Left(i) = 2 * n + 1 Right(i) = 2 * n + 2
for the example : 2*0 + 1 = 1 for the example : 2*0 + 2 = 2
value in index 1 is 5 value in index 2 is 10

Parent(i) = (n - 1) / 2

A deap is a double-ended heap that supports the double-ended priority operations of


insert, delete-min, and delete-max.
Similar to min-max heap but deap is faster on these operations by a constant factor, and
the algorithms are simpler.

COMP6601 – Data Structures


SIMPULAN

//Berisi simpulan SME terhadap materi

COMP6601 – Data Structures


DAFTAR PUSTAKA

1. Reema Thareja,. 2011. Data structures using C. OXFOR. New Delhi. ISBN:978-0-19-
806544-9

2.

COMP6601 – Data Structures

You might also like