21. What is the average case time complexity for finding the height of the binary tree?
- h = O(loglogn)
- h = O(n)
- h = O(nlogn)
- h = O(log n)
Answer : D Explanation: The nodes can be either a part of left sub tree or the right sub tree, so we don’t have to traverse all the nodes, this means the complexity is lesser than n, in the average case, assuming the nodes are spread evenly, the time complexity becomes O(logn). So, option D is correct.
22. Which of the following statement about binary tree is correct?
- Every binary tree is either complete or full
- Every full binary tree is also a complete binary tree
- Every complete binary tree is also a full binary tree
- A binary tree cannot be both complete and full
Answer : B Explanation: Every full binary tree is also a complete binary tree. So, option B is correct.
23. In a full binary tree if number of internal nodes is I, then number of leaves L are?
- L = 2I
- L = I + 1
- L = I – 1
- L = 2I – 1
Answer : B Explanation: In a full binary tree if number of internal nodes is I, then number of leaves L are L = I + 1.
24. What is the number of edges present in a complete graph having n vertices?
- (n*(n+1))/2
- (n*(n-1))/2
- n
- Given information is insufficient
Answer : B Explanation: Number of ways in which every vertex can be connected to each other is nC2. The number of edges present in a complete graph having n vertices is (n*(n-1))/2. So, option B is correct.
25. Suppose a binary tree is constructed with n nodes, such that each node has exactly either zero or two children. The maximum height of the tree will be?
- (n-1)/2
- (n+1)/2
- n/2 -1
- (n+1)/2 -1
Answer : A Explanation: (n-1)/2
26. Which of the following statements for a simple graph is correct?
- Every trail is a path
- Every path is a trail
- Every trail is a path as well as every path is a trail
- None of the above mentioned
Answer : B Explanation: In data structures, in a walk, if the vertices are distinct it is called a path, whereas if the edges are distinct it is called a trail. So, option B is correct.
27. Which of the following ways can be used to represent a graph?
- Incidence Matrix
- Adjacency List, Adjacency Matrix as well as Incidence Matrix
- Adjacency List and Adjacency Matrix
- No way to represent
Answer : B Explanation: A graph can be represented through some ways including: Adjacency List, Adjacency Matrix as well as Incidence Matrix.
28. If all c( i , j )’s and r( i, j )’s are calculated, then OBST algorithm in worst case takes one of the following time:
- O(log n)
- O(n^2)
- O(n log n)
- O(n^3)
Answer : D Explanation: O(n^3)
29. The postfix form of the expression (A+ B)*(C*D- E)*F / G is?
- AB+ CD*E – FG /**
- AB + CD* E – F **G /
- AB + CD* E – *F *G /
- AB + CDE * – * F *G /
Answer : C Explanation: AB + CD* E – *F *G /
30. Quick Sort can be categorized into which of the following?
- Dynamic programming
- Greedy algorithm
- Divide and conquer
- Brute Force technique
Answer : C Explanation: Quick sort is based on divide and conquer because first we divide the array of elements into smaller partition and then process (conquer) over it.
Pingback: JavaScript MCQ Questions and Answers - cozmocard