Todos os livros

Profissional

Apps Sobre Coach Entrar Começar a ler

Computer Science · Glossário

O que é Sift up, sift down, heapify?

Também chamado de: sift up · sift down · heapify

Definition 18.5 University Computer Science — Year 1 · Capítulo 18 — Heaps and Priority Queues

To sift up a node is to exchange it with its parent as long as its key is smaller. To sift down a node is to exchange it with its smaller child as long as that child’s key is smaller. To heapify an array is to make it a heap by sifting down every node that has a child, from the last one back to the root.

Extract-min on the heap [1, 3, 2, 6, 4, 5, 7, 8, 9, 10]: the last leaf, 10, replaces the root 1 (left); it is exchanged with its smaller child 2 (middle), then with 5 (right), where both its subtrees are empty. Two exchanges, four comparisons.
Extract-min on the heap [1,3,2,6,4,5,7,8,9,10][1, 3, 2, 6, 4, 5, 7, 8, 9, 10]: the last leaf, 10, replaces the root 1 (left); it is exchanged with its smaller child 2 (middle), then with 5 (right), where both its subtrees are empty. Two exchanges, four comparisons.
Ler no capítulo →