JavaScript Trees

This section covers the questions for the Tree Data Structure using JavaScript to clear all your concepts.

Last Updated :
Discuss
Comments

Question 1

Which of the following is true about Binary Trees?

  • Every binary tree is either complete or full.

  • Every complete binary tree is also a full binary tree.

  • Every full binary tree is also a complete binary tree.

  • No binary tree is both complete and full.

  • None of the above

Question 2

What are the main applications of tree data structure?

  1. Manipulate hierarchical data 
  2. Make information easy to search  
  3. Manipulate sorted lists of data 
  4. Router algorithms 
  5. Form of a multi-stage decision-making, like Chess Game. 
  6. As a workflow for compositing digital images for visual effects
  • 1, 2, 3, 4 and 6

  • 1, 2, 3, 4 and 5

  • 1, 3, 4, 5 and 6

  • 1, 2, 3, 4, 5 and 6

Question 3

Level of a node is distance from root to that node. For example, level of root is 1 and levels of left and right children of root is 2. The maximum number of nodes on level i of a binary tree is

In the following answers, the operator '^' indicates power.
  • 2^(i-1)
  • 2^i
  • 2^(i+1)
  • 2^[(i+1)/2]

Question 4

In a complete k-ary tree, every internal node has exactly k children or no child. The number of leaves in such a tree with n internal nodes is:
  • nk
  • (n – 1) k+ 1
  • n( k – 1) + 1
  • n(k – 1)

Question 5

The maximum number of binary trees that can be formed with three unlabelled nodes is:

  • 1

  • 5

  • 4

  • 3

Question 6

The number of leaf nodes in a rooted tree of n nodes, with each node having 0 or 3 children is:

  • n/2

  • (n-1)/3

  • (n-1)/2

  • (2n+1)/3

Question 7

A weight-balanced tree is a binary tree in which for each node. The number of nodes in the left sub tree is at least half and at most twice the number of nodes in the right sub tree. The maximum possible height (number of nodes on the path from the root to the farthest leaf) of such a tree on n nodes is best described by which of the following? a) \\log_2 n b) \\log_{4/3} n c) \\log_3 n d) \\log_{3/2} n

  • A

  • B

  • C

  • D

Question 8

A complete n-ary tree is a tree in which each node has n children or no children. Let I be the number of internal nodes and L be the number of leaves in a complete n-ary tree. If L = 41, and I = 10, what is the value of n?
  • 6
  • 3
  • 4
  • 5

Question 9

The height of a binary tree is the maximum number of edges in any root to leaf path. The maximum number of nodes in a binary tree of height h is:
  • 2^h -1
  • 2^(h-1) – 1
  • 2^(h+1) -1
  • 2*(h+1)

Question 10

Postorder traversal of a given binary search tree, T produces the following sequence of keys 10, 9, 23, 22, 27, 25, 15, 50, 95, 60, 40, 29 Which one of the following sequences of keys can be the result of an in-order traversal of the tree T? (GATE CS 2005)
  • 9, 10, 15, 22, 23, 25, 27, 29, 40, 50, 60, 95
  • 9, 10, 15, 22, 40, 50, 60, 95, 23, 25, 27, 29
  • 29, 15, 9, 10, 25, 22, 23, 27, 40, 60, 50, 95
  • 95, 50, 60, 40, 27, 23, 22, 25, 10, 9, 15, 29

There are 10 questions to complete.

Take a part in the ongoing discussion