**AMCAT Technical** **Questions and Answers**

**Q1. A new language has 15 possible letters, 8 different kinds of punctuation marks – and a blank character. Rahul wants to create two data types, first one which could store the letters of the language and a second one which could store any character in the language. The number of bits required to store these two data-types willrespectively be:**

A. 3 and 4

B. 4 and 3

C. 4 and 5

D. 3 and 5

Ans. C

**Q2. A code takes the following code steps (equivalently time unit) to execute:5 n3 + 6n2 + 1. Which of the following is not true about the time complexity of the program?**

A. It has a time complexity of O(n3)

B. It has a time complexity of O(n4)

C. It has a time complexity of O(n2)

D. It has a time complexity of THETA(n3)

Ans. C

*Must See: AMCAT Study Materials, Preparation Guide*

**Q3. We have two programs. We know that the first has a time complexity O(n2), while the second has a complexity &omega(n2).For sufficiently large n, which of the following cannot be true?**

A. Both codes have same complexity

B. The first code has higher time complexity than the second

C. The second code has lower time complexity than the first code.

D. Both codes are the same.

Ans. B

**Q4. Parul takes as input two numbers: a and b. a and b can take integer values between 0 and 255. She stores a, b and c as 1-byte data type. She writes thefollowing code statement to process a and b and put the result in c.c = a + 2*bTo her surprise her program gives the right output with some input values of a and b, while gives an erroneous answer for others. For which of the following inputs will it give a wrong answer?**

A. a = 10 b = 200

B. a = 200 b = 10

C. a = 50 b = 100

D. a = 100 b = 50

Ans. A

**Q5. Prashant takes as input 2 integer numbers, a and b, whose value can bebetween 0 and 127. He stores them as 7 bit numbers. He writes the following code to process these numbers to produce a third number c.c = a – bIn how many minimum bits should Prashant store c?**

A. 6 bits

B. 7 bits

C. 8 bits

D. 9 bits

Ans. C

**Q6. Ankita takes as input 2 integer numbers, a and b, whose value can be between 0 and 31. He stores them as 5 bit numbers. He writes the following code to process these numbers to produce a third number c.c = 2*(a – b)In how many minimum bits should Ankita store c?**

A. 6 bits

B. 7 bits

C. 8 bits

D. 9 bits

Ans. B

**Q7. A character in new programming language is stored in 2 bytes. A string is represented as an array of characters. A word is stored as a string. Each byte in the memory has an address. The word “Mahatma Gandhi” is stored in the memory with starting address 456. The letter ‘d’ will be at which memory address?**

A. 468

B. 480

C. 478

D. 467

Ans. C

**Q8. A program is compiled by Tarun on his machine. Whether it will run on a different computer will depend upon:**A. Operating system on the computer

B. Hardware configuration of the computer

C. Both operating system and hardware configuration

D. The language of the program

Ans. B

**Q9. Shahaana has a 10,000 line code. She is trying to debug it. She knows there is a logical error in the first 25 lines of the code. Which of the following will be an efficient way of debugging:**

A. Compile the whole code and step into it line by line

B. Use an interpreter on the first 25 lines.

C. Compile the whole code and run it

D. None of these

Ans. B

**Q10. Farhan writes a code to find the factorial of an inputted number. His code gives correct answer for some inputs and incorrect answers for others. What kind of error does his program have?**

A. Syntactical error

B. Run-time Error

C. Logical Error

D. None of these

Ans. C

**Q11. Reshama is debugging a piece of code which takes several iterations of modifying and executing code, while Mohammad has to deliver a product to the customer, which the customer will run multiple times. Reshama wants her debug cycle to take minimum possible time, while Mohammad wants that his products run time is minimum. What tools should Reshama and Mohammad respectively use on their code?**

A. Compiler, Interpreter

B. Interpreter, Compiler

C. Compiler, Compiler

D. Interpreter, Interpreter

Ans. B

**Q12. Gautam writes a program to run on a Motorola processor on his Pentium computer. He wants to see how the program will execute on the Motorola processor using his Pentium machine. What tool will he use?**

A. Compiler

B. Interpreter

C. Assembler

D. Simulator

Ans. D

**Q13. Consider the following code:**function modify(y,z)

{

y = y + 1;

z = z + 1;

return y – z

}

function calculate( )

{

integer a = 5, b = 10, c

c = modify(a, b);

print a

print space

print c

}

Assume that a and b were passed by value. What will be the output on executing

function calculate( )?

A. 11 -5

B. 10 -5

C. 6 -5

D. 5 -5

Ans. D

**Q14. Consider the following code:**function modify(b,a)

{

return a – b

}

function calculate( )

{

integer a = 5, b = 12, c

c = modify(a, b);

print c

}

Assume that a and b were passed by reference. What will be the output of the

program on executing function calculate( ) ?

