Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

In an expression tree algorithm, what happens when an operand is encountered?(a) create one node pointing to a stack(b) pop the nodes from the stack(c) clear stack(d) merge all the nodesThis key question is from Trees in portion Trees of Data Structures & Algorithms II had been asked this question in my homework.

Answer»

Correct CHOICE is (a) CREATE one node pointing to a STACK

For explanation: When an operand is encountered, create one node trees and push it on to the stack. When an operator is encountered, POP the pointers from last two trees from the stack.

2.

What is the postfix expression for the following expression tree?(a) abcde++**(b) ab+cde+**(c) abc+de+**(d) abcd+*e+*This question is from Trees in portion Trees of Data Structures & Algorithms IThis question was posed to me in an international level competition.

Answer» RIGHT answer is (b) ab+cde+**

Easy explanation - If the GIVEN expression tree is evaluated, the POSTFIX expression ab+cde+** is OBTAINED.
3.

An expression tree’s nodes can be deleted by calling?(a) malloc(b) calloc(c) delete(d) freeOrigin of the question is Trees topic in division Trees of Data Structures & Algorithms II have been asked this question in examination.

Answer»

Right answer is (d) free

Easiest EXPLANATION - In Binary TREES, NODES are created by calling MALLOC and they are deleted by calling free.

4.

++a*bc*+defg is an?(a) postfix expression(b) infix expression(c) prefix expression(d) invalid expressionThe origin of the question is Trees in division Trees of Data Structures & Algorithms IThis question was addressed to me in homework.

Answer» RIGHT choice is (c) prefix EXPRESSION

The BEST I can explain: It is a prefix expression obtained from a PREORDER traversal since it is of the form operator-operand-operand.
5.

An expression tree is created using?(a) postfix expression(b) prefix expression(c) infix expression(d) paranthesized expressionThis is a very interesting question from Trees in portion Trees of Data Structures & Algorithms IThis question was posed to me in an interview for internship.

Answer»

The correct CHOICE is (a) postfix expression

For explanation: A postfix expression is CONVERTED into an expression TREE by READING one symbol at a TIME and constructing a tree respectively.

6.

Only infix expression can be made into an expression tree.(a) true(b) falseThe doubt is from Trees in portion Trees of Data Structures & Algorithms II had been asked this question in an online interview.

Answer»

The correct ANSWER is (B) false

For explanation: All INFIX, prefix and postfix EXPRESSIONS can be made into an expression tree using appropriate ALGORITHMS.

7.

The average depth of a binary tree is given as?(a) O(N)(b) O(log N)(c) O(M log N)(d) O(√N)This question is from Trees topic in section Trees of Data Structures & Algorithms IThis question was posed to me during an interview.

Answer»

Correct choice is (d) O(√N)

The BEST I can EXPLAIN: The average depth of a BINARY expression TREE is mathematically found to be O(√N).

8.

The expression obtained by recursively producing a left expression, followed by an operator, followed by recursively producing a right expression is called?(a) prefix expression(b) infix expression(c) postfix expression(d) paranthesized expressionMy query is from Trees topic in portion Trees of Data Structures & Algorithms IThis question was addressed to me in examination.

Answer»

Correct CHOICE is (b) INFIX EXPRESSION

For EXPLANATION: It is an infix expression because the FORMAT of an infix expression is given by operand-operator-operand.

9.

An expression tree is a kind of?(a) Binary search tree(b) Fibonacci tree(c) Binary tree(d) TreapI'd like to ask this question from Trees in division Trees of Data Structures & Algorithms IThis question was posed to me in a job interview.

Answer»

The correct CHOICE is (c) BINARY tree

The BEST explanation: The EXPRESSION tree is a binary tree. It contains operands at leaf nodes and REMAINING nodes are filled with operators. The operands and the operators can be arranged in any order (ascending, descending).

10.

What does the other nodes of an expression tree(except leaves) contain?(a) only operands(b) only operators(c) both operands and operators(d) expressionMy question is taken from Trees topic in division Trees of Data Structures & Algorithms II have been asked this question during an interview for a job.

Answer»

Correct CHOICE is (b) only operators

Best EXPLANATION: The nodes other than leaves always contain only operators. There cannot be any OPERAND in those nodes.

11.

A node can have a minimum of one child.(a) true(b) falseI need to ask this question from Trees in portion Trees of Data Structures & Algorithms IThe question was asked by my college professor while I was bunking the class.

Answer» RIGHT CHOICE is (a) true

The BEST explanation: It is possible for a node to have at least ONE CHILD, as is the case with the unary minus operator.
12.

The leaves of an expression tree always contain?(a) operators(b) operands(c) null(d) expressionMy doubt stems from Trees topic in division Trees of Data Structures & Algorithms IThis question was posed to me in exam.

Answer» CORRECT ANSWER is (B) operands

The BEST I can explain: The leaves of an expression tree always contain the result of a given expression (i.e.) operands.
13.

Who invented k-d trees?(a) Arne Andersson(b) Jon Bentley(c) Jon Von Newmann(d) Rudolf BayerQuestion is from Trees topic in section Trees of Data Structures & Algorithms II got this question during an interview.

Answer»

Right option is (b) Jon BENTLEY

Explanation: Jon Bentley found k-d trees. Rudolf BAYER found RED black trees. Arne ANDERSSON found AA- trees.

14.

The 2d search tree has the simple property that branching on odd levels is done with respect to the first key.(a) True(b) FalseI'd like to ask this question from Trees topic in division Trees of Data Structures & Algorithms IThis question was addressed to me during an online exam.

Answer»

Correct answer is (a) True

To EXPLAIN: BRANCHING on ODD LEVELS is done with respect to the FIRST key and branching on even levels is done with respect to the second key in a 2-d tree.

15.

What is the time taken for a range query for a perfectly balanced tree?(a) O(N)(b) O(log N)(c) O(√N+M)(d) O(√N)I want to ask this question from Trees topic in division Trees of Data Structures & Algorithms II got this question in an interview.

Answer»

The correct answer is (C) O(√N+M)

Easy EXPLANATION - For a perfectly balanced k-d tree, the RANGE QUERY could TAKE O(√N+M) in the worst case to report M matches.

16.

Several kinds of queries are possible on a k-d called as?(a) partial queries(b) range queries(c) neighbour queries(d) search queriesThis interesting question is from Trees topic in chapter Trees of Data Structures & Algorithms II had been asked this question in homework.

Answer»

Right answer is (b) range queries

The EXPLANATION is: Several range queries are POSSIBLE on a k-d tree. ONE of the range queries is KNOWN as a partial match query.

17.

Reducing search space by eliminating irrelevant trees is known as?(a) pruning(b) partial results(c) freeing space(d) traversingEnquiry is from Trees topic in chapter Trees of Data Structures & Algorithms IThis question was posed to me during an online exam.

Answer»

Correct answer is (a) pruning

The best explanation: Pruning is eliminating irrelevant trees. Partial RESULTS are KEEPING best results and UPDATING. TRAVERSAL is visiting all the nodes of a TREE.

18.

How many prime concepts are available in nearest neighbour search in a kd tree?(a) 1(b) 2(c) 3(d) 4The above asked question is from Trees in division Trees of Data Structures & Algorithms IThe question was asked by my school teacher while I was bunking the class.

Answer»

Correct answer is (c) 3

Easiest explanation - THREE IMPORTANT concepts are available in finding the nearest NEIGHBOUR. They are partial results, PRUNING, traversal ORDER.

19.

What is the run time of finding the nearest neighbour in a k-d tree?(a) O(2+ log N)(b) O( log N)(c) O(2^d log N)(d) O( N log N)My query is from Trees topic in chapter Trees of Data Structures & Algorithms IThe question was asked in homework.

Answer»

Right answer is (c) O(2^d log N)

To EXPLAIN: The run TIME of finding the nearest neighbour in a KD TREE is given as O(2^d log N) where 2^d is the time taken to search the neighbourhood.

20.

What is the worst case of finding the nearest neighbour?(a) O(N)(b) O(N log N)(c) O( log N)(d) O(N^3)Enquiry is from Trees topic in division Trees of Data Structures & Algorithms IThe question was asked during an interview.

Answer»

Correct answer is (a) O(N)

The EXPLANATION is: The worst CASE ANALYSIS of finding the nearest neighbour in a k-d tree is mathematically FOUND to be O(N).

21.

Each level in a k-d tree is made of?(a) dimension only(b) cutting and dimension(c) color code of node(d) size of the levelI'd like to ask this question from Trees topic in section Trees of Data Structures & Algorithms II got this question by my college professor while I was bunking the class.

Answer» CORRECT option is (B) CUTTING and dimension

Explanation: Each level in a k-d tree is MADE of dimensions and cutting. Cutting and dimensions are used for INSERTION, deletion and searching purposes.
22.

