Prof - Hello , Please introduce yourself .
Me - Introduced .
Prof - Given an array can you write code to find minimum and maximum of array .
Me - Yes Sir
Here is the code I had written -
int max=arr[0];
int min=arr[0];
for(int i=1;i<n;i++)
{
if(a[i]<min)
min=a[i];
else if(a[i]>max)
max=a[i];
}
Prof- Can you optimisze this code So that number of comparisons are reduced ?
Me - I started explaining Tournament Approach . In which total number of comparisons to
find minimum and maximum elements of array is (3n/2 -2) .
But the way I explained was
not very clear to interviewer . They kept asking me how you are approaching it . I told them
to divide the array into two parts of size n/2 then form min and max array . And then take maximum
from max and minimum from min . This part confused interviewers and the whole interview almost
revolved around this topic .
Prof - Can you write code to construct a node for Binary search tree .
Me - written .
There were some minor mistakes I was doing while writing the code they pointed out and ask me to correct.
I used malloc in my code to which one professor asked
Prof- Why malloc is used ? What does this function do here.
Me- To allocate memory in heap for variables .
Prof - What does calloc function do ?
Me - It provides contigous memory in heap just like an array .
Prof- In this code can we use calloc instead of malloc ?
Me - Yes sir we can . (explained)
Prof - Now insert some nodes inside this BST . Explain algorithm only .
Me - Explained
Prof - Whenever you will insert any node do you have to change or update any internal nodes pointers.
of this BST ?
Me - No sir , Because this is a Binary search tree which is not required to be balanced . So each
time a node is inserted as a leaf node . So no need to update or change any internal nodes . If tree was
suppose AVL then updation is required .
I don't think my min-max approach was clear to them . Because even in last they were discussing about it . Professor asked me that are u doing pair-wise comparison and I said No in hurry .
After some instant one professor said that he is explaining same thing .
Prof - Okay , your interview is over now . Do you want to ask anything ?
Me - No sir.
Prof - It was nice to talk to you . We will announce results in next week. all the best.
Interview duration was around 30 minutes . Although I did some
mistakes as I was in pressure . But was very nice experience