A. 7

B. -7

C. Error

D. 8

Ans. A

**Q15. Consider the following code:**function modify(y,z)

{

y = y + 1

z = z + 1

return y – z

}

function calculate( )

{

integer a = 12, b = 20, c

c = modify(a, b);

print a

print space

print c

}

Assume that a and b were passed by reference. What will be the output of the

function calculate( ) ?

A. 12 -8

B. 13 -8

C. 12 8

D. 13 8

Ans. B

**Q16. Afzal writes a piece of code, where a set of three lines occur around 10 times in different parts of the program. What programming concept can he use to shorten his program code length?**

A. Use for loops

B. Use functions

C. Use arrays

D. Use classes

Ans. B

**Q17. Geetika writes a piece of code, where a set of eight lines occur around 10 times in different parts of the program (Code A). She passes on the code to Deva. Deva puts the set of eight lines in a function definition and calls them at the 10 points in the program (Code B). Which code will run faster using an interpreter?**

A. Code A

B. Code B

C. Code A and Code B will run with the same speed

D. None of these

Ans. A

**Q18. There is an array of size n initialized with 0. Akanksha has to write a code which inserts the value 3k at position 3k in the array, where k=0,1…(till possible).Akanksha writes an efficient code to do so. What is the time complexity of her code?**

A. THETA(n^2)

B. THETA(n)

C. THETA(log3(n))

D. THETA(3n)

Ans. B

**Q19. There is a new data-type which can take as values natural numbers between (and including) 0 and 25. How many minimum bits are required to store this datatype.**

A. 4

B. 5

C. 1

D. 3

Ans. B

**Q20. A data type is stored as an 6 bit signed integer. Which of the following cannot be represented by this data type?**

A. -12

B. 0

C. 32

D. 18

Ans. C

**Q21. Rajni wants to create a data-type for the number of books in her book case. Her shelf can accommodate a maximum of 75 books. She allocates 7 bits to the datatype. Later another shelf is added to her book-case. She realizes that she can still use the same data-type for storing the number of books in her book-case. What is the maximum possible capacity of her new added shelf?**

A. 52

B. 127

C. 53

D. 75

Ans. A

**Q22. 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?**

A. THETA(n^2)

B. THETA(n)

C. THETA(n1/2)

D. THETA(log(n))

Ans. B

**Q23. Ravi has to add an strictly upper triangular (no elements at diagonal) and a strictly lower triangular square matrix (no elements at diagonal) and put the result in a third matrix. What is the time complexity of Ravi’s algorithm? Assume that storing a value in a memory space takes negligible time, while each addition between values takes the dominating amount of time.**

A. THETA(n^2)

B. THETA(n)

C. THETA(1)

D. None of these

Ans. C

**Q24. We have two 100X3 (rowsXcolumn) matrices containing mid-term exam marks and end-term exam marks of 100 students. Each row refers to a particular student, while columns refer to marks in English, Social Sciences and Maths. The end-term and mid-term marks of each student in each subject have to be added to get his total score in each subject, to be put in a third matrix (100X3). Parinidhi writes a code (Code A), where the outer loop iterates over the rows, while the inner loop iterates over the columns. Shashi writes a code (Code B), where the outer loop iterates over the columns, while the inner loop iterates over rows. Which of the following is true with regard to their code ignoring any caching or memory storage effects?**

A. Code A is faster than Code B

B. Code B is faster than Code A

C. Code A and Code B will run in the same amount of time

D. The comparison between the speed of the codes cannot be made.

Ans. B

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

A. insertion sort

B. heap sort

C. quick sort

D. bubble sort

Ans. D

**Q26. 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?**

A. insertion sort

B. selection sort

C. heap sort

D. quick sort

Ans. B

**Q27. A language has 28 different letters in total. Each word in the language is composed of maximum 7 letters. You want to create a data-type to store a word of this language. You decide to store the word as an array of letters. How many bits will you assign to the data-type to be able to store all kinds of words of the language.**

A. 7

B. 35

C. 28

D. 196

Ans. B

**Q28. A 10-bit unsigned integer has the following range:**

A. 0 to 1000

B. 0 to 1024

C. 1 to 1025

D. 0 to 1023

Ans. D

**Q29. A sort which uses the binary tree concept such that any number in the tree is larger than all the numbers in the subtree below it is called**

A. selection sort

B. insertion sort

C. heap sort

D. quick sort

Ans. C

**Q30. The time complexity of code A is THETA(n), while for Code B it isTHETA(log(n)). Which of the following is true for sufficiently large n?**

A. Both code have the same time complexity

B. Code A has higher time complexity

C. Code B has higher time complexity

D. No comparison can be made between the time complexity of the two codes.

Ans. B

