SlideShare a Scribd company logo
1 of 10
The Theory of Computation
‫االحتسابية‬ ‫النظرية‬
‫رقم‬ ‫المحاضرة‬
-
10
-
Binary Trees ‫الثنائية‬ ‫االشجار‬
‫إعداد‬
‫م‬
.
‫حميد‬ ‫حبيب‬ ‫وديان‬ ‫م‬
‫االساسية‬ ‫التربية‬ ‫كلية‬
/
‫الحاسبات‬ ‫قسم‬
Differences Between A Tree and A Binary Tree
The subtrees of a binary tree are ordered; those of a tree are not ordered.
• Are different when viewed as binary trees.
• Are the same when viewed as trees.
A
B
A
B
Data Structure for Binary Trees
• A node is represented by an object storing
• Element
• Parent node
• Left child node
• Right child node B
D
A
C E
Arithmetic Expression Tree
• Binary tree associated with an arithmetic expression
• internal nodes: operators
• external nodes: operands
• Example: arithmetic expression tree for the expression (2  (a - 1) + (3  b))
+


-
2
a 1
3 b
Decision Tree
• Binary tree associated with a decision process
• internal nodes: questions with yes/no answer
• external nodes: decisions
• Example: dining decision
Maximum Number of Nodes in a Binary Tree
• The maximum number of nodes on depth i of a binary
tree is 2i, i>=0.
• The maximum nubmer of nodes in a binary tree of height
k is 2k+1-1, k>=0.
Prove by induction.
1
2
2 1
0
-
 +

 k
k
i
i
Full Binary Tree
• A full binary tree of a given height k has 2k+1–1 nodes.
Height 3 full binary tree.
Labeling Nodes In A Full Binary Tree
• Label the nodes 1 through 2k+1 – 1.
• Label by levels from top to bottom.
• Within a level, label from left to right.
Node Number Properties
Parent of node i is node i / 2, unless i = 1.
Node 1 is the root and has no parent.
• Right child of node i is node
2i+1, unless 2i+1 > n, where n is
the number of nodes.
• If 2i+1 > n, node i has no right
child.
Complete Binary Trees
• A labeled binary tree containing the labels 1 to n with root 1,
branches leading to nodes labeled 2 and 3, branches from these
leading to 4, 5 and 6, 7, respectively, and so on.
• A binary tree with n nodes and level k is complete iff its nodes
correspond to the nodes numbered from 1 to n in the full binary tree
of level k.
1
2 3
7
5
9
4
8
6
Complete binary tree
1
2 3
7
5
11
4
10
6
9
8 15
14
13
12
Full binary tree of depth 3

More Related Content

Similar to Lecture 10.pptx

data_structures_and_applications_-_module-4.ppt
data_structures_and_applications_-_module-4.pptdata_structures_and_applications_-_module-4.ppt
data_structures_and_applications_-_module-4.pptssuser5c874e
 
Unit iii(dsc++)
Unit iii(dsc++)Unit iii(dsc++)
Unit iii(dsc++)Durga Devi
 
Introduction to Binary Tree and Conersion of General tree to Binary Tree
Introduction to Binary Tree  and Conersion of General tree to Binary TreeIntroduction to Binary Tree  and Conersion of General tree to Binary Tree
Introduction to Binary Tree and Conersion of General tree to Binary TreeSwarupaDeshpande4
 
Data structures
Data structuresData structures
Data structuresIIUI
 
B trees and_b__trees
B trees and_b__treesB trees and_b__trees
B trees and_b__treesmeghu123
 
Lecture 9: Binary tree basics
Lecture 9: Binary tree basicsLecture 9: Binary tree basics
Lecture 9: Binary tree basicsVivek Bhargav
 
Chapter 5_Trees.pdf
Chapter 5_Trees.pdfChapter 5_Trees.pdf
Chapter 5_Trees.pdfssuser50179b
 
B-and-B-Tree-ppt presentation in data structure
B-and-B-Tree-ppt presentation in data structureB-and-B-Tree-ppt presentation in data structure
B-and-B-Tree-ppt presentation in data structuressuser19bb13
 
tutorial-tree (3).ppt
tutorial-tree (3).ppttutorial-tree (3).ppt
tutorial-tree (3).pptSrinivasanCSE
 
