Mock Interview Question Final
Mock Interview Question Final
2. A characteristic of data that binary search uses but linear search ignores is
A) length of the list B) order of the list 2
C) the maximum n value of the list D) None of these
7. We are given a set of n distinct elements and an unlabelled binary tree with n nodes. In
how many ways can we populate the tree with the given set so that it becomes a binary search
tree?
A) n! B) 0 C) (1/(n+1),2nCn D) 1
15. What does the following function do for a given Linked List with first node as head?
void fun1(struct node* head)
{
if(head == NULL)
return;
fun1 (head->next);
printf("%d", head->data);
}
A) Prints all nodes of linked list in reverse order
B) Prints alternate nodes of Linked List
C) Prints alternate nodes in the reverse order
D) Prints all nodes of the linked list
16. How to measure the size of any variable without “size of” operator?
17. How to merge two sorted linked list, so the resulting linked list is also sorted?
18. Suggest an efficient method to count the no. of 1’s in a 32bit no. Remember without using
loop & testing each bit?
19. How to swap the left and right children for each node of the given root node of a binary
tree?
20. Write a Program in C to Print all natural numbers up to N without using a semi-colon?
22. Out of the following operations, which one is not possible in the case of a register variable?
A) Global declaration of the register variable
B) Copying the value from the memory variable
C) Reading any value into the register variable
D) All of the above
30. For the following declaration of a function in C, pick the best statement?
int [] fun(void (*fptr)(int *));
A) It will result in compile error.
B) No compile error. fun is a function which takes a function pointer fptr as argument and
return an array of int.
C) No compile error. fun is a function which takes a function pointer fptr as argument and
returns an array of int. Also, fptr is a function pointer which takes int pointer as argument and
returns void.
D) No compile error. fun is a function which takes a function pointer fptr as argument and
returns an array of int. The array of int depends on the body of fun i.e. what size array is
returned. Also, fptr is a function pointer which takes int pointer as argument and returns void.
31 A City Bus is a Ring Route Bus which runs in circular fashion. That is, the Bus once started
at Source Bus Stop, halts at each Bus Stop in its Route and at the end it reaches to Source Bus
stop again. If there are n number of Stops and if bus starts at Bus Stop number 1, then after nth
Bus Stop, the next stop in the Route will be Bus Stop number1 always. If there are n stops,
there will be n paths. One path connects 2 stops. Distances (in meters) for all paths in Ring
Route is given in array Path[] as below. Path = 1800, 600. 750, 900, 1400, 1200, 1100, 1500]
Fare is determined based on the distance covered from source to destination stop as Distance d
between Input Source and Destination Stops can be measured by looking at values in array
Path[] and fare can be calculated as per following criteria: If d = 1000 meters, then fare= 5 INR
- (When calculating fare for other distances, the calculated fare containing any fraction value
should be celled. For example, for distance 900, when fare initially calculated is 4.5 which
must be ceiled to 5) Path is circular in function. Value at each index indicate distance till current
stop from previous one. And each index positions can be mapped with values at same index in
Busstops[] array, which is a string array holding abbreviation of names for all stops as
"THANERAILWAYSTN" "TH", "GAONDEVI"="GA", "ICEFACTROY" "IC")
"HARINIWASCIRCLE"="HA", "TEENHATHNAKA" "TE", "LUISWADI"="LU",
"NITINCOMPANYJUNCTION"="NI", "CADBURRYJUNCTION"="CA" Given, n=8,
where n is number of total Bus Stops. Bus Stops =["TH", "GA", "IC", "НА", "TE", "LU", "NI",
"CA"), Write a code with function getFare(String Source, String Destination) which takes Input
as source and destination stops(in the format containing first 2 characters of Name of the
Busstop) and calculate and return travel fare. (5 Marks)
1
121
12321
1234321
123454321
12345654321
1234567654321
33. Creating a music or media player using linked lists is a fascinating project that
demonstrates the use of data structures in a practical application. Design a basic media player
that can handle a playlist of songs.Use a suitable linked list to allow easy navigation in both
directions (forward and backward). (10 Marks)