Presentation is loading. Please wait.

Presentation is loading. Please wait.

Binary Trees CS-2851 Dr. Mark L. Hornick.

Similar presentations


Presentation on theme: "Binary Trees CS-2851 Dr. Mark L. Hornick."— Presentation transcript:

1 Binary Trees CS-2851 Dr. Mark L. Hornick

2 Review: Doubly Linked List
Each Entry object includes a link to the Entry object that contains the next element (or null) And a link to the Entry object that contains the previous element (or null) Entry Entry Entry CS-2851 Dr. Mark L. Hornick

3 Binary Tree - concept BinaryTree A Binary Tree structure is either empty or consists of an Entry (or element), called the Root Entry (or element) and two distinct branches a left subtree and right subtree The left and right subtrees may be empty or contain elements a left element and right element Root Left Right CS-2851 Dr. Mark L. Hornick

4 The Binary Tree grows… BinaryTree The left and right subtrees may also contain distinct branches And each of those subtrees may contain elements Root Left Right Right Left LeftLeft Right Right LeftRight CS-2851 Dr. Mark L. Hornick

5 Binary Tree taxonomy BinaryTree A leaf is an element whose left and right subtrees are empty. A node is an element containing at least one subtree CS-2851 Dr. Mark L. Hornick

6 Depth=3 Height=4 CS-2851 Dr. Mark L. Hornick

7 More taxonomy/definitions
A binary tree is a two-tree if all non-leaf elements (nodes) have, at most, two leaves A binary tree is full if it is a two-tree where all nodes have either 0 or 2 children. CS-2851 Dr. Mark L. Hornick

8 More taxonomy/definitions
A binary tree is perfect if it is a two-tree with all leaves at the same depth. A binary tree is complete if it is full to the level (height-1), and all leaves at the height of the tree are to the left CS-2851 Dr. Mark L. Hornick

9 Can we use a Linked-List approach for implementation?
Links at least mimic the graph notation But what about connecting the entries? Does next and previous make sense? Then how? (maybe left and right?) CS-2851 Dr. Mark L. Hornick

10 Q: Is the Binary Tree a List?
A: No, because there is no definitive way to index the collection For example, what is the 6th element of the collection? A List implies indexing, so a Binary Tree is not a List However, we can implement it as a special type of Collection: a Set is a special case of a Collection which has no duplicate elements CS-2851 Dr. Mark L. Hornick

11 There is no BinaryTree class in the JCF library
There are instead other binary-tree-based classes in the Java collections framework TreeSet (a type of Set) TreeMap CS-2851 Dr. Mark L. Hornick


Download ppt "Binary Trees CS-2851 Dr. Mark L. Hornick."

Similar presentations


Ads by Google