**Q31. Rajini is given an efficient code for summing two nXn matrices and putting the result in a third matrix. She is asked to find it’s time complexity. She realizes that the number of iterations required is more than n. What can she claim with regard to the complexity of the code?**

A. It is O(n)

B. It is O(n2)

C. It is THETA(n)

D. It is &omega(n)

Ans. D

**Q32. Gautam is given two codes, A and B, to solve a problem, which have complexity THETA(n) and THETA(n2) respectively. His client wants to solve a problem of size k, which Gautam does not know. Which code will Gautam deliver to the client, so that the execution is faster?**

A. Code A

B. Code B

C. Gautam cannot determine

D. Both codes have the same execution time, so deliver any.

Ans. C

**Q33. Surbhi is given two codes, A and B, to solve a problem, which have complexity O(n3) and &omega(n4) respectively. Her client wants to solve a problem of size k, which is sufficiently large. Which code will Surbhi deliver to the client, so that the execution is faster?**

A. Code A

B. Code B

C. Surbhi cannot determine

D. Both codes have the same execution time, so deliver any.

Ans. A

**Q34. Vibhu is given two codes, A and B, to solve a problem, which have complexity O(n4) and &omega(n3) respectively. Her client wants to solve a problem of size k, which is sufficiently large. Which code will Gautam deliver to the client, so that the execution is faster?**

A. Code A

B. Code B

C. Vibhu cannot determine

D. Both codes have the same execution time, so deliver any.

Ans. C

**Q35. What does the following function do?**

function operation (int a, int b)

{

if (a < b)

{ return operation(b, a) }

else

{ return a }

}

A. Returns the max of (a,b)

B. Returns the min of (a,b)

C. Loops forever

D. Always returns the second parameter

Ans. A

**Q36. What does the following function do?**

function operation (int a, int b)

{

if (a > b)

{ return operation(b, a) }

else

{ return a; }

}

A. Always returns the first parameter

B. Returns the min of (a,b)

C. Returns the max of (a,b)

D. Loops forever

Ans. B

**Q37.** function g(int n)

{

if (n > 0) return 1;

else return -1;

}

function f(int a, int b)

{

if (a > b) return g(b-a);

if (a < b) return g(a-b);

return 0;

}**If f(a,b) is called, what is returned?**

A. Always -1

B. 1 if a > b, -1 if a < b, 0 otherwise C. -1 if a > b, 1 if a < b, 0 otherwise

D. 0 if a equals b, -1 otherwise

Ans. D

**Q38.** function g(int n)

{

if (n > 0) return 1;

else return -1;

}

function f(int a, int b)

{

if (a > b) return g(a-b);

if (a < b) return g(b-a);

return 0;

}**If f(a,b) is called, what is returned?**

A. 1 if a > b, -1 if a < b, 0 otherwise B. Always +1 C. 0 if a equals b, +1 otherwise D. -1 if a > b, 1 if a < b, 0 otherwise

Ans. C

**Q39.** function g(int n)

{

if (n > 0) return 1;

else return -1;

}

function f(int a, int b)

{

if (a > b) return g(a-b);

if (a < b) return g(-b+a);

return 0;

}**If f(a,b) is called, what is returned?**

A. Always +1

B. 1 if a > b, -1 if a < b, 0 otherwise C. -1 if a > b, 1 if a < b, 0 otherwise

D. 0 if a equals b, -1 otherwise

Ans. B

**Q40.** function g(int n)

{

if (n > 0) return 1;

else return -1;

}

function f(int a, int b)

{

if (a > b) return g(b-a);

if (a < b) return g(-a+b);

return 0;

}**If f(a,b) is called, what is returned?**

A. Always +1

B. -1 if a > b, 1 if a < b, 0 otherwise C. 1 if a > b, -1 if a < b, 0 otherwise

D. 0 if a equals b, -1 otherwise

Ans. B

**Q41. Consider the following code:**

for i= m to n increment 2

{ print “Hello!” }**Assuming m < n and exactly one of (m,n) is even, how many times will Hello be printed?**

A. (n – m + 1)/2

B. 1 + (n – m)/2

C. 1 + (n – m)/2 if m is even, (n – m + 1)/2 if m is odd

D. (n – m + 1)/2 if m is even, 1 + (n – m)/2 if m is odd

Ans. A

**Q42. Consider the following code:**

for i= m to n increment 2

{ print “Hello!” }**Assuming m < n and (m,n) are either both even or both odd, How many times will Hello be printed?**

A. (n – m + 1)/2

B. 1 + (n – m)/2

C. 1 + (n – m)/2 if m is even, (n – m + 1)/2 if m is odd

D. (n – m + 1)/2 if m is even, 1 + (n – m)/2 if m is odd

Ans. B

**Q43. Assuming n > 2, What value does the following function compute for odd n?**

function f (int n)

{

if (n equals 1) { return 1 }

if (n equals 2) { return f(n-1) + n/2 }

return f(n-2) + n;

}

