Trees. Truong Tuan Anh CSE-HCMUT

Similar documents
Binary Trees, Binary Search Trees

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

TREES. Trees - Introduction

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

Todays Lecture. Assignment 2 deadline: You have 5 Calendar days to complete.

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

Binary Trees

Programming II (CS300)

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

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

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

7.1 Introduction. A (free) tree T is A simple graph such that for every pair of vertices v and w there is a unique path from v to w

Chapter 4 Trees. Theorem A graph G has a spanning tree if and only if G is connected.

Binary Trees. College of Computing & Information Technology King Abdulaziz University. CPCS-204 Data Structures I

Trees. CSE 373 Data Structures

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

Chapter 20: Binary Trees

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

March 20/2003 Jayakanth Srinivasan,

Garbage Collection: recycling unused memory

Trees 11/15/16. Chapter 11. Terminology. Terminology. Terminology. Terminology. Terminology

Section 5.5. Left subtree The left subtree of a vertex V on a binary tree is the graph formed by the left child L of V, the descendents

UNIT III TREES. A tree is a non-linear data structure that is used to represents hierarchical relationships between individual data items.

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

Algorithms. Deleting from Red-Black Trees B-Trees

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

Trees. Tree Structure Binary Tree Tree Traversals

Associate Professor Dr. Raed Ibraheem Hamed

Algorithms and Data Structures

Binary Trees. Examples:

Tree. A path is a connected sequence of edges. A tree topology is acyclic there is no loop.

Data Structure Lecture#10: Binary Trees (Chapter 5) U Kang Seoul National University


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

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

a graph is a data structure made up of nodes in graph theory the links are normally called edges

CISC 235 Topic 3. General Trees, Binary Trees, Binary Search Trees

CSI33 Data Structures

Lec 17 April 8. Topics: binary Trees expression trees. (Chapter 5 of text)

CE 221 Data Structures and Algorithms

Successor/Predecessor Rules in Binary Trees

CS24 Week 8 Lecture 1

Trees. Trees. CSE 2011 Winter 2007

Lecture 6: Analysis of Algorithms (CS )

Data Structures and Algorithms for Engineers

Binary Trees. Height 1

Binary Trees Fall 2018 Margaret Reid-Miller

CSE 214 Computer Science II Introduction to Tree

CS350: Data Structures Red-Black Trees

Abstract Data Structures IB Computer Science. Content developed by Dartford Grammar School Computer Science Department

Why Do We Need Trees?

Principles of Computer Science

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

Trees Algorhyme by Radia Perlman

Trees, Binary Trees, and Binary Search Trees

BBM 201 Data structures

Chapter 5. Binary Trees

Binary search trees (BST) Binary search trees (BST)

Binary Tree. Preview. Binary Tree. Binary Tree. Binary Search Tree 10/2/2017. Binary Tree

Terminology. The ADT Binary Tree. The ADT Binary Search Tree

[ DATA STRUCTURES ] Fig. (1) : A Tree

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

CSI33 Data Structures

Data Structures. Trees. By Dr. Mohammad Ali H. Eljinini. M.A. Eljinini, PhD

Data Structure. IBPS SO (IT- Officer) Exam 2017

INF2220: algorithms and data structures Series 1

Advanced Java Concepts Unit 5: Trees. Notes and Exercises

Introduction to Computers and Programming. Concept Question

CSC148 Week 6. Larry Zhang

Binary Search Trees. What is a Binary Search Tree?

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

Friday Four Square! 4:15PM, Outside Gates

Analysis of Algorithms

DATA STRUCTURES AND ALGORITHMS. Hierarchical data structures: AVL tree, Bayer tree, Heap

Chapter 11.!!!!Trees! 2011 Pearson Addison-Wesley. All rights reserved 11 A-1

Chapter 11.!!!!Trees! 2011 Pearson Addison-Wesley. All rights reserved 11 A-1

2-3 Tree. Outline B-TREE. catch(...){ printf( "Assignment::SolveProblem() AAAA!"); } ADD SLIDES ON DISJOINT SETS

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

6-TREE. Tree: Directed Tree: A directed tree is an acyclic digraph which has one node called the root node

Algorithms in Systems Engineering ISE 172. Lecture 16. Dr. Ted Ralphs

Computational Optimization ISE 407. Lecture 16. Dr. Ted Ralphs

Trees. Eric McCreath

CMPT 225. Binary Search Trees

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

CS 206 Introduction to Computer Science II

