SlideShare a Scribd company logo
Computer Science 2
Data Structures and Algorithms
V22.0102 section 2
Introduction to Trees
Professor: Evan Korth
New York University
Road Map
• Introduction to trees
– Terminology
• Binary trees
• Tree traversal
• Reading: 4.1 – 4.2
Tree
• Tree defined recursively
• A tree is a collection of nodes. The collection can
be empty; otherwise, a tree consists of a
distinguished node r, called the root, and zero or
more non-empty (sub) trees T1, T2, …, Tk each of
whose roots are connected by a directed edge from
r.
• A tree is a collection of N nodes, one of which is
the root and N-1 edges.
Source:Mark Allen Weiss
Tree terminology
• The root of each subtree is said to be a
child of r and r is said to be the parent of
each subtree root.
• Leaves: nodes with no children (also
known as external nodes)
• Internal Nodes: nodes with children
• Siblings: nodes with the same parent
Source:Mark Allen Weiss - edited by Evan Korth
Tree terminology (continued)
• A path from node n1 to nk is defined as a sequence
of nodes n1, n2, …, nksuch that ni is the parent of ni+1
for 1<= i <= k.
• The length of this path is the number of edges on
the path namely k-1.
• The length of the path from a node to itself is 0.
• There is exactly one path from from the root to
each node.
Source:Mark Allen Weiss
Tree terminology (continued)
• Depth (of node): the length of the unique
path from the root to a node.
• Depth (of tree): The depth of a tree is equal
to the depth of its deepest leaf.
• Height (of node): the length of the longest
path from a node to a leaf.
– All leaves have a height of 0
– The height of the root is equal to the depth of
the tree
Source:Mark Allen Weiss
Tree terminology (continued)
• Depth (of node): the length of the unique
path from the root to a node.
• Depth (of tree): The depth of a tree is equal
to the depth of its deepest leaf.
• Height (of node): the length of the longest
path from a node to a leaf.
– All leaves have a height of 0
– The height of the root is equal to the depth of
the tree
Source:Mark Allen Weiss

More Related Content

PPT
tree in Data Structures
PPTX
Introduction to tree ds
PPTX
Terminology of tree
PPT
Basic of trees 2
PPT
17. Trees and Graphs
PPTX
week-Lec 10Trees.pptx for dsa students in detail
PPTX
Introduction to Tree .pptx
PPTX
TreesTreesTreesTreesTreesTreesTrees.pptx
tree in Data Structures
Introduction to tree ds
Terminology of tree
Basic of trees 2
17. Trees and Graphs
week-Lec 10Trees.pptx for dsa students in detail
Introduction to Tree .pptx
TreesTreesTreesTreesTreesTreesTrees.pptx

Similar to Tree basics (20)

PPTX
PPTX
Tree Data Structure Tree Data Structure Details
PPTX
lecture_13 tree in mmmmmmmm mmmmmfftro.pptx
PPTX
Data structure using c module 2
PPTX
PPTX
Notes on trees Introduction and graphs.pptx
PPTX
PPTX
Binary Trees - Tree Terminologies and representation
PDF
PPTX
Discrete Mathematics Tree
PPTX
TERMINOLOGIES OF TREE, TYPES OF TREE.pptx
PPTX
Data Structures Module 3 Binary Trees Binary Search Trees Tree Traversals AVL...
PPTX
CHAPTER 5 TREE Student.pptxlllllllllllllllllllllllllll
PDF
Graph Theory: Trees
DOC
23 Tree Best Part
PPTX
Basic Terminologies of Tree and Tree Traversal methods.pptx
PPT
Tree-introduction ,Definition, Types of BT
Tree Data Structure Tree Data Structure Details
lecture_13 tree in mmmmmmmm mmmmmfftro.pptx
Data structure using c module 2
Notes on trees Introduction and graphs.pptx
Binary Trees - Tree Terminologies and representation
Discrete Mathematics Tree
TERMINOLOGIES OF TREE, TYPES OF TREE.pptx
Data Structures Module 3 Binary Trees Binary Search Trees Tree Traversals AVL...
CHAPTER 5 TREE Student.pptxlllllllllllllllllllllllllll
Graph Theory: Trees
23 Tree Best Part
Basic Terminologies of Tree and Tree Traversal methods.pptx
Tree-introduction ,Definition, Types of BT
Ad

More from Rajendran (20)

