Vous êtes sur la page 1sur 19

MCQ: 1)what is the complexity of retrieving min element from a max heap.

2)which is the fastet method to sort an almost sorted array: quick sort,bubble sort,merge sort,shell sort 3)zombie process 4)reverse linked list and a few questions on tress and dynamic prog and aptitude testing. Question 1/22 In a binary max heap containing n numbers, the smallest element can be found in time O(n) O(log(n)) O(log(log(n)) O(1) Question 2 / 22 . A data structure is required for storing a set of integers such that each of the following operations can be done in (log n) time, where n is the number of elements in the set. Deletion of the smallest element Insertion of an element if it is not already present in the set Which of the following data structures can be used for this purpose? Pick one of the choices A heap can be used but not a balanced binary search tree A balanced binary search tree can be used but not a heap Both balanced binary search tree and heap can be used Neither balanced binary search tree nor heap can be used Skip QuestionPrevious Question 3. Question 3 / 22 Predict the output
void m1(int *a){ a = new int[20]; a[0] = 100;

} void m2(int *a){ a = new int[20]; a[0] = 200; delete[] a; } void foo(){ int *a = new int[10]; a[0] = 20; printf(%d, a[0]); m1(a); printf(%d, a[0]); m2(a); printf(%d, a[0]); }

Pick one of the choices 20, 100, 200 20, 100, Crash!! 20, 20, 20 None of the above

Question 4 / 22

What will the following code snippet do, when is it passed the root of a binary tree ?
func( Node *node){ if(node->right != NULL) func( node->right); if(node->left != NULL) func( node->left);

if( node->left == NULL && node->right == NULL ) delete(node); }

Pick one of the choices

Delete the tree from bottom to top Delete the tree from top to bottom Delete the leaf nodes from right to left Delete the leaf nodes from left to right Question 5 / 22
int x[] = { 1, 4, 8, 5, 1, 4 }; int *ptr, y; ptr = x + 4;

y = ptr - x;

What does y in the sample code above equal? Pick one of the choices -3 0 4 4+sizeof(int) Skip QuestionPrevious Question Question 6 / 22 What's the output?
main() { int a[5] = {1,2,3,4,5}; int *ptr = (int*)(&a+1); printf("%d %d" ,*(a+1),*(ptr-1)); }

Pick one of the choices

22 21 25 None of the above Question 7 / 22 A "Most efficient data structure" is designed to optimize the following operations. Pop, Push, Min. The best possible time-complexities with no extra space, respectively would be: Pick one of the choices O(1), O(1), O(N) O(1), O(N), O(1) O(N), O(1), O(1) O(1), O(1), O(1) Question 8 / 22 Suppose you are given an array s[1..n] and a procedure reverse(s,i,j) which reverses the order of elements in s between positions i and j (both inclusive). What does the following sequence do,where 1 <= k < n: reverse(s,1,k) reverse(s,k+1,n) reverse(s,1,n) Pick one of the choices Rotates s left by k positions Leaves s unchanged Reverses all elements of s None of the above Skip QuestionPrevious Question Question 9 / 22 The number of total nodes in a complete balanced binary tree with n levels is, Pick one of the choices

None of the above 3^n + 1 2^(n + 1) -1 2^n + 1 Skip QuestionPrevious Question Question 10 / 22 Which of the following statements are correct about the following program?
#include int main(){ unsigned int num; int i; scanf("%u", &num); for(i=0; i < 16; i++) { printf("%d", (num<<<15)?1:0); } return 0; }

Pick one of the choices


It prints all even bits from num It prints all odd bits from num It prints binary equivalent of num This result in an error Skip QuestionPrevious Question

Question 11 / 22
What does the function doSomething return when the argument is the root of a binary tree?
#define min(a,b) ((a) < (b) ? (a) : (b))

struct Node { struct Node* left; int element; struct Node *right; }; int doSomething(Node *ptr){ static long counter = 0; int value = 0; if(ptr != NULL){ value = 1 + min(doSomething(ptr->left), doSomething(ptr->right)); } return (value); }

Pick one of the choices


Width of the tree Height of the tree Minimum distance between a leaf node and root. Minimum distance between 2 leaf nodes. Skip QuestionPrevious Question

Question 12 / 22
Memory on a machine has space for 3 pages. For the following page access pattern, what is the sequence of pages for which page fault will occur. Give the answer for two different page swapping algorithms, (i) least recently used and (ii) least frequently used. Assume that no page is available in the memory while starting. 8,5,8,9,5,6,5,6,5,8,9,5,8,7,6,7,9 Pick one of the choices LRU Page fault sequence: 8,5,9,6,8,9,7,6,9 LFU Page fault sequence: 8,5,9,6,9,7,6,7,8 LRU Page fault sequence: 8,5,9,7,8,9,7,6,9 LFU Page fault sequence: 8,5,9,6,9,7,8,7,9

LRU Page fault sequence: 8,5,9,6,8,9,7,6,9 LFU Page fault sequence: 8,5,9,6,9,7,6,7,9 LRU Page fault sequence: 8,5,9,7,8,9,7,6,9 LFU Page fault sequence: 8,5,9,6,9,7,6,7,9

Question 13 / 22
How many child processes will be generated by the following?
void main() { int p1= fork(); if (p1 == 0) { int p2 = fork(); if (p2 != 0) { fork(); } } }

Pick one of the choices


3 4 5 6

Question 14 / 22
A parallel program consists of 8 tasks T1 through T8. Each task requires one time step to be executed on a single processor. Let X -> Y denote the fact that task X must be executed before task Y is executed. Suppose only the tasks X, Y are to be executed. On any multiprocessor machine it would require at least 2 time steps since in the first step X could be executed, and Y could be executed in the next time step (since it requires X to complete first). Now, suppose the following dependencies exist between the tasks T1 T8:
T1 T2 T3 T2 T4 T2 T5 -> -> -> -> -> -> -> T2 T3 T6 T4 T7 T5 T8

What is the minimum number of time steps required to execute these 8 tasks on a 2 processor machine and a 4 processor machine? Pick one of the choices 4 and 2 respectively 5 and 2 respectively 5 and 4 respectively 6 and 2 respectively

Question 15 / 22
In a country where everyone wants a boy, each family continues having babies till they have a boy. After some time, what is the proportion of boys to girls in the country? (Assuming probability of having a boy or a girl is the same) Pick one of the choices 1:2 2:1 1:1 1:4

Question 16 / 22
Four players A, B, C and D are holding 4 cards each. Each of them has an Ace, a King, a Queen and a Jack. All of them have all the suits (Spades, hearts, clubs and diamonds).

I. A has Ace of spades and Queen of diamonds. II. B has ace of clubs and King of diamonds. III. C has Queen of clubs and King of spades. IV. D has Jack of clubs.

Ace of diamonds is with Pick one of the choices A B

C D

Question 17 / 22
Deb normally drives to work in 45 minutes at an average speed of 40 miles per hour. This week, however, she plans to bike to work along a route that decreases the total distance she usually travels when driving by 20%. If Deb averages between 12 and 16 miles per hour when biking, how many minutes earlier will she need to leave in the morning in order to ensure she arrives at work at the in time as when she drives? Pick one of the choices 135 120 40 75

Question 18 / 22
Each of the three players Sehwag, Raina and Yuvraj plays exactly one game among Cricket, Football and Tennis, not necessarily in the same order. Each player always gives two replies to any question . Out of these 3 players, exactly one player always speaks the truth, one always lies and one always alternates between truth and lies in any order. When each was asked Which game do you play? , the following were their replies Sehwag : I am a cricketer. Raina is a football player Raina : I am a cricketer. Yuvraj is a tennis player Yuvraj : Sehwag is a football player. Raina is a cricket player Which game does Raina play ? Pick one of the choices Cricket Football Tennis Cannot be determined Skip QuestionPrevious Question

Question 19 / 22
In a class , 72 students drink only tea, 50% of the students drink coffee, 25% of the students drink both tea and coffee and 5% of the students drink neither tea nor coffee. How many of the students drink only coffee ? Pick one of the choices 29 38 40 49

Question 20 / 22
There are 6 boxes numbered 1, 2,...6. Each box is to be filled up either with a red or a green ball in such a way that at least 1 box contains a green ball and the boxes containing green balls are consecutively numbered. The total number of ways in which this can be done is Pick one of the choices 5 21 33 60 Question 21 / 22 Given an integer array sequence, return the length of the longest increasing subsequence (LIS) A longest increasing subsequence is defined as a subsequence in the given sequence of integers such that the elements in the subsequence are in sorted order, lowest to highest and in which the subsequence is as long as possible Sample Test Cases: Input #00: 1, 2, 3 Output: 3 Explanation: The sequence in itself is an increasing one

Input #01: 4, 5, 6, 7, 8, 1, 2, 1, 2, 3, 5, 4, 6, 7, 8, 9, 0, 6, 7 Output #01: 5 Explanation: The length of the LIS is 5. The LIS elements from the sequence are highlighted: 4, 5, 6, 7, 8, 1, 2,1, 2, 3, 5, 4, 6, 7, 8, 9, 0, 6, 7 int lengthLIS(int sequence[], int N){ /*N: size of the array */ } Question 22 / 22 You are given a function sprialArray which takes in a 2-d array. Complete the function to print the numbers in a clockwise spiral order NOTE: Print the numbers with one space separating them. Your output should match with the one given below in the sample testcases Sample Testcases: Input #00: M = 3, N = 3 123 456 789 Output #00: 123698745 Input #01: M = 1, N = 1 1 Output #01: 1 void printSpiralArray(int a[101][101], int M, int N){ /*M denotes the number of rows, N denotes the number of columns */ }

1) what is the output if fn(7) is called? fn(int v) { if(v==1||v==0)

return 1; elseif(v%2==0) return fn(v/2)+5; else return fn(v-1)+3; } 2) One car travels 72 mph when downwards, 63 mph on flat road, 56 mph uphills....and takes 4 hrs to reach to B.....and 4 hrs 40 mins while returning to B....Find distnace between A and B 3) 630 Students arranged so that each row contains 3 students lesser than previous row. How many rows cannt be possible? Options 5 6 7 8 4) f(n) { if(n>0) { f(--n) print n; f(--n); } O/p: 0 1 2 0 5) Sequential numbers are written on a board....if one number is removed then average becomes 290 / 9.....Find the missing number. 6) Which DS gives worst case of O(n logn) in Merge sort Options: LL, DLL, Array

