## Amcat Previous Years Question Paper Computer Programming Question Bank

**Amcat-Q1: There are two matrices A and B of size nXn. The data in both these matrices resides only at positions where both the indices are a perfect square. Rest all positions have 0 as the data. Manuj has available a third matrix initialized with 0's at all positions. He writes an efficient code to put the sum of A and B in C. What is the time complexity of Manuj's program?**

Op 1 : O(n^2)

Op 2 : O(n)

Op 3 : O(n1/2)

Op 4 : O(log(n))

**Amcat-Q2: Ravi and Rupali are asked to write a program to sum the rows of a 2X2 matrices stored in the array A. Ravi writes the following code (Code A): for n = 0 to 1 sumRow1[n] = A[n][1] + A[n][2] end Rupali writes the following code (Code B): sumRow1[0] = A[0][1] + A[0][2] sumRow1[1] = A[1][1] + A[1][2] Comment upon these codes (Assume no loop-unrolling done by compiler):**

Op 1 : Code A will execute faster than Code B.

Op 2 : Code B will execute faster than Code A

Op 3 : Code A is logically incorrect.

Op 4 : Code B is logically incorrect.

Answer : 2

**Amcat-Q3: Here is an infix notation: ((A+B)*C-(D-E)) ^ (F+G) Choose the correct postfix notation of the above from the given options.**

A) AB+CD*E--FG+^

B) AB+C*DE--FG+^

C) AB+C*DE-FG-+^

D) A+BC*DE-FG-+^

Answer : B

**Amcat-Q4: Tarun writes an efficient program to add two upper triangular 10X10 matrices (elements on diagonal retained). How many total additions will his program make?**

Op 1 : 100

Op 2 : 55

Op 3 : 25

Op 4 : 10

Answer : op 2

**Amcat-Q5:**

(Image taken while taking AMCAT test)

**Amcat-Q6: Shreya writes the following program:**

**integer i = 0, j ;**

**while ( i < 2 )**

**{ j = 0;**

**while ( j <= 3*i )**

**{ print j print blank space j = j + 3 }**

**print end-of-line takes the cursor to the next line i = i + 1 }**

**What will be the output of the program?**

Op 1 :

0

0 3

Op 2 :

0 3

0 3 6

Op 3 :

0

0 3 6

0 3 6 9

Op 4 :

0 3 6

0 3 6 9

0 3 6 9 12

Answer : op 1

**Amcat-Q7: Bhavya wants to make a program to print the sum of all perfect squares, where the value of the squares go from 0 to 50. She writes the following program:**

**integer i = 1, a // statement 1**

**integer sum = 0**

**while ( a < 50 ) // statement 2**

**{**

**sum = sum + a // statement 3**

**i = i + 1**

**a = ( i * i ); // statement 4**

**}**

**print sum**

**Does this program have an error? If yes, which one statement will you modify to correct the program?**

Op 1 : Statement 1

Op 2 : Statement 2

Op 3 : Statement 3

Op 4 : Statement 4

Op 5 : No error

Answer : op 1

**Amcat-Q8: Shashi wants to make a program to print the sum of the first 10 multiples of 5. She writes the following program, where statement 5 is missing:**

**integer i = 0**

**integer sum = 0**

**while ( i <= 50 )**

**{**

**sum = sum + i**

**-- MISSING STATEMENT 5 --**

**}**

**print sum**

**Which of the following will you use for statement 5?**

Op 1 : i = 5

Op 2 : i = 5 * i

Op 3 : i = i + 1

Op 4 : i = i + 5

Answer : op 4

**Amcat-Q9:. Smriti wants to make a program to print the sum of square of the first 5 whole numbers (0...4). She writes the following program:**

**integer i = 0 // statement 1**

**integer sum = 0 // statement 2**

**while ( i < 5 ) // statement 3**

**{**

**sum = i*i // statement 4**

**i = i + 1 // statement 5**

**}**

**print sum // statement 6**

**Is her program correct? If not, which statement will you modify to correct it?**

Op 1 : No error, the program is correct.

Op 2 : Statement 1

Op 3 : Statement 4

Op 4 : statement 6

Answer : op 4

**Amcat-Q10: A sorting algorithm iteratively traverses through a list to exchange the first element with any element less than it. It then repeats with a new first element. What is this sorting algorithm called?**

