Download presentation
Presentation is loading. Please wait.
Published byDwight Wiggins Modified over 8 years ago
1
CSC 213 – Large Scale Programming
2
Trees Represent hierarchical relationships Parent-child basis of this abstract data type Real-world example: directories & types csc213/ homeworks/ ideas.todo 1M programs/ LLQueue.java 10K DLNode.java 25K hard.txt 3K impossible.txt 2K Tree.java 20K
3
Trees Represent hierarchical relationships Parent-child basis of this abstract data type Real-world example: organization classification Mammal Cat Ape LionHumanChimpanzee ProfessorsYankees Fan
4
Tree Terms Defined by relationships Talk about parents, siblings, descendant Tree rooted at node A “Top” or “Start” of tree B, C, D are children of A A is parent of B, C, D B, C, D are siblings A BDC G H E F I J K
5
Tree Relationships Nodes either leaf or interior Both or neither not options A, B, C, F are parents At least 1 child for each Also called “interior nodes” "Leaves" name of others Leaf node has no children A BDC G H E F I J K
6
Trees Recursion Trees are recursive structure Subtree defined by a node C is root of this subtree E root of this subtree Trees are like professors Some are tall & thin Short & boring a possibility Others can be empty A BDC G H E F I J K
7
Trees vs. Binary Trees Both represent parent-child relationships Both consist of single "root" node & its descendants Nodes can have at most one parent Root nodes are orphans -- do not have a parent All others, the non-root nodes must have parent Children not required for any node in the tree Nodes can have any number of children in tree 2 children for node in binary tree is the maximum
8
Binary Tree Extends tree & adds following property 2 or fewer children per node Child on left called “left child” “Right child” name for other child node For a level i in a binary tree That level can have 2 i nodes At most 2 (i+1) -1 nodes for tree to that level
9
Independent of Implementation A B Z F I Q M
10
For Next Lecture Weekly assignment posted online Due next Tuesday at 5PM Ask me questions, if you have trouble on a problem Textbook reading on traversals How do we create a book’s table of contents? Could we compute the space used by a directory? How would we print out an arithmetic expression?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.