1)

In an Amazon Fulfillment center, it takes a quality specialist 20 minutes to perform a damage-free check of one laptop. A temporary contractor takes 60 minutes to perform the same task. How many hours does it take a quality specialist and a temporary contractor together to perform a damage-free check of a batch of 160 laptops?

A) B) C) D)

135 hours 40 hours 50 hours 60 hours

E)

24 hours

2)

An space rocket travels around the Earth at a speed of approximately 18.5 miles per second. This approximate speed is how many miles per hour?

A) B) C) D) E)

1,080 1,160 64,800 66,600 3,996,000

3)

If x-4 is 6 more than y, then x+9 is how much more than y+5?

A) B) C) D) E)

10 12 14 17 18

4)

The first generation of the Galaxy 1 smartphone used to have a battery life of 20 hours. The new Galaxy 2 has smaller batteries with 40% less capacity. Also, the operating system of the Galaxy 2 consumes on average 50% less battery than the one of Galaxy 1. What is the battery life of Galaxy 2?

A) B) C) D) E)

24 hours 25 hours 26 hours 30 hours 36 hours

5)

Exactly 1/5 of the clients who entered Mike's shop yesterday were women. If exactly one third of the women were blonde, what is the minimum possible number of clients that entered the shop yesterday?

A) B) C) D)

