Graph and tree
Graph and tree
 A graph is a representative a set of objects where some pairs of
objects are connected links.
 The interconnected objects are called vertex or nodes And that
links are called edges lines.
0 1
4 3
2
Graph and tree
 0 1 2 3 4
 0 0 1 0 0 1
 1 1 0 1 1 1
 2 0 1 0 1 0
 3 0 1 1 0 1
0
2
1
34
0
2
1
34
0
1
3
2
4
1 4
0 2
1 3
3 4
1 2
0 1
4
3
Graph and tree
subtree
 Root: node without parent (A)
 Siblings: nodes share the same parent
 Internal node: node with at least one child (A, B, C, F)
 External node (leaf ): node without children (E, I, J, K, G, H, D)
 Ancestors of a node: parent, grandparent, grand-grandparent, etc.
 Descendant of a node: child, grandchild, grand-grandchild, etc.
 Depth of a node: number of ancestors
 Height of a tree: maximum depth of any node (3)
 Degree of a node: the number of its children
 Degree of a tree: the maximum number of its node.
A
B DC
G HE F
I J K
Subtree: tree consisting of a
node and its descendants
 Three main methods:
 Preorder
 Postorder
 Inorder
 Preorder:
 visit the root
 traverse in preorder the children (subtrees)
 Postorder
 traverse in postorder the children (subtrees)
 visit the root
 A traversal visits the nodes of a tree in a systematic manner
 In a preorder traversal, a node is visited before its descendants
 Application: print a structured document
Become Rich
1. Motivations 3. Success Stories2. Methods
2.1 Get a
CS PhD
2.2 Start a
Web Site
1.1 Enjoy
Life
1.2 Help
Poor Friends
2.3 Acquired
by Google
1
2
3
5
4 6 7 8
9
 In a postorder traversal, a node is visited after its descendants
 Application: compute space used by files in a directory and its
subdirectories
cs16/
homeworks/
todo.txt
1K
programs/
DDR.java
10K
Stocks.java
25K
h1c.doc
3K
h1nc.doc
2K
Robot.java
20K
9
3
1
7
2 4 5 6
8
 A binary tree is a tree with the following properties:
 Each internal node has at most two children (degree of two)
 The children of a node are an ordered pair
 We call the children of an internal node left child and right child
 Alternative recursive definition: a binary tree is either
 a tree consisting of a single node, OR
 a tree whose root has an ordered pair of children,
each of which is a binary tree
Applications:
arithmetic expressions
decision processes
searching
A
B C
F GD E
H I
Examples of the Binary Tree
A
B C
GE
I
D
H
F
Complete Binary Tree
1
2
3
4
A
B
A
B
Skewed Binary Tree
E
C
D
5
Binary search tree : binary search tree a
particular type of containers: data
structures that store items in memory.
HEAP TREE:A binary heap is a complete
binary tree which satisfies
the heap ordering property.
Graph and tree
Graph and tree
Graph and tree
Graph and tree

More Related Content

PPTX
PPTX
Trees in data structures
PPT
Tree-In Data Structure
PPTX
PPTX
Tree in data structure
PPTX
non linear data structure -introduction of tree
PPTX
Data structure tree - intermediate
PPTX
Working with Files
Trees in data structures
Tree-In Data Structure
Tree in data structure
non linear data structure -introduction of tree
Data structure tree - intermediate
Working with Files

Similar to Graph and tree (20)

PPTX
tree Data Structures in python Traversals.pptx
PPTX
Why Tree is considered a non-linear data structure?
PPTX
trees in data structure
PPTX
Data structure using c module 2
PPTX
binary tree.pptx
PPT
Tree and Binary Search tree
PPTX
PPTX
TreesTreesTreesTreesTreesTreesTrees.pptx
PPT
Binary tree traversal ppt - 02.03.2020
PPT
Binary trees
PPT
Lecture 5 trees
PPTX
Unit 6 tree
PPTX
Data Structures using Python(generic elective).pptx
PPTX
Tree Data Structure Tree Data Structure Details
PPT
PPTX
Tree.pptx
PPTX
TREES34.pptx
PPTX
UNIT III Non Linear Data Structures - Trees.pptx
PPT
Lecture 5 tree.pptx
tree Data Structures in python Traversals.pptx
Why Tree is considered a non-linear data structure?
trees in data structure
Data structure using c module 2
binary tree.pptx
Tree and Binary Search tree
TreesTreesTreesTreesTreesTreesTrees.pptx
Binary tree traversal ppt - 02.03.2020
Binary trees
Lecture 5 trees
Unit 6 tree
Data Structures using Python(generic elective).pptx
Tree Data Structure Tree Data Structure Details
Tree.pptx
TREES34.pptx
UNIT III Non Linear Data Structures - Trees.pptx
Lecture 5 tree.pptx
Ad

More from Imran Hossain (20)

