B-Tree and Heaps Todays announcements HW3 out, due Nov 15, 23:59 - - PowerPoint PPT Presentation

b tree and heaps
SMART_READER_LITE
LIVE PREVIEW

B-Tree and Heaps Todays announcements HW3 out, due Nov 15, 23:59 - - PowerPoint PPT Presentation

B-Tree and Heaps Todays announcements HW3 out, due Nov 15, 23:59 MT2 Nov 7, 19:00-21:00 WOOD 2 Todays Plan B-Tree wrap Priority queues Warm up: If m = 128, then a B-Tree of height 4 must contain at least 1. 300 items 2.


slide-1
SLIDE 1

B-Tree and Heaps

Today’s announcements

◮ HW3 out, due Nov 15, 23:59 ◮ MT2 Nov 7, 19:00-21:00 WOOD 2

Today’s Plan

◮ B-Tree wrap ◮ Priority queues

Warm up: If m = 128, then a B-Tree of height 4 must contain at least

  • 1. 300 items
  • 2. 3,000 items
  • 3. 30,000 items
  • 4. 300,000 items
  • 5. 3,000,000 items
  • 6. 30,000,000 items

1 / 10

slide-2
SLIDE 2

Thinking about B-Trees

◮ Remove is fast if leaf doesn’t underflow or we can take from a

  • sibling. Merging and propagation take more time.

◮ Insert is fast if leaf doesn’t overflow. (Could we give to a

sibling?) Splitting and propagation take more time.

◮ Propagation is rare if m is large (Why?) ◮ Repeated insertions and deletion can cause thrashing ◮ Range queries (i.e., findBetween(key1, key2)) are fast

because of sibling pointers.

2 / 10

slide-3
SLIDE 3

B-Trees in practice

Multiple B-Trees can index the same data records.

15 20 30 16 10 31 22 11 12 17 25 26 32 33 36 auk yak boa ewe gnu elk fox

  • wl

bee goa kit ant bat emu kea Employee ID Employee Name Name: auk ID: 16 Food: fish Name: yak ID: 22 Food: grass disk

3 / 10

slide-4
SLIDE 4

A Tree by Any Other Name...

◮ B-Trees with m = 3 are called 2-3 trees ◮ B-Trees with m = 4 are called 2-3-4 trees

Why would we ever use these?

4 / 10

slide-5
SLIDE 5

Back to Queues

◮ Applications

◮ ordering CPU jobs ◮ simulating events ◮ picking the next search site

◮ But we don’t want FIFO ...

◮ short jobs should go first ◮ earliest (simulated time) events should go first ◮ most promising sites should be searched first 5 / 10

slide-6
SLIDE 6

Priority Queue ADT

ant 8 bee 2 cat 4 dog 14 emu 6 insert deleteMin

◮ Priority Queue operations

◮ create ◮ destroy ◮ insert ◮ removeMin ◮ is empty

◮ Priority Queue property: For two elements in the queue, x and

y, if x has a lower priority value than y, x will be dequeued before y.

6 / 10

slide-7
SLIDE 7

Applications of the Priority Q

◮ Hold jobs for a printer in order of length ◮ Store packets on network routers in order of urgency ◮ Simulate events ◮ Select symbols for compression ◮ Sort numbers ◮ Anything greedy: an algorithm that makes the “locally best

choice” at each step

7 / 10

slide-8
SLIDE 8

Priority Q Data Structures

◮ Unsorted list

◮ insert time: ◮ removeMin time:

◮ Sorted list

◮ insert time: ◮ removeMin time: 8 / 10

slide-9
SLIDE 9

Binary Heap Priority Q Data Structure

11 14 12 9 13 7 6 4 10 8 5 2

What properties does this structure have?

9 / 10

slide-10
SLIDE 10

Nifty Storage Trick

11 14 12 9 13 7 6 4 10 8 5 2 1 2 3 4 5 6 7 8 9 10 11

Navigation using indices:

◮ left child(i) = ◮ right child(i) = ◮ parent(i) = ◮ root = ◮ next free position =

1 2 3 4 5 6 7 8 9 10 11 12 2 4 5 7 6 10 8 13 9 12 14 11

10 / 10