Op 1 : insertion sort

Op 2 : selection sort

Op 3 : heap sort

Op 4 : quick sort

Answer : op 2

**Amcat-Q11: A sorting algorithm traverses through a list, comparing adjacent elements and switching them under certain conditions. What is this sorting algorithm called?**

Op 1 : insertion sort

Op 2 : heap sort

Op 3 : quick sort

Op 4 : bubble sort

Answer : op 4

**Amcat-Q12:**

**(Image taken while taking AMCAT test)**

**Amcat-Q13: Which of the following method may or may not have its methods implementation?**

a)Interface

b)abstract class

c)generic class

d)anonymous class

Answer : b

**Amcat-Q14: Pankaj stores n data elements in a hash table. He is able to get the best efficiency achievable by a hash table. What is the time complexity of accessing any element from this hash table?**

Op 1 : O(1)

Op 2 : O(n2)

Op 3 : O(log n)

Op 4 : O(n)

Answer : op 1

**Amcat-Q15: The time complexity of linear search algorithm over an array of n elements is**

Op 1 : O (log2 n)

Op 2 : O (n)

Op 3 : O (n log2 n )

Op 4 : O (n2)

Answer : op 2

**Amcat-Q16: To solve a problem, it is broken in to a sequence of smaller sub-problems, till a stage that the sub-problem can be easily solved. What is this design approach called?**

Op 1 : Top-down Approach

Op 2 : Bottom-Up Approach

Op 3 : Procedural Programming

Op 4 : None of these

Answer : op 1

**Amcat-Q17: Tarun wants to write a code to divide two numbers. He wants to warn the user and terminate the program if he or she enters 0 as the divisor. Which programming construct can he use to do this?**

Op 1 : Iteration

Op 2 : Decision-making

Op 3 : Recursion

Op 4 : None of these

Answer : op 2

**Amcat-Q18: Zenab and Shashi independently write a program to find the the mass of one mole of water, which includes mass of hydrogen and oxygen. Zenab defines the variables:**

**integer hydrogen, oxygen, water // Code A**

**while Shashi defines the three quantities as:**

**integer a, b, c // Code B**

**Which is a better programming practice and why?**

Op 1 : Code B is better because variable names are shorter

Op 2 : Code A is better because the variable names are understandable and non-confusing

Op 3 : Code A will run correctly, while Code B will give an error.

Op 4 : Code B will run correctly, while Code A will give an error.

Answer : op 2

**Amcat-Q19: Raju 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 Raju use to represent the ticket booklet?**

a) Queue

b) Stack

c) Array

d) Graph

Answer : a

**Amcat-Q20: A queue is implemented as a (singly linked) linked-list for easy addition and deletion of elements. Each node has an element and pointer to another node. Which node will point to empty/no location?**

a) Front

b) Rear

c) Both

d) None of these

Answer : b

**Amcat-Q21: There are two loops which are nested. This implies which one of the following?**

Op 1 : Two loop, one after the other

Op 2 : Two loops, one inside the others

Op 3 : One loop with two different iteration counts

Op 4 : Two loops with the same iteration count

Answer : op 2

**Amcat-Q22: The construct "if (condition) then A else B" is for which of the following purposes?**

Op 1 : Decision-Making

Op 2 : Iteration

Op 3 : Recursion

Op 4 : Object Oriented Programming

Answer : op 1

**Amcat-Q23: Consider the statement**

**while (a < 10.0) { a = a*a }**

**Assuming a is positive, for what value of a will this code statement result in an infinite loop?**

Op 1 : a < 1.0

Op 2 : a < sqrt(10)

Op 3 : a > sqrt(10)

Op 4 : a = 0

Answer : op 2

**Amcat-Q24: which is not a data type ?**

A) boolean

B) array

C) float

D) char

Answer : B

Related Pages:

- Amcat Previous Years Question Paper with answers Question Bank Quants.
- Amcat Previous Years Question Paper with answers Question Bank English Comprehension.
- Amcat Previous Years Question Paper with answers Question Bank Verbal Ability.
- Amcat Previous Years Question Paper with answers Question Bank Computer Programming.
- Amcat Previous Years Question Paper with answers Question Bank Computer Science.
- Amcat Previous Years Question Paper with answers Question Bank Automata.

## No comments:

## Post a Comment