Lec15HeapsInClass

Lec15HeapsInClass - My unsubstantiated claim: Two ways data...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
My unsubstantiated claim: Two ways data structures can be implemented in this class: linked structures and arrays Binary Tree: Linked structure Binary Trees with arrays Root node : index 0 Root node’s children in indeces 1 and 2 What should go in indeces 3 and 4? 1’s children Who should go in indeces 5 and 6? 2’s children Function called leftchild leftchild(x) = y x leftchild rightchild 0 1 2 1 3 4 2 5 6 3 7 8 4 9 10 leftchild(x) = 2x+1 rightchild(x) = 2x + 2 parent(x) = |_ (x-1) / 2 _| Arrays vs linked structures – tradeoffs Access items – the same number of accesses Add items – the same number of accesses – but if we run out of room, we have to allocate and copy everything over Remove items – array is worse unless you are deleting a leaf because you have to move the entire subtree. Arrays can have a lot of unused memory -> wasted memory We are now done with Binary Search Trees. Let’s move on. Priority Queues
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/27/2011 for the course CMPSC 24 taught by Professor Agrawal during the Fall '09 term at UCSB.

Page1 / 2

Lec15HeapsInClass - My unsubstantiated claim: Two ways data...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online