## National Instruments Interview Question for Software Engineer / Developers

• 0

Comment hidden because of low score. Click to expand.
0
of 0 vote

1. do a inorder traversal, maintain a static counter for no of elemnts, maintain a static sum variable..your job is done..

Comment hidden because of low score. Click to expand.
0
of 0 vote

How to find the loop in a binary tree.

Comment hidden because of low score. Click to expand.
0
of 0 vote

hahah.. !! trees do not have loops !!

Check the definition of a tree!!

Comment hidden because of low score. Click to expand.
0
of 0 vote

well, for more than one calls to your function static counter and sum won't work!

Comment hidden because of low score. Click to expand.
0

Hey, I think it should work...Should not be a problem in this case....

Comment hidden because of low score. Click to expand.
0

It would work..static member should be defined outside your main or any other functional call just after the pre-processor directives.

Comment hidden because of low score. Click to expand.
0
of 0 vote

Use non recursive DFS or use BFS. Mark a node as visited with BFS and if you come to that again then you are in a loop.

Comment hidden because of low score. Click to expand.
0
of 0 vote

Solution 1: Using Marker byte.
Solution 2: Using Property check, BST condition will fail. left<parent<right
Solution 3: like in Linked list, maintain 2 pointers,
if(ptr1==ptr2) loop detected
for a node call
ptr1 = node->left
ptr2 = node->left->left and also node->left->right
AND
ptr1 = node->right
ptr2 = node->right>left and also node->right>right

Comment hidden because of low score. Click to expand.
0
of 0 vote

Use inorder, preorder or postorder traversal or BFS or DFS to calculate the sum and average. Tree doesn't have loops

Comment hidden because of low score. Click to expand.
0
of 0 vote

Use recursion its very simple...to calculate sum and use static variable to calculate the number of nodes available and simple divide them.

The base case for the recursion will be:
{if (head of node is == null) return 0;}

else keep callin the same function with the argument as its child:
else
return (sum(left.child) + sum(right.child) + nodes' value);
and
static variable count = 0; and in each else count++;

Comment hidden because of low score. Click to expand.
0
of 0 vote

LOL......tree with loop!!!!!!!! :-)

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.