PPT
Element distinctness lower bounds
PPT
Scheduling with Startup and Holding Costs
PPT
Divide and conquer surfing lower bounds
PPT
Red black tree
PPT
Hash table
PPT
Medians and order statistics
PPT
Proof master theorem
PPT
Recursion tree method
PPT
Recurrence theorem
PPT
Master method
PPT
Master method theorem
PPT
Hash tables
PPT
Lower bound
PPT
Master method theorem
PPT
Greedy algorithms
PPT
Longest common subsequences in Algorithm Analysis
PPT
Dynamic programming in Algorithm Analysis
PPT
Average case Analysis of Quicksort
PPT
Np completeness
PPT
computer languages
Element distinctness lower bounds
Scheduling with Startup and Holding Costs
Divide and conquer surfing lower bounds
Red black tree
Hash table
Medians and order statistics
Proof master theorem
Recursion tree method
Recurrence theorem
Master method
Master method theorem
Hash tables
Lower bound
Master method theorem
Greedy algorithms
Longest common subsequences in Algorithm Analysis
Dynamic programming in Algorithm Analysis
Average case Analysis of Quicksort
Np completeness
computer languages
Ad

Recently uploaded (20)

PDF
RMMM.pdf make it easy to upload and study
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Trump Administration's workforce development strategy
PPTX
Lesson notes of climatology university.
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
PDF
Weekly quiz Compilation Jan -July 25.pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PDF
A systematic review of self-coping strategies used by university students to ...
PPTX
Unit 4 Skeletal System.ppt.pptxopresentatiom
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PDF
1_English_Language_Set_2.pdf probationary
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
Classroom Observation Tools for Teachers
PPTX
Introduction to Building Materials
PDF
Complications of Minimal Access Surgery at WLH
RMMM.pdf make it easy to upload and study
Supply Chain Operations Speaking Notes -ICLT Program
Final Presentation General Medicine 03-08-2024.pptx
Trump Administration's workforce development strategy
Lesson notes of climatology university.
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
Weekly quiz Compilation Jan -July 25.pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
A systematic review of self-coping strategies used by university students to ...
Unit 4 Skeletal System.ppt.pptxopresentatiom
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
1_English_Language_Set_2.pdf probationary
Paper A Mock Exam 9_ Attempt review.pdf.
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Chinmaya Tiranga quiz Grand Finale.pdf
Classroom Observation Tools for Teachers
Introduction to Building Materials
Complications of Minimal Access Surgery at WLH

Tree basics

  • 1. Computer Science 2 Data Structures and Algorithms V22.0102 section 2 Introduction to Trees Professor: Evan Korth New York University
  • 2. Road Map • Introduction to trees – Terminology • Binary trees • Tree traversal • Reading: 4.1 – 4.2
  • 3. Tree • Tree defined recursively • A tree is a collection of nodes. The collection can be empty; otherwise, a tree consists of a distinguished node r, called the root, and zero or more non-empty (sub) trees T1, T2, …, Tk each of whose roots are connected by a directed edge from r. • A tree is a collection of N nodes, one of which is the root and N-1 edges. Source:Mark Allen Weiss
  • 4. Tree terminology • The root of each subtree is said to be a child of r and r is said to be the parent of each subtree root. • Leaves: nodes with no children (also known as external nodes) • Internal Nodes: nodes with children • Siblings: nodes with the same parent Source:Mark Allen Weiss - edited by Evan Korth
  • 5. Tree terminology (continued) • A path from node n1 to nk is defined as a sequence of nodes n1, n2, …, nksuch that ni is the parent of ni+1 for 1<= i <= k. • The length of this path is the number of edges on the path namely k-1. • The length of the path from a node to itself is 0. • There is exactly one path from from the root to each node. Source:Mark Allen Weiss
  • 6. Tree terminology (continued) • Depth (of node): the length of the unique path from the root to a node. • Depth (of tree): The depth of a tree is equal to the depth of its deepest leaf. • Height (of node): the length of the longest path from a node to a leaf. – All leaves have a height of 0 – The height of the root is equal to the depth of the tree Source:Mark Allen Weiss
  • 7. Tree terminology (continued) • Depth (of node): the length of the unique path from the root to a node. • Depth (of tree): The depth of a tree is equal to the depth of its deepest leaf. • Height (of node): the length of the longest path from a node to a leaf. – All leaves have a height of 0 – The height of the root is equal to the depth of the tree Source:Mark Allen Weiss