4A-Trees1 - 4 Trees Part 1 Data Structures and Algorithms...

Info icon This preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
1/34 Data Structures and Algorithms in Java 4. Trees Part 1
Image of page 1

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

View Full Document Right Arrow Icon
2/34 Data Structures and Algorithms in Java 2 What is a Trees? Tree Terminology Tree examples Ordered Trees Tree Traversals Binary Trees Implementing Binary Trees Binary Search Tree Insertion Deletion Objectives
Image of page 2
3/34 Data Structures and Algorithms in Java What is a Tree? In computer science, a tree is an abstract model of a hierarchical structure A tree consists of nodes with a parent-child relation Inspiration: family trees Applications: Organization charts File systems Programming environments Every node except one (a root) has a unique parent. Computers”R”Us Sales R&D Manufacturing Laptops Desktops US International Europe Asia Canada Empty structure is an empty tree. Non-empty tree consists of a root and its children, where these children are also trees. Exact definition Trees, Binary Trees, and Binary Search Trees
Image of page 3

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

View Full Document Right Arrow Icon
4/34 Data Structures and Algorithms in Java Tree Terminology - 1 Root : unique node without a parent Internal node : node with at least one child (A, B, C, F) External (leaf) node : node without children (E, I, J, K, G, H, D) Ancestors of a node: parent, grandparent, great-grandparent, … Descendants of a node: child, grandchild, great-grandchild, etc. Level of a node: The level of the root is 1 . If a father has level i then its children has level i+1. sub-tree A B D C G H E F I J K Sub-tree : tree consisting of a node and its descendants (The level is known with other name: depth. In some documents a level of the root is defined as 0) Height of a tree : maximum level in a tree, thus a single node is a tree of height 1 . The height of an empty tree is 0. Height of a node p is the height of the sub-tree with root p. We can see that the height of a tree is the maximum number of nodes on a path from the root to a leaf node. In text book and some other documents the height of a tree with single node is defined as 0
Image of page 4
5/34 Data Structures and Algorithms in Java Tree Terminology - 2 Degree (order) of a node: number of its non-empty childrens. Each node has to be reachable from the root through a unique sequence of arcs (edges), called a path The number of arcs in a path is called the length of the path Tree example: Hierarchical structure of a university shown as a tree
Image of page 5

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

View Full Document Right Arrow Icon
6/34 Image Source: JEDI Tree examples
Image of page 6
7/34 Ordered Trees A tree is ordered if there is a meaningful linear order among the children of each node; that is, we purposefully identify the children of a node as being the first, second, third, and so on. Such an order is usually visualized by arranging siblings left to right, according to their order.
Image of page 7

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

View Full Document Right Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern