Interview Question

Software Engineering New Grad Interview

-

Meta

How to access data from a tree structure and to sort them into an array?

Tags:data structures
AnswerAdd Tags

Interview Answers

5 Answers

0

Is it just a plain rooted tree or is there any property associated with the tree.

Anonymous on

0

I'm not a CS student, so I'm not sure if it is a plain tree. It is a rooted tree, and each branch with one or two branches below. The solution seems using recursion.

Anonymous on

0

Generally in this type of question, tree should mean a binary search tree in which each left child (and subtree) is smaller than the parent and right child (and subtree) is greater than the parent. So it requires an inorder traversal of this tree to obtain values in a sorted order that can be put in an array.

Fayyaz on

0

Small correction to above answer from Vikas... if the tree is a Binary Search tree, than an inorder traversal will by default get the nodes out in sorted order.

Anonymous on

0

if the tree is a binary tree, an INORDER traversal will provide a sorted series of elements in the binary tree ...

Vikas on

Add Answers or Comments

To comment on this, Sign In or Sign Up.