Tree Interview Questions | Glassdoor

Tree Interview Questions

33

interview questions shared by candidates

Tree Interview Questions

Sort: RelevancePopular Date

Find the deepest common ancestor of two nodes in a tree structure.

13 Answers

This interview was frustrating because it felt like the woman couldn't write code in C++. I first asked whether I could assume a standard Tree node structure (as I've built several custom structures and they all have many of the same basic components) and she was pretty much dumbstruck and told me ti write the implementation for one. So i did. Then I started walking through my solution and practically had to spell the word iterator when I said I declared one. My solution was basically to just descend in the tree toward the first value until the two values are on different sides of the current node or you fall out the bottom of the tree. I had to repeat the conditional statements character by character for the interviewer.

Isn't the root node always the "deepest" common ancestor? Either the question is worded wrong, or you answered it incorrectly, but I think it's most likely that it's worded wrong.

@mliu the question is correct. u r thinking wrong. depth of a tree grows towards its leaves. root is the least deep node in a tree.

Find the minimum depth of binary search tree

10 Answers

Write a function that takes 2 arguments: a binary tree and an integer n, it should return the n-th element in the inorder traversal of the binary tree.

7 Answers

Define binary search tree. Develop a procedure to verify a binary search tree.

6 Answers

First explain what a tree, then binary tree, then a binary search tree is. Now implement a function that verifies whether a binary tree is a valid binary search tree.

5 Answers

In a BST write a program to find 2 nodes x and y such that X+y=k

4 Answers

find lowest common ancestor of 2 nodes in a binary tree

3 Answers

Write an algorithm that does an in-order traversal of a tree recursively. Now, write the same algorithm iteratively.

4 Answers

Find the height of a binary tree

3 Answers

Serialize (flatten) and de-serialize a binary tree. First describe the approach, then write the code.

3 Answers
110 of 33 Interview Questions