## National Instruments Interview Question for Software Engineer / Developers

• 0

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

We can use a recursive function along with static storage for the summation such that value is retained between successive call to the function.
This method first computer over left subtree and then on right subtree of the Root of the binary tree.. static specifier maintain the value between recursive calls..

void average(node* start)
{
static int average = 0;
if(start!= NULL)
{
result += node->value;
}
}

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

do a inorder traversal on binary tree and suming up all integer in node as well keep count of nodes as well.

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

void average(node *Start)
{
static int result=0;
static int count=0;
int average=0;
if(start !=null)
{
average(Start->left);
result+=Start->data;
count++;
average(Start->right);
}
average=(result)/count;

}

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

@Anonymous: Should the static variables be not declared as global???

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

``````struct node
{
int info;
}
typedef struct node *NODE;

void average(NODE first)
{
NODE temp;
temp=first;
int sum=0,n=0;
float avg=0.0;
do
{
sum=sum+temp->info;
n++;
}
avg=sum/n;
printf("average  = %f",avg);
}
}``````

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

@Anonymous: u have given the solution for a linked list. The question is to find the 'average for a BST'

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

public float meanvalue(int[] graph, int i)
{
float mean = 0 ;
int count = 0 ;
for all node in graph{
node.visit = false;
}
stack.push(i);
while(!stack.empty())
{
p <- stack.pop()
if(p is not visited)
{
visited[p] = true;
count++ ;
mean = mean + p.value;
for each neighbor p:
stack.push(p.neighbor)
}

}
mean = mean/ count;
return mean;
}

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

int CalculateAverage(stTree* pRoot)
{
int nCount = 0;
return CalculateSumNCount(pRoot,nCount)/nCount;
}

int CalculateSumNCount(stTree* pRoot,int& count)
{
if(pRoot == NULL)
return 0;
count++;
return (pRoot->data + CalculateSumNCount(pRoot->left,count) + CalculateSumNCount(pRoot->right,count));
}

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

I am an IT Recruiter looking for some Software Engineers in the Austin area contact me directly--client has asked that I recruit specifically for National Candidates candidates suzie.jimenez@thehtgroup.com 512.345.9300

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.