CSE 214 Computer Science II Introduction to Tree

Similar documents
CSE 230 Intermediate Programming in C and C++ Binary Tree

Trees : Part 1. Section 4.1. Theory and Terminology. A Tree? A Tree? Theory and Terminology. Theory and Terminology

Binary Trees

CSE 214 Computer Science II Heaps and Priority Queues

Programming II (CS300)

Trees. CSE 373 Data Structures

Trees (Part 1, Theoretical) CSE 2320 Algorithms and Data Structures University of Texas at Arlington

Data Structures and Algorithms

TREES. Trees - Introduction

Lecture 32. No computer use today. Reminders: Homework 11 is due today. Project 6 is due next Friday. Questions?

Trees. Q: Why study trees? A: Many advance ADTs are implemented using tree-based data structures.

1. Why Study Trees? Trees and Graphs. 2. Binary Trees. CITS2200 Data Structures and Algorithms. Wood... Topic 10. Trees are ubiquitous. Examples...

Trees. Truong Tuan Anh CSE-HCMUT

(2,4) Trees. 2/22/2006 (2,4) Trees 1

Uses for Trees About Trees Binary Trees. Trees. Seth Long. January 31, 2010

Why Do We Need Trees?

11 TREES DATA STRUCTURES AND ALGORITHMS IMPLEMENTATION & APPLICATIONS IMRAN IHSAN ASSISTANT PROFESSOR, AIR UNIVERSITY, ISLAMABAD

An undirected graph is a tree if and only of there is a unique simple path between any 2 of its vertices.

Tree Structures. A hierarchical data structure whose point of entry is the root node

Multi-way Search Trees. (Multi-way Search Trees) Data Structures and Programming Spring / 25

Data Structures and Algorithms

Trees. (Trees) Data Structures and Programming Spring / 28

CS 231 Data Structures and Algorithms Fall Recursion and Binary Trees Lecture 21 October 24, Prof. Zadia Codabux

Trees. Eric McCreath

(2,4) Trees Goodrich, Tamassia (2,4) Trees 1

12/5/17. trees. CS 220: Discrete Structures and their Applications. Trees Chapter 11 in zybooks. rooted trees. rooted trees

Binary Trees, Binary Search Trees

ITI Introduction to Computing II

Trees! Ellen Walker! CPSC 201 Data Structures! Hiram College!

Trees. Trees. CSE 2011 Winter 2007

CSC148 Week 6. Larry Zhang

ITI Introduction to Computing II

CE 221 Data Structures and Algorithms

CS 151. Binary Trees. Friday, October 5, 12

CS F-11 B-Trees 1

Module 4: Index Structures Lecture 13: Index structure. The Lecture Contains: Index structure. Binary search tree (BST) B-tree. B+-tree.

Trees. Carlos Moreno uwaterloo.ca EIT

Trees and Tree Traversal

CS24 Week 8 Lecture 1

Programming II (CS300)

CSCI-401 Examlet #5. Name: Class: Date: True/False Indicate whether the sentence or statement is true or false.

Chapter 10: Trees. A tree is a connected simple undirected graph with no simple circuits.

Trees. Introduction & Terminology. February 05, 2018 Cinda Heeren / Geoffrey Tien 1

Bioinformatics Programming. EE, NCKU Tien-Hao Chang (Darby Chang)

CS301 - Data Structures Glossary By

Algorithms. Deleting from Red-Black Trees B-Trees

Topic 18 Binary Trees "A tree may grow a thousand feet tall, but its leaves will return to its roots." -Chinese Proverb


CSE 230 Intermediate Programming in C and C++ Recursion

CS 206 Introduction to Computer Science II

Self-Balancing Search Trees. Chapter 11

Garbage Collection: recycling unused memory

BST Implementation. Data Structures. Lecture 4 Binary search trees (BST) Dr. Mahmoud Attia Sakr University of Ain Shams

Design and Analysis of Algorithms Lecture- 9: B- Trees

2-3 and Trees. COL 106 Shweta Agrawal, Amit Kumar, Dr. Ilyas Cicekli

Algorithms and Data Structures (INF1) Lecture 8/15 Hua Lu

TREES cs2420 Introduction to Algorithms and Data Structures Spring 2015

CS 171: Introduction to Computer Science II. Binary Search Trees

CSE 530A. B+ Trees. Washington University Fall 2013

BBM 201 Data structures

Topic 14. The BinaryTree ADT

Organizing Spatial Data

EE 368. Weeks 5 (Notes)

Algorithms and Data Structures