5 10 15 20

E)

30

6)

Amazon.it had 140 thousand visits on Friday, including new and returning visitors. Statistics show that for 5 new visitors there were 3 returning visitors (ratio of 5:3). What was the difference between new visitors and returning visitors on Friday?

A) B) C) D) E)

15 thousand 25 thousand 35 thousand 55 thousand 75 thousand

7)

Amazon is negotiating with a carrier (SEUR) that will ship products from Amazon's wharehouse in Madrid to clients within the same city. SEUR charges Amazon per shipment based on the DISTANCE between Amazon's wharehouse to the client's address - 2 fixed for the first 2 kilometers and 0.5 per additional kilometer (measured by the meter, not by who le kilometers) for each delivery within a given city. 20% of clients live within 2 kilometers of Amazons wharehouse in Madrid - on average they live 1 km away. If all Amazons clients in Madrid live on average 4.5 kilometers away from Amazon's wharehouse, what is the estimated average shipping cost per delivery in Madrid, with SEUR?

A) B) C) D) E)

2.25 2.5 3.0 3.35 3.68

8)

A supplier of Amazon increases the price of a Book Cooking for Children) by 30% from last year and Amazon has planned to acquire additional stock with total (cost) value of 10,5% higher than last years stock acquisition. , By what % should Amazon reduce the quantity of Cooking for Children books that will buys,with regards to last year?