A. 1 + 2 + 3 + 4 + … + n

B. 1 + 3 + 5 + 7 + … + n

C. n/2 + (1 + 3 + 5 + 7 + … + n)

D. 1 + (1 + 3 + 5 + 7 + … + n)

Ans. B

**Q44. Assuming n > 2, What value does the following function compute for even n?**

int f (int n)

{

if (n equals 1) { return 1 }

if (n equals 2) { return f(n-1) + n/2 }

return f(n-2) + n

}

A. 1 + 2 + 3 + 4 + … + n

B. 1 + (2 + 4 + 6 + 8 + … + n)

C. 1 + n/2 + (4 + 6 + 8 + … + n)

D. 2 + 4 + 6 + 8 + … + n

Ans. D

**Q45. The for loop is equivalent to a while loop when**

A. There is no initialization expression

B. There is no increment expression

C. A and B combined are true

D. It is never equivalent

Ans. C

**Q46. How will 47 be stored as an unsigned 8-bit binary number?**

A. 10111101

B. 00101111

C. 10111000

D. 00101101

Ans. B

**Q47. An integer X is saved as an unsigned 8-bit number, 00001011.What is X?**

A. 22

B. 11

C. 10

D. None of these

Ans. B

**Q48. A variable cannot be used…**

A. Before it is declared

B. After it is declared

C. In the function it is declared in

D. Can always be used

Ans. A

**Q49. What is implied by the argument of a function?**

A. The variables passed to it when it is called

B. The value it returns on execution

C. The execution code inside it

D. Its return type

Ans. A

**Q50. Which of the following is true about comments?**

A. They are executed only once.

B. They are not executed

C. A good program does not contain them

D. They increase program execution time.

Ans. B

**Q51. Neelam wants to share her code with a colleague, who may modify it. Thus she wants to include the date of the program creation, the author and other information with the program. What component should she use?**

A. Header files

B. Iteration

C. Comments

D. Preprocessor directive

Ans. C

**Q52. Shashi writes a program in C++ and passes it on to Pankaj. Pankaj does some indentation in some statements of the code. What will this lead to?**

A. Faster Execution

B. Lower memory requirement

C. Correction of errors

D. Better readability

Ans. D

**Q53. 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 Awhile Shashi defines the three quantities as:integer a, b, c // Code B**

Which is a better programming practice and why?

A. Code B is better because variable names are shorter

B. Code A is better because the variable names are understandable and nonconfusing

C. Code A will run correctly, while Code B will give an error.

D. Code B will run correctly, while Code A will give an error.

Ans. B

**Q54. For solving a problem, which of these is the first step in developing a working program for it?**

A. Writing the program in the programming language

B. Writing a step-by-step algorithm to solve the problem.

C. Compiling the libraries required.

D. Code debugging

Ans. B

**Q55. A robust program has which one of the following features?**

A. It runs correctly on some inputs

B. It is robust to hardware damage

C. It can handle incorrect input data or data types.

D. None of these

Ans. C

**Q56. 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?**

A. Iteration

B. Decision-making

C. Recursion

D. None of these

Ans. B

**Q57. 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?**

A. Top-down Approach

B. Bottom-Up Approach

C. Procedural Programming

D. None of these

Ans. A

**Q58. The time complexity of linear search algorithm over an array of n elements is**

A. O (log2 n)

B. O (n)

C. O (n log2 n )

D. O (n2)

Ans. B

**Q59. Rajesh implements queue as a singly-linked linked list. The queue has n elements. The time complexity to ADD a new element to the queue:**

A. O (1)

B. O (log2 n)

C. O (n)

D. O (n log2 n )

Ans. A

**Q60. The time required to insert an element in a stack with linked listimplementation is**

A. O (1)

B. O (log2 n)

C. O (n)

D. O (n log2 n )

Ans. A

**Q61. In the following sorting procedures, which one will be the slowest for any given array?**

A. Quick sort

B. Heap sort

C. Merge Sort

D. Bubble sort

Ans. D

**Q62. 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?**

A. O(1)

B. O(n2)

C. O(log n)

D. O(n)

Ans. A

**Q63. Every element of a data structure has an address and a key associated with it.A search mechanism deals with two or more values assigned to the same address byusing the key. What is this search mechanism?**

A. Linear Search

B. Binary search

C. Hash Coded Search

D. None of these

Ans. C

**Q64. The order of magnitude of the worst case performance of a hash coded search (over N elements) is**

A. N

B. N log2 N

C. log2 N

D. not dependent upon N

Ans. A

**Q65. Sakshi writes a code in a high-level programming language on a Pentium-III machine, which she wants to execute on a Motorola chip. What of the following will she run on the code?**

A. An interpreter

B. A compiler

C. A cross-compiler

D. Linker

Ans. C