PDF
Artificial Intelligence (AI): Impact, Costs, and Future Prospects.
PDF
COMPUTER
PDF
The Power of Energy- A Journey Through Electricity
PDF
Mental Health Awareness in a Fast-Paced World
PDF
Artificial Intelligence and Its Role in Everyday Life.
PDF
SSD (Solid State Drive)
PDF
Smartphone, Mobile phone, Digital phone, Mobile, Handset
PPTX
Bangabandhu Sheikh Mujibur Rahman Tunnel
PDF
Rooppur Nuclear Power Plant, Pabna, Bangladesh
PPTX
Secondary storage
PPTX
Region based segmentation
PPTX
Thin film electroluminescent display
PPTX
CRT (Cathode ray tube)
PPTX
Color model
PPTX
Computer graphics
PPTX
DDA (digital differential analyzer)
PPTX
Led (light emitting diode )
PPTX
Virtual Blood Bank
PPTX
Compiler vs interpreter
PPTX
Monopoly and monopolistic
Artificial Intelligence (AI): Impact, Costs, and Future Prospects.
COMPUTER
The Power of Energy- A Journey Through Electricity
Mental Health Awareness in a Fast-Paced World
Artificial Intelligence and Its Role in Everyday Life.
SSD (Solid State Drive)
Smartphone, Mobile phone, Digital phone, Mobile, Handset
Bangabandhu Sheikh Mujibur Rahman Tunnel
Rooppur Nuclear Power Plant, Pabna, Bangladesh
Secondary storage
Region based segmentation
Thin film electroluminescent display
CRT (Cathode ray tube)
Color model
Computer graphics
DDA (digital differential analyzer)
Led (light emitting diode )
Virtual Blood Bank
Compiler vs interpreter
Monopoly and monopolistic
Ad

Recently uploaded (20)

PDF
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
PDF
Hazard Identification & Risk Assessment .pdf
PDF
advance database management system book.pdf
PDF
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
PPTX
Virtual and Augmented Reality in Current Scenario
PDF
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
PDF
Empowerment Technology for Senior High School Guide
PDF
Skin Care and Cosmetic Ingredients Dictionary ( PDFDrive ).pdf
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
BP 505 T. PHARMACEUTICAL JURISPRUDENCE (UNIT 1).pdf
PDF
Journal of Dental Science - UDMY (2021).pdf
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PDF
Race Reva University – Shaping Future Leaders in Artificial Intelligence
PPTX
Education and Perspectives of Education.pptx
PDF
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
PPTX
Core Concepts of Personalized Learning and Virtual Learning Environments
PPTX
B.Sc. DS Unit 2 Software Engineering.pptx
PDF
My India Quiz Book_20210205121199924.pdf
PDF
LIFE & LIVING TRILOGY - PART (3) REALITY & MYSTERY.pdf
PDF
What if we spent less time fighting change, and more time building what’s rig...
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
Hazard Identification & Risk Assessment .pdf
advance database management system book.pdf
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
Virtual and Augmented Reality in Current Scenario
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
Empowerment Technology for Senior High School Guide
Skin Care and Cosmetic Ingredients Dictionary ( PDFDrive ).pdf
Paper A Mock Exam 9_ Attempt review.pdf.
BP 505 T. PHARMACEUTICAL JURISPRUDENCE (UNIT 1).pdf
Journal of Dental Science - UDMY (2021).pdf
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
Race Reva University – Shaping Future Leaders in Artificial Intelligence
Education and Perspectives of Education.pptx
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
Core Concepts of Personalized Learning and Virtual Learning Environments
B.Sc. DS Unit 2 Software Engineering.pptx
My India Quiz Book_20210205121199924.pdf
LIFE & LIVING TRILOGY - PART (3) REALITY & MYSTERY.pdf
What if we spent less time fighting change, and more time building what’s rig...

Graph and tree

  • 3.  A graph is a representative a set of objects where some pairs of objects are connected links.  The interconnected objects are called vertex or nodes And that links are called edges lines. 0 1 4 3 2
  • 5.  0 1 2 3 4  0 0 1 0 0 1  1 1 0 1 1 1  2 0 1 0 1 0  3 0 1 1 0 1 0 2 1 34
  • 6. 0 2 1 34 0 1 3 2 4 1 4 0 2 1 3 3 4 1 2 0 1 4 3
  • 8. subtree  Root: node without parent (A)  Siblings: nodes share the same parent  Internal node: node with at least one child (A, B, C, F)  External node (leaf ): node without children (E, I, J, K, G, H, D)  Ancestors of a node: parent, grandparent, grand-grandparent, etc.  Descendant of a node: child, grandchild, grand-grandchild, etc.  Depth of a node: number of ancestors  Height of a tree: maximum depth of any node (3)  Degree of a node: the number of its children  Degree of a tree: the maximum number of its node. A B DC G HE F I J K Subtree: tree consisting of a node and its descendants
  • 9.  Three main methods:  Preorder  Postorder  Inorder  Preorder:  visit the root  traverse in preorder the children (subtrees)  Postorder  traverse in postorder the children (subtrees)  visit the root
  • 10.  A traversal visits the nodes of a tree in a systematic manner  In a preorder traversal, a node is visited before its descendants  Application: print a structured document Become Rich 1. Motivations 3. Success Stories2. Methods 2.1 Get a CS PhD 2.2 Start a Web Site 1.1 Enjoy Life 1.2 Help Poor Friends 2.3 Acquired by Google 1 2 3 5 4 6 7 8 9
  • 11.  In a postorder traversal, a node is visited after its descendants  Application: compute space used by files in a directory and its subdirectories cs16/ homeworks/ todo.txt 1K programs/ DDR.java 10K Stocks.java 25K h1c.doc 3K h1nc.doc 2K Robot.java 20K 9 3 1 7 2 4 5 6 8
  • 12.  A binary tree is a tree with the following properties:  Each internal node has at most two children (degree of two)  The children of a node are an ordered pair  We call the children of an internal node left child and right child  Alternative recursive definition: a binary tree is either  a tree consisting of a single node, OR  a tree whose root has an ordered pair of children, each of which is a binary tree Applications: arithmetic expressions decision processes searching A B C F GD E H I
  • 13. Examples of the Binary Tree A B C GE I D H F Complete Binary Tree 1 2 3 4 A B A B Skewed Binary Tree E C D 5
  • 14. Binary search tree : binary search tree a particular type of containers: data structures that store items in memory.
  • 15. HEAP TREE:A binary heap is a complete binary tree which satisfies the heap ordering property.