A) B) C) D) E) 9)

19.5% 12% 8% 15% 6.66%

There are ONLY 3 brands of video consoles (A, B and C). In 2010 A and B together represented 50% of units sold. C sold 3 million more units than A. Also, C sold 2.5 times the same units sold by B. If all video consoles had the same price of 300, what was the total video console market value in 2010?

A) B) C) D) E) 10)

1.5 billion 3 billion 4.5 billion 6 billion 7.5 billion

Three years ago, a son was 25 years younger than his father. At present the father is 6 times as old as the son. How old will the son be three years from now?

A) B) C) D) E)

5 9 1 8 11

11) Of the all employees that Amazon has in the UK, 1/3 are web developers. If the web developer staff were to be reduced by 1/3, what percent of the total number of the remaining employees would then be web developers?

A) B) C) D) E) 12)

33% 20% 25% 9% 66%

Social network AmazonLovers.com has just been launched. The daily evolution of number of visits follows a given algorithm. In the first five days, the number of visits evolves as detailed below. If the same algorithm continues to apply, what is the number of visits you would expect on day 6? 0. 1.3....7.15.___

A) B) C) D) E) 13)

22 39 31 105 225

If Luxembourg has on average 30 minutes of sunlight less than Spain and Spain has on average 5/6 times the hours of sunshine of Morocco. Knowing that Morocco has 12 hours of sunshine per day, how many hours of Sunshine has Luxembourg?

A)

8 hours and a half

B) C) D) E) 14)

9 hours and a half 10 hours 10 hours and a half 11 hours

A website sells only one model of shoes, with a acquisition cost of 18 for a pair of shoes. The site adds 9 on top of costs to determine the price at which to sell the shoes. What profit margin (as % of price) does the site obtain, assuming it has no additional costs?

A) B) C) D) E) 15)

33% 38% 45% 50% 66%

Greg was both 13th highest and 13th lowest in a chicken wing eating contest. How many people were in the contest? Note: No participant was disqualified and all participants were ranked

A) B) C) D) E) 16)

29 24 26 25 27

The Mobile section of the Amazon website received 30 million unique visits in 2010. 16 million unique visitors bought handsets, 12 million bought accessories and 10 million only visited the site but did not buy. What percentage of unique visitors THAT BOUGHT HANDSETS also bought accessories in 2010? Note: In the Mobile section, no products other than handsets and accessories are sold. Note: You are asked to calculate the attachment ratio of accessories in handsets, which means the % of users that buy handsets and also buy an accessory