What will be the correct sequence of insertion for the following k-d tree?(a) (30,40),(5,25),(70,70),(10,12),(50,30),(35,45)(b) (40,30),(5,25),(12,10),(70,70),(30,50),(45,35)(c) (30,40),(5,25),(10,12),(70,70),(50,30),(35,45)(d) (40,30),(25,5),(12,10),(70,70),(50,30),(45,35)My doubt stems from Trees in section Trees of Data Structures & Algorithms II got this question during an online exam.

Answer»

Right answer is (C) (30,40),(5,25),(10,12),(70,70),(50,30),(35,45)

EXPLANATION: The correct sequence of INSERTION of the above GIVEN TREE is (30,40),(5,25),(10,12),(70,70),(50,30),(35,45). The insertion is given by, first left, then right.

23.

In a k-d tree, k originally meant?(a) number of dimensions(b) size of tree(c) length of node(d) weight of nodeThis key question is from Trees in portion Trees of Data Structures & Algorithms II got this question during an interview.

Answer» CORRECT answer is (a) NUMBER of dimensions

For explanation: INITIALLY, 2-d TREES were CREATED. Then, 3-d trees, 4-trees etc., where k meant the number of dimensions.
24.

Which of the following is the simplest data structure that supports range searching?(a) Heaps(b) binary search trees(c) AA-trees(d) K-d treesThe question is from Trees topic in portion Trees of Data Structures & Algorithms IThis question was posed to me in homework.

Answer»

The correct answer is (d) K-d TREES

Explanation: K-d trees are the simplest DATA structure that supports RANGE SEARCHING and also it achieves the respectable running time.

25.

In a two-dimensional search tree, the root is arbitrarily chosen to be?(a) even(b) odd(c) depends on subtrees(d) 1My question is based upon Trees in division Trees of Data Structures & Algorithms II got this question in an international level competition.

Answer»

Correct answer is (b) odd

For explanation: In a TWO- dimensional k-d TREE (i.e.) 2-d tree, the root is arbitrarily CHOSEN to be an odd level and it APPLIES to all 2-d TREES.

26.

Insertion into a 2-d tree is a trivial extension of insertion into a binary search tree.(a) true(b) falseQuery is from Trees in portion Trees of Data Structures & Algorithms IThis question was addressed to me in an online interview.

Answer»

Correct answer is (a) true

Best explanation: Insertion of elements in a 2-d tree is SIMILAR to that of a BINARY SEARCH tree. HENCE, it is a trivial EXTENSION of the binary search tree.

27.

In what time can a 2-d tree be constructed?(a) O(N)(b) O(N log N)(c) O(N^2)(d) O(M log N)My enquiry is from Trees topic in portion Trees of Data Structures & Algorithms IThis question was posed to me during a job interview.

Answer»

The correct answer is (b) O(N LOG N)

Easy explanation - A PERFECTLY balanced 2-d tree can be CONSTRUCTED in O(N log N) TIME. This value is computed mathematically.

28.

Bigger the query rectangle the better is the query efficiency.(a) true(b) falseThis interesting question is from Trees topic in section Trees of Data Structures & Algorithms IThe question was posed to me in class test.

Answer»

Right choice is (b) false

To explain: EFFICIENCY of bin depends upon the LOCATION and size of QUERY and candidates. ALSO, the smaller is the query rectangle the BETTER is the query efficiency.

29.

Efficiency of bin depends upon ___________(a) size of query and candidates(b) location of query and candidates(c) location and size of query and candidates(d) depends on the inputThe doubt is from Trees in chapter Trees of Data Structures & Algorithms IThe question was posed to me in homework.

Answer» RIGHT option is (c) location and SIZE of query and candidates

Explanation: Efficiency of BIN DEPENDS upon the location and size of query and candidates. It is SIMILAR to that of a hash table.
30.

What will be the time complexity of insertion operation if all the candidates are evenly spaced so that each bin has constant no. of candidates? (m = number of bins intersecting candidate intersects)(a) O(1)(b) O(m)(c) O(m^2)(d) O(log m)The query is from Trees in section Trees of Data Structures & Algorithms IThe question was asked in homework.

Answer»

Correct choice is (b) O(m)

EASY explanation - The process of insertion BECOMES faster in the CASE when the number of CANDIDATES are equally DISTRIBUTED among the bins. In such a case the query operation becomes O(m). It is practically faster than deletion in this case.

31.

What will be the time complexity of delete operation if all the candidates are evenly spaced so that each bin has constant no. of candidates? (m = number of bins intersecting candidate intersects)(a) O(1)(b) O(m)(c) O(m^2)(d) O(log m)This interesting question is from Trees topic in chapter Trees of Data Structures & Algorithms II had been asked this question in my homework.

