Starting Out with C++ from Control Structures to Objects (9th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
9th Edition
ISBN: 9780134498379
Author: Tony Gaddis
Publisher: PEARSON
Question
Book Icon
Chapter 21, 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?
To accommodate search keys that are not unique, a new property was added to the search key. What impact may this modification have on the height of the B+-tree?
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