Computer Science, asked by shanilahameed3195, 1 year ago

If the inorder and level order traversal of a tree are given, what is the minimum height of the tree

Answers

Answered by raghuballu
0

Answer:

may be 2

Explanation:

may be 2 length of nodes are 2

Answered by ravilaccs
0

Answer:

The longest path from the root to the deepest leaf node, defines the height of a binary tree.

Explanation:

  • Given a binary tree, find out the height of binary using non-recursive algorithm.
  • Traverse the binary tree using level order traversal or breadth-first search algorithm.

Height of Binary tree

  • The longest path from the root to the deepest leaf node, defines the height of a binary tree.
  • Root node of a binary tree is assumed to be at Height 1.
  • Calculate the height of binary tree wrt. root node.

Algorithm: calculate height of a binary tree using breadth-first search

  • The root is at a height 1.
  • Push root node to queue.
  • Add null to the queue
  • null will be the level delimiter (a marker that we have finished the current level)
  • Start iterating through the Queue till it is empty
  • Pop node from the queue
  • Check node is null (if yes, we are next level)
  • Increment height by 1 & add level delimiter (null)
  • Add next level children (left or/and right)
  • At end of the iteration, we will get the height of the tree
Similar questions