Tree Introduction.pptx
Tree Introduction.pptxTree Introduction.pptx
Tree Introduction.pptxRahulAI
 

Similar to Lecture 10.pptx (20)

data_structures_and_applications_-_module-4.ppt
data_structures_and_applications_-_module-4.pptdata_structures_and_applications_-_module-4.ppt
data_structures_and_applications_-_module-4.ppt
 
Data Structures 4
Data Structures 4Data Structures 4
Data Structures 4
 
B+ tree.pptx
B+ tree.pptxB+ tree.pptx
B+ tree.pptx
 
Unit iii(dsc++)
Unit iii(dsc++)Unit iii(dsc++)
Unit iii(dsc++)
 
Introduction to Binary Tree and Conersion of General tree to Binary Tree
Introduction to Binary Tree  and Conersion of General tree to Binary TreeIntroduction to Binary Tree  and Conersion of General tree to Binary Tree
Introduction to Binary Tree and Conersion of General tree to Binary Tree
 
Trees
TreesTrees
Trees
 
7.tree
7.tree7.tree
7.tree
 
DSA-Unit-2.pptx
DSA-Unit-2.pptxDSA-Unit-2.pptx
DSA-Unit-2.pptx
 
Tree
TreeTree
Tree
 
Data structures
Data structuresData structures
Data structures
 
Tree 11.ppt
Tree 11.pptTree 11.ppt
Tree 11.ppt
 
Tree
TreeTree
Tree
 
B trees and_b__trees
B trees and_b__treesB trees and_b__trees
B trees and_b__trees
 
Lecture 9: Binary tree basics
Lecture 9: Binary tree basicsLecture 9: Binary tree basics
Lecture 9: Binary tree basics
 
Chapter 5_Trees.pdf
Chapter 5_Trees.pdfChapter 5_Trees.pdf
Chapter 5_Trees.pdf
 
Unit 3 trees
Unit 3   treesUnit 3   trees
Unit 3 trees
 
B-and-B-Tree-ppt presentation in data structure
B-and-B-Tree-ppt presentation in data structureB-and-B-Tree-ppt presentation in data structure
B-and-B-Tree-ppt presentation in data structure
 
tutorial-tree (3).ppt
tutorial-tree (3).ppttutorial-tree (3).ppt
tutorial-tree (3).ppt
 
Tree Introduction.pptx
Tree Introduction.pptxTree Introduction.pptx
Tree Introduction.pptx
 
Unit 8
Unit 8Unit 8
Unit 8
 

More from SamiAAli44

المحاضرة الاولى بور بوينت تعليم اساسي.pptx
المحاضرة  الاولى      بور بوينت تعليم اساسي.pptxالمحاضرة  الاولى      بور بوينت تعليم اساسي.pptx
المحاضرة الاولى بور بوينت تعليم اساسي.pptxSamiAAli44
 
م.م عقيل ثامر (4).pptx
م.م عقيل ثامر (4).pptxم.م عقيل ثامر (4).pptx
م.م عقيل ثامر (4).pptxSamiAAli44
 
م.م عقيل ثامر (9).pptx
م.م عقيل ثامر (9).pptxم.م عقيل ثامر (9).pptx
م.م عقيل ثامر (9).pptxSamiAAli44
 
virus-140717152102-phpapp02.pdf
virus-140717152102-phpapp02.pdfvirus-140717152102-phpapp02.pdf
virus-140717152102-phpapp02.pdfSamiAAli44
 
________ ________1.ppt
________ ________1.ppt________ ________1.ppt
________ ________1.pptSamiAAli44
 
lce1 مترجمات.pptx
lce1 مترجمات.pptxlce1 مترجمات.pptx
lce1 مترجمات.pptxSamiAAli44
 
محاضرات في مادة طرائق التدريس التخصصية (1).pptx
محاضرات في مادة طرائق التدريس التخصصية (1).pptxمحاضرات في مادة طرائق التدريس التخصصية (1).pptx
محاضرات في مادة طرائق التدريس التخصصية (1).pptxSamiAAli44
 
Computer-Networks--Network.ppt
Computer-Networks--Network.pptComputer-Networks--Network.ppt
Computer-Networks--Network.pptSamiAAli44
 

More from SamiAAli44 (8)

