• Tidak ada hasil yang ditemukan

Think Different Materi ASD 2014 pertemuan_17

N/A
N/A
Protected

Academic year: 2017

Membagikan "Think Different Materi ASD 2014 pertemuan_17"

Copied!
30
0
0

Teks penuh

(1)
(2)

Heaps

(3)

Heaps

A

heap

is a

certain kind

of complete

binary tree.

When a complete binary tree is built, its first node must be

the root.

(4)

Heaps

Complete

binary tree.

Left child of the

root

The second node is always the left child

(5)

Heaps

Complete

binary tree.

Right child of the root

The third node is always the right child

(6)

Heaps

Complete

binary tree.

(7)

Heaps

Complete

binary tree.

The next nodes always fill the next

(8)

Heaps

Complete

binary tree.

The next nodes always fill the next

(9)

Heaps

Complete

binary tree.

The next nodes always fill the next

(10)

Heaps

(11)

Heaps

A heap is a

certain

kind

of complete

binary tree.

Each node in a heap contains a key that can be compared to

other nodes' keys. 19

4 22

21 27

23 45

(12)

Heaps

A heap is a

certain

kind

of complete

binary tree.

The "heap property" requires that each node's key is >= the

keys of its children 19

4 22

21 27

23 45

(13)

Adding a Node to a Heap

Put the new node in

the next available spot.

Push the new node

upward, swapping with its parent until the new node reaches an

acceptable location. 19

4 22

21 27

23 45

35

(14)

Adding a Node to a Heap

Put the new node in

the next available spot.

Push the new node

upward, swapping with its parent until the new node reaches an

acceptable location. 19

4 22

21 42

23 45

35

(15)

Adding a Node to a Heap

Put the new node in

the next available spot.

Push the new node

upward, swapping with its parent until the new node reaches an

acceptable location. 19

4 22

21 35

23 45

42

(16)

Adding a Node to a Heap

The parent has a key that is >= new node, or

The node reaches the root.

The process of

(17)

Removing the Top of a Heap

Move the last node

onto the root.

19

4 22

21 35

23 45

42

(18)

Removing the Top of a Heap

Move the last node

onto the root.

19

4 22

21 35

23 27

(19)

Removing the Top of a Heap

Move the last node

onto the root.

Push the out-of-place

node downward, swapping with its larger child until the new node reaches an acceptable location. 19

4 22

21 35

23 27

(20)

Removing the Top of a Heap

Move the last node

onto the root.

Push the out-of-place

node downward, swapping with its larger child until the new node reaches an acceptable location. 19

4 22

21 35

23 42

(21)

Removing the Top of a Heap

Move the last node

onto the root.

Push the out-of-place

node downward, swapping with its larger child until the new node reaches an acceptable location. 19

4 22

21 27

23 42

(22)

Removing the Top of a Heap

The children all have keys <= the out-of-place node, or

The node reaches the leaf.

The process of

(23)

Implementing a Heap

We will store

the data from

the nodes in a

partially-filled

array.

An array of data

21 27

23 42

(24)

Implementing a Heap

Data from the

root goes in the

first

location

of the

array.

An array of data

21 27

23 42

35

(25)

Implementing a Heap

Data from the

next row goes

in the next two

array locations.

An array of data

21 27

23 42

35

(26)

Implementing a Heap

Data from the

next row goes

in the next two

array locations.

An array of data

21 27

23 42

35

(27)

Implementing a Heap

Data from the

next row goes

in the next two

array locations.

An array of data

21 27

23 42

35

42 35 23 27 21

(28)

Important Points about the

Implementation

The links between the tree's nodes are not actually stored as pointers, or in any other way.

The only way we "know" that "the array is a tree" is from the way we manipulate the data.

An array of data

21 27

23 42

35

(29)

Important Points about the

Implementation

If you know the index of a

node, then it is easy to figure out the indexes of that

node's parent and children. Formulas are given in the book.

[1] [2] [3] [4] [5]

21 27

23 42

35

(30)

A heap is a complete binary tree, where the

entry at each node is greater than or equal

to the entries in its children.

To add an entry to a heap, place the new

entry at the next available spot, and

perform a reheapification upward.

To remove the biggest entry, move the last

node onto the root, and perform a

reheapification downward.

Referensi

Dokumen terkait

Utilising as raw material only the fibrous frac- tion of miscanthus plants, the objectives of the present study were: (a) to investigate the feasibil- ity of obtaining papermaking

Fine chopping of stalk materials significantly influence compacting density and is more prefer- able to heating, because energy requirement for chopping − 25 kJ / kg is one order

The lactide ring opening polymerisation reaction reaches the state of equilibrium within the resi- dence time of the reactive material inside the extrusion system and can thus be

Dinyatakan LULUS / TIDAK LULUS dengan perbaikan skripsi seperti tercantum dalam tabel berikut dan dengan jangka waktu perbaikan 1 (satu)

Several rheological parameters (e.g. fracture stress and energy) were calculated from stress – strain curves and compared to those of citrus pectin and algal alginate gel

Yang bertanda tangan di bawah ini menyatakan dengan sebenarnya, bahwa mahasiswa : Nama : NIM : Jurusan : ..4. Telah bebas dari tanggungan pinjaman selama tahun akademik

This, together with the fact that the acidified plant juice is an excellent medium for par example amino acid producing strains of Corynebacterium glutamicum , leads us to

Dengan ini mengajukan pergantian Dosen Pembimbing Skripsi dari &lt;&lt;Bapak/ Ibu Nama Dosen&gt;&gt; yang saat ini bertindak sebagai &lt;&lt;Dosen Pembimbing I/II&gt;&gt;