Answer»

Right option is (b) O(m)

The best I can EXPLAIN: The process of DELETION becomes faster in a case when the number of candidates are equally distributed AMONG the bins. In such a case the QUERY operation becomes O(m). It is practically SLOWER than insertion in this case.

32.

What will be the time complexity of query operation if all the candidates are evenly spaced so that each bin has constant no. of candidates? (k = number of bins query rectangle intersects)(a) O(1)(b) O(k)(c) O(k^2)(d) O(log k)Query is from Trees topic in section Trees of Data Structures & Algorithms IThis question was posed to me in examination.

Answer» RIGHT answer is (B) O(k)

The best I can EXPLAIN: The process of query becomes faster in a case when the number of candidates are equally DISTRIBUTED among the bins. In such a case the query operation becomes O(k).
33.

What is computational geometry?(a) study of geometry using a computer(b) study of geometry(c) study of algorithms(d) study of algorithms related to geometryThe query is from Trees topic in chapter Trees of Data Structures & Algorithms IThis question was posed to me during an interview.

Answer»

The correct CHOICE is (d) study of algorithms RELATED to geometry

For explanation: COMPUTATIONAL geometry deals with the study of algorithms which can be expressed in TERMS of geometry. Bin data structure is an example of it.

34.

What is the worst case time complexity of insertion operation(n =no. of candidates)?(a) O(1)(b) O(n)(c) O(log n)(d) O(n log n)My doubt is from Trees in section Trees of Data Structures & Algorithms II have been asked this question in exam.

Answer»

Right CHOICE is (a) O(1)

The EXPLANATION is: The WORST case in a bin INSERT operation occurs when all the candidates are concentrated in one bin. So in this case the time complexity is O(1).

35.

What is the worst case time complexity of delete operation(n is the no. of candidates)?(a) O(1)(b) O(n)(c) O(log n)(d) O(n log n)My question is from Trees in division Trees of Data Structures & Algorithms IThe question was asked in class test.

Answer»

The correct choice is (b) O(n)

EASIEST explanation - The WORST CASE in a BIN delete operation OCCURS when all the candidates are concentrated in one bin. So in this case the time complexity is O(n).

36.

What is the worst case time complexity of query operation(n is the no. of candidates)?(a) O(1)(b) O(n)(c) O(log n)(d) O(n log n)Query is from Trees in chapter Trees of Data Structures & Algorithms IThe question was asked by my college professor while I was bunking the class.

Answer»

Correct answer is (B) O(n)

Best explanation: The worst case in a BIN query occurs when all the candidates are concentrated in ONE bin. So in this case the time COMPLEXITY is O(n).

37.

Bin is an example of a range query data structure.(a) true(b) falseQuery is from Trees in division Trees of Data Structures & Algorithms IThe question was asked during an internship interview.

Answer»

The correct option is (a) true

For explanation: BIN is an EXAMPLE of a RANGE query data structure. It is because it efficiently answers any number of queries on any subset of the input.

38.

What is the use of the bin data structure?(a) to have efficient insertion(b) to have efficient deletion(c) to have efficient region query(d) to have efficient traversalI would like to ask this question from Trees in division Trees of Data Structures & Algorithms IThis question was posed to me in quiz.

Answer»

Right answer is (c) to have efficient region query

The best I can explain: Bin DATA STRUCTURE allows us to have efficient region queries. A FREQUENCY of bin is increased by one each time a data point falls into a bin.

39.

What is the condition for an equivalence relation if two cities are related within a country?(a) the two cities should have a one-way connection(b) the two cities should have a two-way connection(c) the two cities should be in different countries(d) no equivalence relation will exist between two citiesMy enquiry is from Trees topic in portion Trees of Data Structures & Algorithms II have been asked this question in semester exam.

Answer»

Right answer is (b) the TWO cities should have a two-way connection

The best I can EXPLAIN: If the two towns are in the same COUNTRY and have a two-way road connection between them, it satisfies equivalence property.

40.

What is the total time spent for N-1 merges in a dynamic equivalence problem?(a) O(N)(b) O(log N)(c) O(N log N)(d) O(M log N)The above asked question is from Trees in section Trees of Data Structures & Algorithms IThe question was asked in unit test.

Answer»

The CORRECT CHOICE is (c) O(N log N)