المحاضرة الاولى بور بوينت تعليم اساسي.pptx
المحاضرة  الاولى      بور بوينت تعليم اساسي.pptxالمحاضرة  الاولى      بور بوينت تعليم اساسي.pptx
المحاضرة الاولى بور بوينت تعليم اساسي.pptx
 
م.م عقيل ثامر (4).pptx
م.م عقيل ثامر (4).pptxم.م عقيل ثامر (4).pptx
م.م عقيل ثامر (4).pptx
 
م.م عقيل ثامر (9).pptx
م.م عقيل ثامر (9).pptxم.م عقيل ثامر (9).pptx
م.م عقيل ثامر (9).pptx
 
virus-140717152102-phpapp02.pdf
virus-140717152102-phpapp02.pdfvirus-140717152102-phpapp02.pdf
virus-140717152102-phpapp02.pdf
 
________ ________1.ppt
________ ________1.ppt________ ________1.ppt
________ ________1.ppt
 
lce1 مترجمات.pptx
lce1 مترجمات.pptxlce1 مترجمات.pptx
lce1 مترجمات.pptx
 
محاضرات في مادة طرائق التدريس التخصصية (1).pptx
محاضرات في مادة طرائق التدريس التخصصية (1).pptxمحاضرات في مادة طرائق التدريس التخصصية (1).pptx
محاضرات في مادة طرائق التدريس التخصصية (1).pptx
 
Computer-Networks--Network.ppt
Computer-Networks--Network.pptComputer-Networks--Network.ppt
Computer-Networks--Network.ppt
 

Recently uploaded

Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxLigayaBacuel1
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........LeaCamillePacle
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayMakMakNepo
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxsqpmdrvczh
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 

Recently uploaded (20)

Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptx
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up Friday
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptx
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 

Lecture 10.pptx

  • 1. The Theory of Computation ‫االحتسابية‬ ‫النظرية‬ ‫رقم‬ ‫المحاضرة‬ - 10 - Binary Trees ‫الثنائية‬ ‫االشجار‬ ‫إعداد‬ ‫م‬ . ‫حميد‬ ‫حبيب‬ ‫وديان‬ ‫م‬ ‫االساسية‬ ‫التربية‬ ‫كلية‬ / ‫الحاسبات‬ ‫قسم‬
  • 2. Differences Between A Tree and A Binary Tree The subtrees of a binary tree are ordered; those of a tree are not ordered. • Are different when viewed as binary trees. • Are the same when viewed as trees. A B A B
  • 3. Data Structure for Binary Trees • A node is represented by an object storing • Element • Parent node • Left child node • Right child node B D A C E
  • 4. Arithmetic Expression Tree • Binary tree associated with an arithmetic expression • internal nodes: operators • external nodes: operands • Example: arithmetic expression tree for the expression (2  (a - 1) + (3  b)) +   - 2 a 1 3 b
  • 5. Decision Tree • Binary tree associated with a decision process • internal nodes: questions with yes/no answer • external nodes: decisions • Example: dining decision
  • 6. Maximum Number of Nodes in a Binary Tree • The maximum number of nodes on depth i of a binary tree is 2i, i>=0. • The maximum nubmer of nodes in a binary tree of height k is 2k+1-1, k>=0. Prove by induction. 1 2 2 1 0 -  +   k k i i
  • 7. Full Binary Tree • A full binary tree of a given height k has 2k+1–1 nodes. Height 3 full binary tree.
  • 8. Labeling Nodes In A Full Binary Tree • Label the nodes 1 through 2k+1 – 1. • Label by levels from top to bottom. • Within a level, label from left to right.
  • 9. Node Number Properties Parent of node i is node i / 2, unless i = 1. Node 1 is the root and has no parent. • Right child of node i is node 2i+1, unless 2i+1 > n, where n is the number of nodes. • If 2i+1 > n, node i has no right child.
  • 10. Complete Binary Trees • A labeled binary tree containing the labels 1 to n with root 1, branches leading to nodes labeled 2 and 3, branches from these leading to 4, 5 and 6, 7, respectively, and so on. • A binary tree with n nodes and level k is complete iff its nodes correspond to the nodes numbered from 1 to n in the full binary tree of level k. 1 2 3 7 5 9 4 8 6 Complete binary tree 1 2 3 7 5 11 4 10 6 9 8 15 14 13 12 Full binary tree of depth 3