## Bloomberg LP Interview Question Financial Software Developers

• 1
of 1 vote

Q: Do you know what is a Binary tree? How would you go about coding for addition of a new element to Binary tree?
A: I asked if they want a Binary Tree or a BST? When he said BST I just said we can have a recursive function in which we pass the root of the tree and see if the value to be added is smaller or bigger than the root, and depending on result, we go to left or right of the tree, assuming the left (or right) is not null. If null, just use new to create a memory location, put the value, and use the left reference of the root to link to this new memory. Simple basic stuff.

Country: United States
Interview Type: Phone Interview

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

``````struct node{
int info;
struct node *leftch;
struct node *rightch;
};

int AppendInBST(struct node **start, int num)
{
struct node *ptr,*tmp,*par=NULL;
tmp = (struct node*)malloc(sizeof(struct node));
tmp->info = num;
tmp->leftch= NULL;
tmp->rightch = NULL;

ptr = *start;
while(ptr != NULL)
{
par = ptr;
if(num > ptr->info)
ptr = ptr->rightch;
else if(num < ptr->info)
ptr = ptr->leftch;
else{
printf("Duplicate Entry\n");
return 0;
}
}
if(par == NULL)
{
*start = tmp;
}
else if(par->info > num)
par->leftch= tmp;
else if((par->info) < num)
par->rightch = tmp;
return 1;
}``````

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

``````struct node{
int data;
node *leftch;
node *rightch;
};

void intoatree(struct node **root, int n){
node *temp=new node;
(*temp).data=n;
(*temp).leftch=NULL;
(*temp).rightch=NULL;

node **par;

par=root;

if(*root==NULL){
*root=temp; //insert as the first node
}
else if((*(*par)).data==n){
cout<<"duplicate input"<<endl;
return;
}
else if((*(*par)).data>n){
*par=(*(*par)).leftch;
intoatree(par,n);
}
else{
*par=(*(*par)).rightch;
intoatree(par,n);
}

}``````

Name:

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

### Books

is a comprehensive book walking you through 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.