LectureHeapInClass

LectureHeapInClass - Binary Tree stored as an array In this...

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

View Full Document Right Arrow Icon
Binary Tree stored as an array In this course, I've said that you can choose between array and linked implementations for the data structures. You may have thought that was true only for the structures based on a linked list. It is actually true for all structures. A binary tree can also be stored as a linked list, and it has a similar set of tradeoffs as the linked list. Array - root is in index 0. Root's children are at index 1 and 2. 1's children What we need to do to make this efficient is figure out the pattern rightchild(x) = ?? f(x) leftchild(x) = ??? parent(x) = ???? Then we can navigate the same way. Let's look at the trade-offs. Accessing items - faster through the array or linked structure? At the top of the tree, it is faster, since those items are next to each other in memory. Memory performance is very tied to locations. What about inserting / deleting items? The classic problem with arrays was that it took a long time to do this because you had to move everything around. Is that
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

LectureHeapInClass - Binary Tree stored as an array In this...

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