Professional Documents
Culture Documents
Ds Tree Dem PVP
Ds Tree Dem PVP
Trees
• We have the following dilemma with respect to representing ordered
lists of items
– The array
• offers efficient search – O(log n)
• but requires shifting elements when inserting and deleting
resulting in O(n)
• limits storage space available without an expensive array
doubling operation, or wastes storage space as we might request
an array larger in size than needed
– The linked list
• offers easy insert/delete – O(1)
• and utilizes the exact amount of storage space needed
• but we must use sequential search to find an item for
search/insert/delete, so ultimately has an O(n)
search/insert/delete
– The tree data structure offers the best of both – efficient
insert/delete, utilizes the exact amount of memory needed, and may
provide log n search
– The drawback?
• tree implementations can be very complicated especially if we
want to guarantee log n search
• here we introduce the tree and specifically a binary tree
Binary Trees
8.1 Trees, Binary Trees, and Binary Search Trees
How to transform
a list into a tree?
Trees