Todos los libros

Profesional

Apps Acerca de Coach Iniciar sesión Empezar a leer

Computer Science · Glosario

¿Qué es Sift up, sift down, heapify?

También llamado: 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.
Leer en el capítulo →