Starting Out with C++ from Control Structures to Objects (8th Edition)
Starting Out with C++ from Control Structures to Objects (8th Edition)
8th Edition
ISBN: 9780133769395
Author: Tony Gaddis
Publisher: PEARSON
Question
Book Icon
Chapter 20, Problem 20RQE
Program Plan Intro

Binary tree:

  • It is a tree data structure which comes under hierarchical data structure.
  • It is made of nodes that have a left child, right child and a data element.

Tree traversal:

  • There are 3 common methods
    • Inorder traversal
    • Preorder traversal
    • Postorder traversal
  • In inorder traversal, the left subtree is encountered first, then data node and then the right subtree.
  • In preorder traversal, the data node is encountered first, then left subtree and then the right subtree.
  • In postorder traversal, the left subtree is encountered first, then right subtree and then the data node.

Algorithm for Postorder traversal:

  • Traverse through the leftmost subtree and then print the element.
  • Ttraverse the rightmost subtree and then print the element.
  • At last visit and print the root node.

Blurred answer
Students have asked these similar questions
How would the values in the tree you sketched for queston 16 be displayed in a preorder traversal?
A new property was added to the search key to address non-unique search keys. What impact may this modification have on the height of the B+-tree?
For non-unique search keys, a property was added. How does this affect B+ tree height?
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:9781305503922
Author:Patrick M. Carey
Publisher:Cengage Learning