A) B) C) D) E)

0% 12.5% 25.0% 50.0% 62.5%

17) At Fabio's ecommerce website, a TV is for sale for 50. Fabio decides to increase the price by 20% during Christmas. After Christmas, no unit of the product has been sold. Fabio decides

to discount the price of the product by 15% from the price in Christmas. What is the current price of the product?

A) B) C) D) E) 18)

49 51 52.2 52.5 53

A truck going from Luxembourg to Madrid traveled the first 12 hours of his journey at 40 mph and the remaining 8 hours of his journey at 80 mph. What is his average speed for the entire journey?

A) B) C) D) E) 19)

60 mph 54 mph 53.33 mph 56 mph 66.67 mph

Peter can develop a web page in 12 hours, and Tim can develop the same web page in 8 hours. Peter starts alone the job at 9 a.m., and stops working at 3 p.m. still alone. If Tim, alone too, starts working at 4 p.m. to complete Peters job, at what time is the job finished?

A) B) C) D) E) 20)

6 p.m. 7 p.m. 8 p.m. 10 p.m. 12p.m.

A truck transporting 3D flat TVs from Luxembourg to Marseille is half full. The truck stops in Paris and adds another 9 TVs of the same model and now the truck has only 1/8 of capacity free. What is the capacity (in number of TVs) that the truck could carry?

A) B) C) D) E)

24 26 27 30 32

Programs:
1. Print the first character in a given string that does not repeat. 2. In a given array of integers, print the pair which has minimum difference ie, print a[i ] and a[j] such that abs(a[i]-a[j]) is minimum. 3. Linked list with English letter; bring the vowels at the beginning of the list (in order). 4. An array of integer. Print all possible triplet which represent the sides of a triangle. 5. Generate the next highest permutation. (iitg) 6. Print the character having longest run in an array of strings. Given n strings, if u concatenate all n string(not necessary in order, consider all permutations) what will be the character which occur continuously maximum number of times. e.g. abc, cdb, aabaa, bad. there if i concatenate aabaa with abc then a will consecutively occur maximum number of times i.e 3 times.. its a very beautiful question. (iitg) 7. Given an string str and substring subs, if matching substring is found on the str, return the index otherwise return -1; 8. Given top(x,y) and bottom(x,y) of two rectangles, find if two rectangles have some common area return 1 otherwise return 0; 9. Given set of coins {1, 3, 4 ,5 } find min number of coins required to get sum amount. 10. write code to find sum of two numbers stored as linked list.(LSB at last node) and head of each list is given. 11. write code to print elements on the path from root to leaf node having the maximum sum. 12. Find repeating characters in the string and print them in lexicographical order. eg- aaabccffd ans- acf 13. Delete Kth node from a linked list. 14. Rotate the given matrix by 90 degree. 15. Clone a directed graph. 16. Write functions to find whether 2 timerange overlap or are within range. 17. Finding all possible UNIQUE substings of and array of char. And displaying it in sorted order. 18. An array of int is given find out the next possible number using that array . eg. Array has 1 2 5 8 6 4 then the next no will be 1 4 2 5 6 8 i.e no num. is possible between given two no. using the ints in the array. 19. Clone a singly link list with an extra pointer in the struct the extra pointer points anywhere and the node doesnt have any value. i.e. node cannot be identified easily. 20. Create a double link list from a tree. 21. Remove extra spaces in a sentence...Keep only one space after each word. 22. Next possible integer e.g 2378 => 2387 23. Given an string str and substring subs, if matching substring is found on the str, return the index otherwise return -1; 24. Given top(x,y) and bottom(x,y) of two rectangles, find if two rectangles have some common area return 1 otherwise return 0; 25. Given set of coins {1, 3, 4 ,5 } find min number of coins required to get sum amount. 26. diameter of tree,

27. write routing problem: ie finding the shortest path for the rat to cheese in a maze 28. Next higher number with same number of set bits

Vous aimerez peut-être aussi