The tree data structure. Trees COL 106. Amit Kumar Shweta Agrawal. Acknowledgement :Many slides are courtesy Douglas Harder, UWaterloo

V Advanced Data Structures

CSC148H Week 8. Sadia Sharmin. July 12, /29

CMPT 225. Binary Search Trees

LECTURE 11 TREE TRAVERSALS

TREES Lecture 10 CS2110 Spring2014

CSE 143 Lecture 19. Binary Trees. read slides created by Marty Stepp

CSE 230 Computer Science II (Data Structure) Introduction

Trees. Tree Structure Binary Tree Tree Traversals

We will show that the height of a RB tree on n vertices is approximately 2*log n. In class I presented a simple structural proof of this claim:

Computer Science 210 Data Structures Siena College Fall Topic Notes: Trees

Principles of Computer Science

V Advanced Data Structures

CS61BL. Lecture 3: Asymptotic Analysis Trees & Tree Traversals Stacks and Queues Binary Search Trees (and other trees)

CSI33 Data Structures

Analysis of Algorithms

B-Trees and External Memory

CS 106X Lecture 18: Trees

Trees. See Chapter 18 of Weiss

CSE 230 Intermediate Programming in C and C++ Functions

Tree: non-recursive definition. Trees, Binary Search Trees, and Heaps. Tree: recursive definition. Tree: example.

B-Trees and External Memory

Building Java Programs

B-Trees. CS321 Spring 2014 Steve Cutchin

Algorithms. AVL Tree

Linked Structures Songs, Games, Movies Part III. Fall 2013 Carola Wenk

A set of nodes (or vertices) with a single starting point

birds fly S NP N VP V Graphs and trees

Binary Trees Fall 2018 Margaret Reid-Miller

CSCI2100B Data Structures Trees

Algorithms and Data Structures CS-CO-412

Motivation for B-Trees

Objectives. In this session, you will learn to:

Lecture Notes 16 - Trees CSS 501 Data Structures and Object-Oriented Programming Professor Clark F. Olson

Data Structure - Binary Tree 1 -

singly and doubly linked lists, one- and two-ended arrays, and circular arrays.

Transcription:

CSE 214 Computer Science II Introduction to Tree Fall 2017 Stony Brook University Instructor: Shebuti Rayana shebuti.rayana@stonybrook.edu http://www3.cs.stonybrook.edu/~cse214/sec02/

Tree Tree is a non-linear data structure which is a collection of data (Node) organized in hierarchical structure. In tree data structure, every individual element is called as Node. Node stores the actual data of that particular element and link to next element in hierarchical structure. Tree with 11 nodes and 10 edges Shebuti Rayana (CS, Stony Brook University) 2

Root In a tree data structure, the first node is called as Root Node. Every tree must have root node. In any tree, there must be only one root node. Root node does not have any parent. (same as head in a LinkedList). Here, A is the Root node Shebuti Rayana (CS, Stony Brook University) 3

Edge The connecting link between any two nodes is called an Edge. In a tree with 'N' number of nodes there will be a maximum of 'N-1' number of edges. Edge is the connecting link between the two nodes Shebuti Rayana (CS, Stony Brook University) 4

Parent The node which is predecessor of any node is called as Parent Node. The node which has branch from it to any other node is called as parent node. Parent node can also be defined as "The node which has child / children". Here, A is Parent of B and C B is Parent of D, E and F C is the Parent of G and H Shebuti Rayana (CS, Stony Brook University) 5

Child The node which is descendant of any node is called as CHILD Node. In a tree, any parent node can have any number of child nodes. In a tree, all the nodes except root are child nodes. Here, B and C are Children of A G and H are Children of C K is a Child of G Shebuti Rayana (CS, Stony Brook University) 6

Siblings In a tree data structure, nodes which belong to same Parent are called as Siblings. In simple words, the nodes with same parent are called as Sibling nodes. Here, B and C are siblings D, E and F are siblings G and H are siblings Shebuti Rayana (CS, Stony Brook University) 7

Leaf The node which does not have a child is called as Leaf Node. leaf node is also called as 'Terminal' node. Here, D, I, J, F. K and H are leaf nodes Shebuti Rayana (CS, Stony Brook University) 8

Internal Nodes In a tree data structure, the node which has at least one child is called as Internal Node. Here, A, B, E, C, G are Internal Nodes Shebuti Rayana (CS, Stony Brook University) 9

Degree the total number of children of a node is called as Degree of that Node. The highest degree of a node among all the nodes in a tree is called as 'Degree of Tree' Here, Degree of A is 2 Degree of B is 3 Degree of F is 0 Shebuti Rayana (CS, Stony Brook University) 10