Section Summary. Introduction to Trees Rooted Trees Trees as Models Properties of Trees

Binary Trees. BSTs. For example: Jargon: Data Structures & Algorithms. root node. level: internal node. edge.

Data Structure - Binary Tree 1 -

Tree Structures. Definitions: o A tree is a connected acyclic graph. o A disconnected acyclic graph is called a forest

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

Trees. Estruturas de Dados / Programação 2 Árvores. Márcio Ribeiro twitter.com/marciomribeiro. Introduc)on. Hierarchical structure

COSC 2011 Section N. Trees: Terminology and Basic Properties

Definitions A A tree is an abstract t data type. Topic 17. "A tree may grow a. its leaves will return to its roots." Properties of Trees

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

THE EULER TOUR TECHNIQUE: EVALUATION OF TREE FUNCTIONS

1 Binary trees. 1 Binary search trees. 1 Traversal. 1 Insertion. 1 An empty structure is an empty tree.

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

Data Structures and Algorithms

Discussion 2C Notes (Week 8, February 25) TA: Brian Choi Section Webpage:

Chapter Summary. Introduction to Trees Applications of Trees Tree Traversal Spanning Trees Minimum Spanning Trees

Transcription:

Trees Truong Tuan Anh CSE-HCMUT

Outline Basic concepts Trees

Trees A tree consists of a finite set of elements, called nodes, and a finite set of directed lines, called branches, that connect the nodes

Degree of Trees Degree of a node: the number of branches associated with the node Indegree branch: directed branch toward the node Outdegree branch: directed branch away from the node

Degree of Trees The first node is called the root indegree of the root = 0 Except the root, the indegree of a node = 1 outdegree of a node = 0 or 1 or more

Trees A root is the first node with an indegree of zero A leaf is any node with an outdegree of zero A internal node is not a root or a leaf A parent has an outdegree greater than zero A child has an indegree of one a internal node is both a parent of a node and a child of another one Siblings are two or more nodes with the same parent For a given node, an ancestor is any node in the path from the root to the node For a given node, an descendent is any node in the paths from the node to a leaf

Trees A path is a sequence of nodes in which each node is adjacent to the next one The level of a node is its distance from the root Siblings are always at the same level The height of a tree is the level of the leaf in the longest path from the root plus 1 A subtree is any connected structure below the root

Trees

Trees

Binary Trees

Binary Trees A binary tree node cannot have more than two subtrees

Binary Trees: Properties

Binary Trees: Properties

Binary Trees: Structure A binary tree is either empty, or it consists of a node called root together with two binary trees called the left and the right subtree of the root

Binary Tree Structure: Linked List Implementation

Binary Trees: Traversals Depth-first traversal (duyệt theo chiều sâu): the processing proceeds along a path from the root through one child to the most distant descendent of that first child before processing a second child, i.e. processes all of the descendents of a child before going on to the next child Breadth-first traversal (duyệt theo chiều rộng): the processing proceeds horizontally from the root to all of its children, then to its children's children, i.e. each level is completely processed before the next level is started.

Depth-first Traversals Preorder traversal Inorder traversal Postorder traversal

Preorder Traversal (NLR) In the preorder traversal, the root is processed first, before the left and right subtrees

Inorder Traversal (NLR) In the inorder traversal, the root is processed between its subtrees

Postorder Traversal (NLR) In the postorder traversal, the root is processed after its subtrees

Breadth-First Traversals In the breadth-first traversal of a binary tree, we process all of the children of a node before proceeding with the next level

Binary Search Trees

Binary Search Trees A binary search tree is a binary tree with the following properties: 1. All items in the left subtree are less than the root 2. All items in the right subtree are greater than or equal to the root 3. Each subtree is itself a binary search tree

Valid Binary Search Trees

Invalid Binary Search Trees

Binary Search Trees (BST) BST is one of implementations for ordered list In BST we can search quickly (as with binary search on a contiguous list) In BST we can make insertions and deletions quickly (as with a linked list)

Binary Search Trees: Traversals

Operations

Insert a Node into BST All BST insertions take place at a leaf or a leaflike node (a node that has only one null branch)

Delete a Node from BST Deletion of a leaf: Set the deleted node's parent link to NULL

Delete a Node from BST Deletion of a node having only right subtree or left subtree: Attach the subtree to the deleted node's parent

Delete a Node from BST Deletion of a node having both subtrees: Replace the deleted node by its predecessor or by its successor, recycle this node instead

Delete a Node from BST

Delete a Node from BST

Takeaways Basic concepts Trees