Amcat programming questions by questionsgems. Looking for some good amcat questions? Then you are at the right place here we provide you some good collection of amcat programming questions.

Also check- CTS Interview Questions / Appium Interview Questions

## Amcat Programming Questions Answers 2019

Q1. A is an empty stack. The following operations are done on it.PUSH(1)PUSH(2)POPPUSH(5)PUSH(6)POPWhat will the stack contain after these operations?a) 5 6b) 1 6c) 5 6d) 1 5Ans: dTo an Empty Stack A,PUSH(1): 1PUSH(2): 1 2POP: 1PUSH(5): 1 5PUSH(6): 1 5 6POP: 1 5By the end of all the operation, the elements remaining are 1 5.

Q2. What is implied by the argument of a function?a) The variables passed to it when it is calledb) The value it returns on executionc) The execution code inside itd) Its return typeAns: aThe variables that are passed as inputs to a function in a function call are called arguments.

Q3. In a sequential programming language, code statements are executed in which order?a) All are executed simultaneouslyb) From top to bottomc) From bottom to topd) None of theseAns: bIn a sequential programming language code statements are executed from top to bottom.

Q4. A pseudo-code is used. Assume that when two data-types are processed through an operator, the answer maintains the same data-type as the input data-types. Assume that all data-types have enough range to accommodate any number. If two different data-types are operated on, the result assumes the more expressive data-type.What will be the output of the following pseudo-code statements?Integer a = 456, b, c, d =10b = a/dc = a – bprint ca) 410b) 410.4c) 411.4d) 411Ans: da/d = 456/10 = 45.6 =45 ( input data type and the output must be same) c = 456 – 45 = 411

Q5. Geeta takes as input 2 integer numbers, a and b, whose value can be between 0 and 31. She stores them as 5 bit numbers. She writes the following code to process these numbers to produce a third number c à c = 2*(a – b)In how many minimum bits should Geeta store c?a) 6 bitsb) 7 bitsc) 8 bitsd) 9 bitsAns: bc = 2*(a – b)For lowest number, when a=0 and b=31 à c= 2*(0-31) = -62For highest number, when a=31 and b=0 à c= 2*(31-0) = 62Range= -62 to 62, so It will fit on (-64 to 63) i.e., 2^7Bits Required = 7

Q6. I have a problem to solve which takes as input a number n. The problem has a property that given the solution for (n-1), I can easily solve the problem for n. Which programming technique will I use to solve such a problem?a) Iterationb) Decision-makingc) Object Oriented Programmingd) RecursionAns: dRecursion means calling again and again. Therefore problem n can be solved with the solution n-1, by repeatedly calling it.

Q7. The memory space needed by an algorithm has a fixed part independent of the problem instance solved and a variable part which changes according to the problem instance solved. In general, which of these two is of prime concern to an algorithm designer?a) Fixed partb) Variable Partc) Product of fixed part and variable partd) None of theseAns: bVariable part, since it changes according to the problem instance solved.

Q8. Pankaj and Mythili were both asked to write the code to evaluate the following expression:a – b + c/(a-b) + (a-b)^2Pankaj writes the following code statements (Code A):print (a-b) + c/(a-b) + (a-b)*(a-b)Mythili writes the following code statements (Code B):d = (a-b)print d + c/d + d*dIf the time taken to load a value in a variable, for addition, multiplication or division between two operands is same, which of the following is true?a) Code A uses lesser memory and is slower than Code Bb) Code A uses lesser memory and is faster than Code Bc) Code A uses more memory and is faster than Code Bd) Code A uses more memory and is slower than Code BAns: aCode A uses lesser memory and it is slower than code B. Since code B uses another variable d it needs to have more memory than code A. But code B will execute faster.

Q9. A queue is implemented as a singly-linked-list for easy addition and deletion of elements. Each node has an element and a pointer to another node. Which node will point to empty/no location?a) Rearb) Frontc) Bothd) NoneAns: aThe new node will always be added at the rear end, so the new/empty location will be pointed by Rear end.

Q10. Q is an empty queue. The following operations are done on it:ADD 5ADD 7ADD 46DELETEADD 13DELETEDELETEADD 10What will be the content of Q after these operations? Front is marked by (F) and Rear is marked by (R).a) 10(R) 13(F)b) 5(R) 10(F)c) 13(R) 10(F)d) 10(R) 5(F)Ans: aQueue follows FIFO principle, so performing the FIFO operation the Front will be pointing to 13 and Rear will be pointing to 10.

## Amcat Programming Questions Answers For Wipro

Q1. An array contains the following elements in order: 7 6 12 30 18. Insertion sort is used to sort the array in ascending order. How many times will an insertion be made?a) 2b) 3c) 4d) 5Ans: aThe insertion is made twice. First insertion is inserting 6 before 7. Second insertion is inserting 18 between 12 and 30.