Level In a tree data structure, the root node is said to be at Level 0 and the children of root node are at Level 1 and the children of the nodes which are at Level 1 will be at Level 2 and so on. In simple words, in a tree each step from top to bottom is called as a Level and the Level count starts with '0' and incremented by one at each level (Step). Shebuti Rayana (CS, Stony Brook University) 11

Height the total number of edges from leaf node to a particular node in the longest path is called the Height of that Node. In a tree, height of the root node is said to be height of the tree. In a tree, height of all leaf nodes is '0'. Here, Height of the tree is 3 Shebuti Rayana (CS, Stony Brook University) 12

Depth The total number of edges from root node to a particular node is called as Depth of that Node. In a tree, the total number of edges from root node to a leaf node in the longest path is said to be Depth of the tree. Here, Depth of the tree is 3 Shebuti Rayana (CS, Stony Brook University) 13

Path The sequence of Nodes and Edges from one node to another node is called a Path between that two Nodes. Length of a Path is total number of nodes in that path. In below example the path A - B - E - J has length 4. Here, Path between A and J: A-B-E-J Path between C and K: C-G-K Shebuti Rayana (CS, Stony Brook University) 14

Sub-tree Each child from a node forms a subtree recursively. Every child node will form a subtree on its parent node. Shebuti Rayana (CS, Stony Brook University) 15

Tree Definition With the basic vocabulary now defined, we can move on to a formal definition of a tree. Two definitions of a tree. One definition involves nodes and edges. The second definition, which will prove to be very useful, is a recursive definition. Shebuti Rayana (CS, Stony Brook University) 16

Tree Definition Definition One: A tree consists of a set of nodes and a set of edges that connect pairs of nodes. A tree has the following properties: One node of the tree is designated as the root node. Every node n, except the root node, is connected by an edge from exactly one other node p, where p is the parent of n. A unique path traverses from the root to each node. If each node in the tree has a maximum of two children, we say that the tree is a binary tree. Shebuti Rayana (CS, Stony Brook University) 17

Tree Definition Definition Two: A tree is either empty or consists of a root and zero or more subtrees, each of which is also a tree. The root of each subtree is connected to the root of the parent tree by an edge. Shebuti Rayana (CS, Stony Brook University) 18

Advantages of Trees Trees are so useful and frequently used, because they have some advantages: Trees reflect structural relationships in the data Trees are used to represent hierarchies Trees provide an efficient insertion and searching Trees are very flexible data structure, allowing to move subtrees around with minimum effort Shebuti Rayana (CS, Stony Brook University) 19

Examples of Tree An example of the biological classification of some animals. From this simple example, we can learn about several properties of trees. The first property this example demonstrates is that trees are hierarchical. By hierarchical, we mean that trees are structured in layers with the more general things near the top and the more specific things near the bottom. The top of the hierarchy is the Kingdom, the next layer of the tree (the children of the layer above) is the Phylum, then the Class, and so on. However, no matter how deep we go in the classification tree, all the organisms are still animals. Shebuti Rayana (CS, Stony Brook University) 20

Examples of Tree Another example of a tree structure that you probably use every day is a file system. In a file system, directories, or folders, are structured as a tree. Following figure illustrates a small part of a Unix file system hierarchy. Shebuti Rayana (CS, Stony Brook University) 21

Examples of Tree The HTML source code and the tree accompanying the source illustrate another hierarchy. Notice that each level of the tree corresponds to a level of nesting inside the HTML tags. The first tag in the source is<html> and the last is </html> All the rest of the tags in the page are inside the pair. If you check, you will see that this nesting property is true at all levels of the tree. Shebuti Rayana (CS, Stony Brook University) 22

Some More Examples genealogical trees organizational trees biological hierarchy trees evolutionary trees population trees book classification trees decision trees graph spanning trees search trees compression trees program dependency trees expression/syntax trees Shebuti Rayana (CS, Stony Brook University) 23

Binary Tree Binary tree is a special type of tree data structure in which every node can have a maximum of 2 children. One is known as left child and the other is known as right child. In a binary tree, every node can have either 0 children or 1 child or 2 children but not more than 2 children. Shebuti Rayana (CS, Stony Brook University) 24

Types of Binary Tree A full binary tree is a binary tree in which each node has exactly zero or two children. A complete binary tree is a binary tree, which is completely filled, with the possible exception of the bottom level, which is filled from left to right. Full Tree Complete Tree Shebuti Rayana (CS, Stony Brook University) 25