Easy EXPLANATION - The total time spent for N-1 merges in a dynamic EQUIVALENCE problem is mathematically found to be O(N log N).

41.

How many strategies are followed to solve a dynamic equivalence problem?(a) 1(b) 2(c) 3(d) 4Asked question is from Trees in section Trees of Data Structures & Algorithms IThe question was asked in an internship interview.

Answer» RIGHT choice is (b) 2

The BEST I can explain: There are two strategies INVOLVED to SOLVE a dynamic equivalence problem- executing find instruction in worst-case time and executing union instruction in worst-case time.
42.

In the Union/Find algorithm, the ranks of the nodes on a path will increase monotonically from?(a) leaf to root(b) root to node(c) root to leaf(d) left subtree to right subtreeQuestion is taken from Trees in section Trees of Data Structures & Algorithms IThis question was addressed to me in my homework.

Answer»

Right choice is (a) leaf to root

To explain: One of the lemmas STATE that, in the Union/Find algorithm, the ranks of the NODES on a path will increase MONOTONICALLY from leaf to root.

43.

What is the worst-case running time of unions done by size and path compression?(a) O(N)(b) O(logN)(c) O(N logN)(d) O(M logN)My question is based upon Trees topic in section Trees of Data Structures & Algorithms IThe question was asked by my school teacher while I was bunking the class.

Answer» RIGHT CHOICE is (d) O(M logN)

For explanation: The worst case running time of a union operation done by size and PATH compression is mathematically found to beO(M logN).
44.

What is the value for the number of nodes of rank r?(a) N(b) N/2(c) N/2^r(d) N^rThis intriguing question comes from Trees topic in portion Trees of Data Structures & Algorithms IThis question was addressed to me during an online exam.

Answer»

Correct CHOICE is (c) N/2^r

For EXPLANATION: Each NODE of a RANK r is the root of a subtree of at least 2^r. THEREFORE, there are at most N/2^r disjoint subtrees.

45.

When executing a sequence of Unions, a node of rank r must have at least 2^r descendants.(a) true(b) falseMy question comes from Trees in section Trees of Data Structures & Algorithms II have been asked this question in an interview for job.

Answer»

Correct choice is (a) true

The best explanation: By the INDUCTION hypothesis, each tree has at LEAST 2^r – 1 descendants, giving a total of 2^r and ESTABLISHING the lemma.

46.

What is the depth of any tree if the union operation is performed by height?(a) O(N)(b) O(log N)(c) O(N log N)(d) O(M log N)My doubt is from Trees topic in division Trees of Data Structures & Algorithms II had been asked this question in semester exam.

Answer»

Correct choice is (B) O(LOG N)

For EXPLANATION: If the Unions are PERFORMED by HEIGHT, the depth of any tree is calculated to be O(log N).

47.

___________ is one of the earliest forms of a self-adjustment strategy used in splay trees, skew heaps.(a) Union by rank(b) Equivalence function(c) Dynamic function(d) Path compressionOrigin of the question is Trees topic in division Trees of Data Structures & Algorithms II had been asked this question at a job interview.

Answer»

Right choice is (d) PATH COMPRESSION

Explanation: Path compression is one of the EARLIEST forms of self-adjustment used in extremely important strategies USING theoretical explanations.

48.

What is the definition for Ackermann’s function?(a) A(1,i) = i+1 for i>=1(b) A(i,j) = i+j for i>=j(c) A(i,j) = i+j for i = j(d) A(1,i) = i+1 for i

Answer»

Correct option is (a) A(1,i) = i+1 for i>=1

Easy EXPLANATION - The Ackermann’s function is defined as A(1,i) = i+1 for i>=1. This FORM in TEXT grows FASTER and the inverse is SLOWER.

49.

Path Compression algorithm performs in which of the following operations?(a) Create operation(b) Insert operation(c) Find operation(d) Delete operationThis interesting question is from Trees topic in portion Trees of Data Structures & Algorithms IThe question was asked by my college professor while I was bunking the class.

Answer»

Right CHOICE is (C) Find operation

The best explanation: Path compression ALGORITHM is performed during find operation and is independent of the strategy used to perform unions.

50.

What is the worst case efficiency for a path compression algorithm?(a) O(N)(b) O(log N)(c) O(N log N)(d) O(M log N)My doubt stems from Trees in section Trees of Data Structures & Algorithms IThis question was addressed to me in homework.

Answer» RIGHT OPTION is (d) O(M log N)

Best explanation: The worst case EFFICIENCY for a PATH COMPRESSION algorithm is mathematically found to be O(M log N).