Q2. Ragu writes a program to find an element in the array A[5] with the following elements in order: 18 32 44 46 57. She runs the program to find a number X. X is found in the first iteration of binary search. What is the value of X?a) 44b) 18c) 46d) 32Ans: aThe array has 18 32 44 46 57 Binary search is performed only on sorted arrays. In this search the middle element is identified and if the element to be searched is lesser than the middle element then all the elements to the right of the middle value are neglected and again the middle value is obtained for the remaining elements. If the element to be searched is greater than the middle element then all the elements to the left of the middle value are neglected and again the middle value is obtained for the remaining elements. If the value is obtained in the first iteration itself, then the value should be the middle element of the array. Here the middle element is 44.

Q3. A stack is implemented as a linear array A[0…N-1]. Farhan writes the following functions for pushing an element E in to the stack.function PUSH( top, E, N ){if(X){top= top+1A[top] = E}else{print “Overflow”}return top}Fill in the condition Xa) top< Nb) top <N-1c) top > 0d) top > 1Ans: bThe array is 0,1,2,……,N-1. The maximum size of the array is N-1. To perform a PUSH operation, the stack should have free space. This is checked using the top pointer. If the top pointer is less than N1(maximum size) then PUSH operation can be done. If not the condition is called Stack Overflow. Hence X should be top<N-1.

Q4. A queue is implemented by a linear array of size 10 (and not as a circularly connected array). Front and Rear are represented as an index in the array. To add an element, the rear index is incremented and the element is added. To delete an element, the front index is incremented. The following operations are done on an empty queue.ADD 1; DELETE; ADD 2; ADD 3; ADD 4; DELETE, DELETEAfter this set of operations, what is the maximum capacity of the queue?a) 6b) 7c) 10d) None of theseAns: bThe maximum size of the queue is 10. For every DELETE operation the front pointer is incremented and the space becomes useless. Here, there are three DELETE operations. So, the front pointer is incremented by three spaces and these three spaces become useless. Hence 10-3=7. Only 7 spaces are available which the maximum size of the array is.

Q5. Riyaz has a book of tickets and wants to store ticket numbers in a data structure. New tickets are added to the end of the booklet. Ticket at the top of the stack is issued to the customer. Which data structure should Riyaz use to represent the ticket booklet?a) Queueb) Stackc) Arrayd) GraphAns: aTickets are added to the end and are removed from the top. This follows the logic of First In First Out. This logic can be represented using a queue data structure.

Q6. Which of the following data structures may give overflow error, even though the current number of elements in it is less than its size?a) Queue implemented in a linear arrayb) Queue implemented in a circularly connected arrayc) Stack implemented in a linear arrayd) None of theseAns: aIn a queue data structure implemented in a static linear array, for an enqueue operation the rear pointer is incremented. Similarly, for a dequeue operation the front pointer is incremented. When the front pointer is incremented, the memory space before front becomes useless. So even if the size is more the queue will end up showing an overflow error.

Q7. Number of possible ordered trees with 3 nodes A, B, C isa) 16b) 12c) 13d) 14Ans: b

Q8. Farhan writes a code to find the factorial of an inputted number. His code gives correct answers for some inputs and incorrect answers for others. What kind of error does his program have?a) Syntactical errorb) Run-time Errorc) Logical Errord) None of theseAns: cSyntactical Error and Run-time error will not give any output. Logical error is a bug in a program that causes it to operate incorrectly, but not to terminate abnormally. A logic error produces unintended or undesired output, although it may not immediately be recognized as such. The problem to the given question can be Integer overflow. If int is 32 bits, then the largest value it can represent But 13 factorial is x If it is 64-bit integer type such a long long, this can give up to 20 factorial.

Q9. As part of the maintenance work, you are entrusted with the work of rearranging the library books in a shelf in proper order, at the end of each day. The ideal choice will be Bubble Sorta) Insertion Sortb) Selection Sortc) Heap Sortd) NoneAns: bSorting of books in a library is an example of insertion sort. We pick a book and place it in its corresponding place as it is done in an insertion sort.

Q10. A hash table can store a maximum of 10 records. Currently there are records in locations 1, 3, 4, 7, 8, 9, 10. The probability of a new record going into location 2, with a hash function resolving collisions by linear probing isa) 0.6b) 0.1c) 0.2d) 0.5Ans: aThe probability is 6/10. Due to uniform distribution, the probability that the new record will be placed to any location X will be same for any X of (1,2,3,4,5,6,7,8,9,10) & will be equal to 1/10. Now if the hash function will try to place the new record in to any of the locations 1,7,8,9,10 the record will be redirected to location 2 due to collision resolution by linear probing. And if hash function will try to place the new record into 2, since location 2 is available, the record will go to location 2. So The probability of going new record into location 2, will be same as probability that the output of hash function is any one of (1,2,7,8,9,10) out of (1,2,3,4,5,6,7,8,9,10) where each location is equally likely. So the chances will be 6/10 i.e., 0.6

Conclusion:These are amcat programming questions. I hope you guys like it. if you have any question or suggestion just comment below or contact us.Thanks