Nothing Special   »   [go: up one dir, main page]

Amcat Programming Questions With Answers

Download as pdf or txt
Download as pdf or txt
You are on page 1of 39

11/28/2014 comp.

htm

Ques 1 : Choose the correct answer
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 data­type.
Option 1 : 4 Option 2 : 5 Option 3 : 1 Option 4 : 3

Ques 2 : Choose the correct answer
A data type is stored as an 6 bit signed integer. Which of the following cannot be represented
by this data type?
Option 1 : ­12 Option 2 : 0 Option 3 : 32 Option 4 : 18

Ques 3 : Choose the correct answer
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.
Option 1 : 7 Option 2 : 35 Option 3 : 28 Option 4 : 196

Ques 4 : Choose the correct answer
A 10­bit unsigned integer has the following range:
Option 4 : 0 to
Option 1 : 0 to 1000 Option 2 : 0 to 1024 Option 3 : 1 to 1025
1023

Ques 5 : Choose the correct answer
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 data­type. 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?
Option 1 : 52 Option 2 : 127 Option 3 : 53 Option 4 : 75

Ques 6 : Choose the correct answer
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 will respectively be:
Option 1 : 3 and 4 Option 2 : 4 and 3 Option 3 : 4 and 5 Option 4 : 3 and 5

Ques 7 : Choose the correct answer
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 the following code statement to process a
and b and put the result in c.

c = a + 2*b

To her surprise her program gives the right output with some input values of a and b, while
file:///C:/Users/snovaspace2/Downloads/comp.htm 1/39
11/28/2014 comp.htm

gives an erroneous answer for others. For which of the following inputs will it give a wrong
answer?
Option 1 : a = 10 b = Option 2 : a = 200 b = Option 4 : a = 100
Option 3 : a = 50 b = 100
200 10 b = 50

Ques 8 : Choose the correct answer
Prashant takes as input 2 integer numbers, a and b, whose value can be between 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 ­ b

In how many minimum bits should Prashant store c?
Option 1 : 6 bits Option 2 : 7 bits Option 3 : 8 bits Option 4 : 9 bits

Ques 9 : Choose the correct answer
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?
Option 1 : 6 bits Option 2 : 7 bits Option 3 : 8 bits Option 4 : 9 bits

Ques 10 : Choose the correct answer
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?
Option 1 : 468 Option 2 : 480 Option 3 : 478 Option 4 : 467

Ques 11 : Choose the correct answer
Stuti is making a questionnaire of True­false questions. She wants to define a data­type which
stores the response of the candidate for the question. What is the most­suited data type for this
purpose?
Option 4 :
Option 1 : integer Option 2 : boolean Option 3 : float
character

Ques 12 : Choose the correct answer:
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 =10 
b = a/d
file:///C:/Users/snovaspace2/Downloads/comp.htm 2/39
11/28/2014 comp.htm

c = a ­ b
print c
Option 1 : 410 Option 2 : 410.4 Option 3 : 411.4 Option 4 : 411

Ques 13 : Choose the correct answer:
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.
// in pseudo code refers to comment
What will be the output of the following pseudo­code statements:
integer a = 984,   b, c, d =10 
print remainder(a,d) // remainder when a is divided by d
a = a/d
print remainder(a,d) // remainder when a is divided by d
Option 1 : 48 Option 2 : Error Option 3 : 84 Option 4 : 44

Ques 14 : Choose the correct answer:
Assume the following precedence (high to low). Operators in the same row have the same
precedence:
(.)
*   /   
+   ­
AND
OR
For operators with equal precedence, the precedence is from left­to­right in expression.
What will be the output of the following code statements?

integer a = 50, b = 25, c = 0
print ( a > 45 OR b > 50 AND c > 10 )
Option 1 : 1 Option 2 : 0 Option 3 : ­1 Option 4 : 10

Ques 15 : Choose the correct answer:
Assume the following precedence (high to low). Operators in the same row have the same
precedence:
(.)
*   /   
+   ­
AND
OR
For operators with equal precedence, the precedence is from left­to­right in expression.
What will be the output of the following code statements?

integer a = 50, b = 25, c = 5
print a * b / c + c

Option 1 : 120 Option 2 : 125 Option 3 : 255 Option 4 : 250

Ques 16 : Choose the correct answer:
file:///C:/Users/snovaspace2/Downloads/comp.htm 3/39
11/28/2014 comp.htm

Assume the following precedence (high to low). Operators in the same row have the same
precedence:
(.)
*   /   
+   ­
AND
OR
For operators with equal precedence, the precedence is from left­to­right in expression.
What will be the output of the following code statements?

integer a = 10, b = 35, c = 5
print a * b / c ­ c
Option 1 : 65 Option 2 : 60 Option 3 : Error Option 4 : 70

Ques 17 : Choose the correct answer:
Assume the following precedence (high to low). Operators in the same row have the same
precedence:
(.)
*   /   
+   ­
AND
OR
For operators with equal precedence, the precedence is from left­to­right in expression.
integer a = 10, b = 35, c = 5
Comment about the output of the two statements?
print a * b + c / d
print c / d + a * b
Option 1 : Differ due
to left­to­right Option 2 : Differ by 10 Option 3 : Differ by 20 Option 4 : Same
precedence

Ques 18 : Choose the correct answer:
Assume the following precedence (high to low). Operators in the same row have the same
precedence:
(.)
*   /   
+   ­
AND
OR
For operators with equal precedence, the precedence is from left­to­right in expression.
integer a = 40, b = 35, c = 20, d = 10

Comment about the output of the following two statements:

print a * b / c ­ d
print a * b / (c ­ d)
Option 1 : Differ by Option 4 : Differ
Option 2 : Same Option 3 : Differ by 50
80 by 160

Ques 19 : Choose the correct answer:
file:///C:/Users/snovaspace2/Downloads/comp.htm 4/39
11/28/2014 comp.htm

Assume the following precedence (high to low). Operators in the same row have the same
precedence:
(.)
*   /   
+   ­
AND
OR
For operators with equal precedence, the precedence is from left­to­right in expression.
integer a = 60, b = 35, c = ­30

What will be the output of the following two statements:
print ( a > 45 OR b > 50 AND c > 10 )
print ( ( a > 45 OR b > 50 ) AND c > 10 )
Option 1 : 0 and 1 Option 2 : 0 and 0 Option 3 : 1 and 1 Option 4 : 1 and 0

Ques 20 : Choose the correct answer:
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.
// in pseudo code refers to comment
What will be the output of the following pseudo­code statements:
integer a = 984,   b=10
//float is a data­type to store real numbers.
float c 
c = a / b
print c
Option 1 : 984 Option 2 : 98.4 Option 3 : 98 Option 4 : Error

Ques 21 : Choose the correct answer:
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.
// in pseudo code refers to comment
What will be the output of the following pseudo­code statements:
integer a = 984
//float is a data­type to store rational numbers.
float b= 10, c
c = a / b
print c
Option 1 : 984 Option 2 : Error Option 3 : 98.4 Option 4 : 98

Ques 22 : Choose the correct answer
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
file:///C:/Users/snovaspace2/Downloads/comp.htm 5/39
11/28/2014 comp.htm

{
  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?
Option 1 : No error, Option 4 :
Option 2 : Statement 1 Option 3 : Statement 4
the program is correct. statement 6

Ques 23 : Choose the correct answer
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?
Option 1 : i = 5 Option 2 : i = 5 * i Option 3 : i = i + 1 Option 4 : i = i + 5

Ques 24 : Choose the correct answer
Shantanu wants to make a program to print the sum of the first 7 multiples of 6. He writes the
following program:

integer i = 0 // statement 1
integer sum   // statement 2
while ( i <= 42 ) // statement 3
{
  sum = sum + i // statement 4
  i = i + 6;    
}   
print sum // statement 6

Does this program have an error? If yes, which one statement will you modify to correct the
program?
Option 4 :
Option 1 : Statement 1 Option 2 : Statement 2 Option 3 : Statement 3
Statement 4

Ques 25 : Choose the correct answer
Sharmili wants to make a program to print the sum of all perfect cubes, where the value of the
cubes go from 0 to 100. She writes the following program:

integer i = 0, a    // statement 1
integer sum = 0; 
file:///C:/Users/snovaspace2/Downloads/comp.htm 6/39
11/28/2014 comp.htm

a = ( i * i * i )
while ( i < 100 ) // statement 2

  sum = sum + a // statement 3
  i = i + 1
  a = ( i * i * i )   // statement 4

}   
print sum 

Does this program have an error? If yes, which one statement will you modify to correct the
program?
Option
Option 4 :
Option 1 : Statement 1 Option 2 : Statement 2 Option 3 : Statement 3 5 : No
Statement 4
error

Ques 26 : Choose the correct answer
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?
Option
Option 4 :
Option 1 : Statement 1 Option 2 : Statement 2 Option 3 : Statement 3 5 : No
Statement 4
error

Ques 27 : Choose the correct answer
Vijay wants to print the following pattern on the screen:
2
2 4
2 4 6
2 4 6 8

He writes the following program:

integer i = 1, j=2 // statement 1
while ( i <= 4 ) // statement 2

  j = 2;
  while ( j <= ? ) // Statement 3
  {

file:///C:/Users/snovaspace2/Downloads/comp.htm 7/39
11/28/2014 comp.htm

    print j
    print blank space
    j = j + 2
  }
  print end­of­line \takes the cursor to the next line
  i = i + 1
}

What is the value of ? in statement 3 ::
Option 1 : 8 Option 2 : i Option 3 : 2*i Option 4 : 4

Ques 28 : Choose the correct answer
Shravanti 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?
Option 3 : 0 Option 4 : 0 3 6
Option 1 : 0 Option 2 : 0 3
0 3 6 0 3 6 9
0 3 0 3 6
0 3 6 9 0 3 6 9 12

Ques 29 : Choose the correct answer
Vijay wants to print the following pattern on the screen:
1
1 2
1 2 3

He writes the following program:

integer i = 1 // statement 1
while ( i <= 3 )
{   
  int j // Statement 2
  while ( j <= i ) // Statement 3
  {
    print j
    print blank space
    j = j + 1 // Statement 4
  }

file:///C:/Users/snovaspace2/Downloads/comp.htm 8/39
11/28/2014 comp.htm

  print end­of­line \takes the cursor to the next line
  i = i + 1
}

Will this program function correctly? If not which one statement will you modify to make the
program function correctly?
Option
5 :
Option 4 : Program
Option 1 : Statement 1 Option 2 : Statement 2 Option 3 : Statement 3
Statement 4 does not
have
error.

Ques 30 : Choose the correct answer
Charu writes the following program:

integer i = 1, j, a 
while ( i <= 4 ) 

  j = 1;
  a = 0;
  while ( a <= 5*i ) 
  {
    a = 2^j;
    print a
    print blank space
    j = j + 1
  }
  print end­of­line \takes the cursor to the next line
  i = i + 1
}

What will be the output of the program?
Option 1 : 2 Option 2 : 2 4 Option 3 : 2 4 Option 4 : 2
2 4 2 4 8 2 4 8 2 4
2 4 8 2 4 8 16 2 4 8  2 4
2 4 8 16 2 4 8 16 32 2 4 8 16 2 4 8 16

Ques 31 : Choose the correct answer
Himanshu wants to write a program to print the larger of the two inputted number. He writes
the following code:

int number1, number 2
input number1, number 2
if ("??") // Statement 1
print number1
else
print number2
end if 
Fill in the ?? in statement 1.
Option 4 :
file:///C:/Users/snovaspace2/Downloads/comp.htm 9/39
11/28/2014 comp.htm

Option 1 : Option 2 : Option 3 : number2 number1 <=


number1>number2 number2>number1 equals number1 number2

Ques 32 : Choose the correct answer
Shalini wants to program to print the largest number out of three inputted numbers. She
writes the following program:

int number1, number 2, number3, temp;
input number1, number2, number3;
if (number1>number2)
temp = number1
else 
  temp = number2
end if
if (??) // Statement 1
  temp = number3
end if
print temp

Fill in the ?? in Statement 1
Option 4 :
Option 1 : number3 > Option 2 : number3 > Option 3 : number3 <
number3 >
number2 temp temp
number1

Ques 33 : Choose the correct answer
Rohit writes the following program which inputs a number and prints "Double digit" if the
number is composed of two digits and "Not a double digit" if it is not. 

int number;
if (number>10 AND number < 100)
  print "Double digit"
else 
  print "Not a double digit"
end if

Rohit tries the following inputs: 5 and 66. The program works fine. He asks his brother Ravi to
try the program. When Ravi enters a number, the program doesn't work correctly. What did
Ravi enter?   
Option 1 : 8 Option 2 : 100 Option 3 : 99 Option 4 : 10

Ques 34 : Choose the correct answer
Rohan writes the following program which inputs a number and prints "Triple digit" if the
number is composed of three digits and "Not triple digit" if it is not. 

int number;
if (number>99)
  print "Triple digit"
else 
  print "Not triple digit"
end if
file:///C:/Users/snovaspace2/Downloads/comp.htm 10/39
11/28/2014 comp.htm

Rohan tries the following inputs: 25 and 566. The program works fine. He asks his brother
Ravi to try the program. When Ravi enters a number, the program doesn't work correctly.
What did Ravi enter?   
Option 1 : 99 Option 2 : 100 Option 3 : 0 Option 4 : 1000

Ques 35 : Choose the correct answer
Abhinav wants to find the largest number in a given list of 20 numbers. Which of the following
is an efficient approach to do this?
Option 2 : Use
Option 1 : Use bubble Option 3 : Implement
selection sort to sort
sort to sort the list in one iteration of selection
the list in descending Option 4 : None
descending order and sort for descending order
order and then print of these
then print the first and print the first number
the first number of the
number of the series. in the series.
series.

Ques 36 : Choose the correct answer
Lavanya wants to find the smallest number out of 26 inputted numbers. How many minimum
comparisons he has to make?
Option 1 : 25 Option 2 : 13 Option 3 : 26 Option 4 : 52

Ques 37 : Choose the correct answer
A company offers commission for selling it products to its salesperson. The commission rate is
Rs. 5 per product. However if the salesperson sells more than 200 items, he gets a commission
of Rs. 10 on all items he sold after the first 200. Kanu writes a program to calculate the
commission for the salesperson:

integer numberProducts, commission
input numberProducts

if ( numberProducts > 200 )
­­ MISSING STATEMENT ­­
else
commission = numberProducts * 5
end if
print commission

Fill in the missing statement.
Option 1 : Option 2 : commission
commission = = 200 * 5 + Option 3 : commission = Option 4 : None
(numberProducts ­ (numberProducts ­ numberProducts * 10 of these
200) * 10 200) * 10

Ques 38 : Choose the correct answer
Vikram wants to write a program which checks whether the inputted number is divisible by
any of the first 6 natural numbers (excluding 1). He writes the following efficient code for it.

file:///C:/Users/snovaspace2/Downloads/comp.htm 11/39
11/28/2014 comp.htm

int number, n = 2, isdivisible=0 
input number
while ( n <=6) // Statement 1
{
  if ( remainder (number, n) == 0)
    isdivisible = 1
  end
  n = n+1 // Statement 2
}
if (isdivisible equals 1)
  print "It is divisible"
else 
  print "It is not divisible"
end

Vikram takes the program to Hari. Hari tells Vikram that though the code is correct, it can be
made more efficient. Hari modifies a single statement and makes the code more efficient.
Which statement does he modify and how?
Option 1 : Statement 1 Option 2 : Statement 1 Option 4 :
Option 3 : Statement 1 is
is changed to:  is changed to:  Statement 2 is
changed to: 
while (n <=6 AND while (n <=6 OR changed to: 
while (isdivisible=0)
isdivisible=0) isdivisible=0) n = n + 2

Ques 39 : Choose the correct answer
Rajiv wants to make a program which inputs two numbers: a and b (a>b) and   computes the
number of terms between a and b (including a and b). What will be code statement to do this:
Option 1 : a ­ b Option 2 : a ­ b + 1 Option 3 : a + b Option 4 : a ­ b ­ 1

Ques 40 : Choose the correct answer
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?
Option 2 : Decision­ Option 3 : Object Option 4 :
Option 1 : Iteration
making Oriented Programming Recursion

Ques 41 : Choose the correct answer:
A pseudo­code is used with the following meaning.
"pointer" is a data­type which contains memory address (or pointers)
Statement "a = *b" puts the value at the memory address referenced by b into a.
Statement "a = &b" puts the memory address of b into a.
Statement "*b = a" puts the value a at the memory address referenced by b.
What is the output of the following code statements? The compiler saves the first integer at the
memory location 4062. Integer is one byte long.

integer a
pointer b
a = 20
b = &a
print *b

file:///C:/Users/snovaspace2/Downloads/comp.htm 12/39
11/28/2014 comp.htm

Option 1 : 4062 Option 2 : 4063 Option 3 : 20 Option 4 : 10

Ques 42 : Choose the correct answer:
A pseudo­code is used with the following meaning.
"pointer" is a data­type which contains memory address (or pointers)
Statement "a = *b" puts the value at the memory address referenced by b into a.
Statement "a = &b" puts the memory address of b into a.
Statement "*b = a" puts the value a at the memory address referenced by b.
What is the output of the following code statements? The compiler saves the first integer at the
memory location 4165 and the rest at consecutive memory spaces in order of declaration.
Integer is one byte long.

integer a, b
pointer c, d
a = 30
c = &a
b = *c
a = a + 10
print b
Option 1 : 30 Option 2 : 4165 Option 3 : 40 Option 4 : 4166

Ques 43 : Choose the correct answer:
A pseudo­code is used with the following meaning.
"pointer" is a data­type which contains memory address (or pointers)
Statement "a = *b" puts the value at the memory address referenced by b into a.
Statement "a = &b" puts the memory address of b into a.
Statement "*b = a" puts the value a at the memory address referenced by b.
What is the output of the following code statements? The compiler saves the first integer at the
memory location 4165 and the rest at consecutive memory spaces in order of declaration.
Integer is one byte long.

integer a
pointer c, d
a = 30
c = &a
d = c
a = a + 10
print *c

Option 1 : 30 Option 2 : 4165 Option 3 : 40 Option 4 : 4166

Ques 44 : Choose the correct answer
What is space complexity of a program?
Option 4 :
Option 1 : Amount of Option 2 : Amount of
Option 3 : Amount of Amount of
hard­disk space hard­disk space
memory required by the memory required
required to store the required to compile the
program to run for the program to
program program
compile

file:///C:/Users/snovaspace2/Downloads/comp.htm 13/39
11/28/2014 comp.htm

Ques 45 : Choose the correct answer
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?
Option 3 : Product of
Option 2 : Variable Option 4 : None
Option 1 : Fixed part fixed part and variable
Part of these
part

Ques 46 : Choose the correct answer
While calculating time complexity of an algorithm, the designer concerns himself/herself
primarily with the run time and not the compile time. Why?
Option 4 : A
Option 1 : Run time is Option 2 : Compile program needs to
Option 3 : Compile time
always more than time is always more be compiled once
is a function of run time.
compile time. than run time. but can be run
several times.

Ques 47 : Choose the correct answer
Pankaj and Mythili were both asked to write the code to evaluate the following expression: 
a ­ b + c/(a­b) + (a­b)2 
Pankaj 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*d
If 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?
Option 4 : Code A
Option 1 : Code A Option 2 : Code A
Option 3 : Code A uses uses more
uses lesser memory uses lesser memory
more memory and is memory and is
and is slower than and is faster than Code
faster than Code B slower than Code
Code B B
B

Ques 48 : Choose the correct answer

Vrinda writes an efficient program to sum two square diagonal matrices (matrices with
elements only on diagonal). The size of each matrix is nXn. What is the time complexity of
Vrinda's algorithm?
Option 4 : None
Option 1 : θ(n^2) Option 2 : θ(n) Option 3 : θ(n*log(n))
of these

Ques 49 : Choose the correct answer
Tarang writes an efficient program to add two upper triangular 10X10 matrices (elements on
diagonal retained). How many total additions will his program make?
Option 1 : 100 Option 2 : 55 Option 3 : 25 Option 4 : 10

Ques 50 : Choose the correct answer

file:///C:/Users/snovaspace2/Downloads/comp.htm 14/39
11/28/2014 comp.htm

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):
Option 1 : Code A Option 2 : Code B will Option 4 : Code B
Option 3 : Code A is
will execute faster execute faster than is logically
logically incorrect.
than Code B. Code A incorrect.

Ques 51 : Choose the correct answer
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?
Option 1 : θ(n^2) Option 2 : θ(n) Option 3 : θ(log3(n)) Option 4 : θ(3n)

Ques 52 : Choose the correct answer
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?
Option 4 :
Option 1 : θ(n^2) Option 2 : θ(n) Option 3 : θ(n1/2) θ(log(n))

Ques 53 : Choose the correct answer

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.
Option 4 : None
Option 1 : θ(n^2) Option 2 : θ(n) Option 3 : θ(1)
of these

Ques 54 : Choose the correct answer
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?

file:///C:/Users/snovaspace2/Downloads/comp.htm 15/39
11/28/2014 comp.htm

Option 3 : Code A and Option 4 : The
Option 1 : Code A is Option 2 : Code B is comparison
Code B will run in the
faster than Code B faster than Code A between the speed
same amount of time
of the codes
cannot be made.

Ques 55 : Choose the correct answer
A code takes the following code steps (equivalently time unit) to execute: 5*n3 + 6*n2 + 1.
Which of the following is not true about the time complexity of the program?
Option 1 : It has a Option 4 : It has a
Option 2 : It has a time Option 3 : It has a time
time complexity of time complexity
3 complexity of O(n4) complexity of O(n2)
O(n ) of θ(n3)

Ques 56 : Choose the correct answer
We have two programs. We know that the first has a time complexity O(n2), while the second
has a complexity ω(n2). For sufficiently large n, which of the following cannot be true?
Option 2 : The first Option 3 : The second
Option 4 : Both
Option 1 : Both codes code has higher time code has lower time
codes are the
have same complexity complexity than the complexity than the first
same.
second code.

Ques 57 : Choose the correct answer
The time complexity of code A is θ(n), while for Code B it is θ(log(n)). Which of the following is
true for sufficiently large n?

Option 4 : No
Option 1 : Both code Option 2 : Code A has comparison can be
Option 3 : Code B has
have the same time higher time made between the
higher time complexity
complexity complexity time complexity
of the two codes.

Ques 58 : Choose the correct answer
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?
Option 4 : It is
Option 1 : It is O(n) Option 2 : It is O(n2) Option 3 : It is θ(n)
ω(n)

Ques 59 : Choose the correct answer
Gautam is given two codes, A and B, to solve a problem, which have complexity θ(n) and θ(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?
Option 4 : Both
codes have the
Option 3 : Gautam
Option 1 : Code A Option 2 : Code B same execution
cannot determine
time, so deliver
any.
file:///C:/Users/snovaspace2/Downloads/comp.htm 16/39
11/28/2014 comp.htm

Ques 60 : Choose the correct answer
Surbhi is given two codes, A and B, to solve a problem, which have complexity O(n3) and ω(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?
Option 4 : Both
codes have the
Option 3 : Surbhi cannot
Option 1 : Code A Option 2 : Code B same execution
determine
time, so deliver
any.

Ques 61 : Choose the correct answer
Vibhu is given two codes, A and B, to solve a problem, which have complexity O(n4) and ω(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?
Option 4 : Both
codes have the
Option 3 : Vibhu cannot
Option 1 : Code A Option 2 : Code B same execution
determine
time, so deliver
any.

Ques 62 : Choose the correct answer
Pavithra is given two codes, A and B, to solve a problem, which have complexity θ(n3) and
ω(n3) respectively. Her client wants to solve a problem of size k, which is sufficiently large.
Which code should she deliver to the client in the present scenario?
Option 3 : Both codes
Option 4 : None
Option 1 : Code A Option 2 : Code B have the same execution
of these
time, so deliver any.

Ques 63 : Choose the correct answer
Code A has to execute 4*n2 + 64 program statements, while Code B has to execute 32*n
program statements for a problem of size n. The time for executing a single program statement
is same for all statements. Rajesh was given a problem with a certain size k and he delivered
Code A. What could be the possible value of k?
Option 1 : 1000 Option 2 : 5 Option 3 : 10 Option 4 : 3

Ques 64 : Choose the correct answer
Saumya writes a code which has a function which calls itself. Which programming concept is
Saumya using?
Option 1 : This is bad
programming practice Option 3 : Decision Option 4 :
Option 2 : Recursion
and should not be Making Overloading
done.

Ques 65 : Choose the correct answer

file:///C:/Users/snovaspace2/Downloads/comp.htm 17/39
11/28/2014 comp.htm

Shrishti writes the code for a function that computes the factorial of the inputted number n.

function factorial(n)
{
  if(n equals 1)
    return 1
  else
­­ MISSING STATEMENT ­­
  end
}

Fill in the missing statement.
Option 1 : return Option 2 : return Option 4 : return
Option 3 : return n*(n­1)
factorial(n­1) n*factorial(n) n*factorial(n­1)

Ques 66 : Choose the correct answer
Tanuj writes the code for a function that takes as input n and calculates the sum of first n
natural numbers.

Function sum( n )
{
  if(??)
    return 1
  else
    return (n + sum(n­1))
  end
}

Fill in ?? in the code.
Option 1 : n equals 1 Option 2 : n equals 2 Option 3 : n >= 1 Option 4 : n > 1

Ques 67 : Choose the correct answer
Saloni writes the code for a function that takes as input n, an even integer and calculates the
sum of first n even natural numbers.

function sum( n )
{
  if(n equals 2)
    return 2
  else
    return (n + sum(n­2))
  end
}

She then calls the function by the statement, sum(30). How many times will the function sum be
called to compute this sum.
Option 1 : 1 Option 2 : 30 Option 3 : 15 Option 4 : 16

Ques 68 : Choose the correct answer
Consider the following function
file:///C:/Users/snovaspace2/Downloads/comp.htm 18/39
11/28/2014 comp.htm

function calculate( n )
{
  if(n equals 5)
    return 5
  else
    return (n + calculate(n­5))
  end
}

Shishir calls the function by the statement, calculate(20). What value will the function return?
Option 1 : 50 Option 2 : 200 Option 3 : 35 Option 4 : 20

Ques 69 : Choose the correct answer
Ravi is writing a program in C++. C++ uses the 'for' keyword for loops. Due to distraction,
Ravi writes 'gor' instead of 'for'. What will this result to?

Option 2 : The code Option 3 : The code may Option 4 : It will


Option 1 : The code
will give an error work for some inputs and create no
will not compile.
while in execution not for others. problems.

Ques 70 : Choose the correct answer
What does a compiler do?
Option 4 :
Option 1 : Converts Option 3 : Converts code
Option 2 : Necessarily Necessarily
code from a high level from a low level
converts the code into converts the code
language to a low language to a high level
assembly language into machine
level language language
language

Ques 71 : Choose the correct answer
A program is compiled by Tarun on his machine. Whether it will run on a different computer
will depend upon:
Option 1 : Operating Option 2 : Hardware Option 3 : Both Option 4 : The
system on the configuration of the operating system and language of the
computer computer hardware configuration program

Ques 72 : Choose the correct answer
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?
Option 1 : An Option 3 : A cross­
Option 2 : A compiler Option 4 : Linker
interpreter compiler

Ques 73 : Choose the correct answer
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:
Option 1 : Compile Option 2 : Use an
Option 3 : Compile the Option 4 : None
the whole code and interpreter on the first
whole code and run it of these
file:///C:/Users/snovaspace2/Downloads/comp.htm 19/39
11/28/2014 comp.htm

step into it line by line 25 lines.

Ques 74 : Choose the correct answer
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?
Option 1 : Syntactical Option 2 : Run­time Option 4 : None
Option 3 : Logical Error
error Error of these

Ques 75 : Choose the correct answer
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?
Option 4 :
Option 1 : Compiler, Option 2 : Interpreter, Option 3 : Compiler,
Interpreter,
Interpreter Compiler Compiler
Interpreter

Ques 76 : Choose the correct answer
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?
Option 4 :
Option 1 : Compiler Option 2 : Interpreter Option 3 : Assembler
Simulator

Ques 77 : Choose the correct answer
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( )?
Option 1 : 11 ­5 Option 2 : 10 ­5 Option 3 : 6 ­5 Option 4 : 5 ­5

file:///C:/Users/snovaspace2/Downloads/comp.htm 20/39
11/28/2014 comp.htm

Ques 78 : Choose the correct answer
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( ) ?
Option 1 : 7 Option 2 : ­7 Option 3 : Error Option 4 : 8

Ques 79 : Choose the correct answer
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( ) ?
Option 1 : 12 ­8 Option 2 : 13 ­8 Option 3 : 12 8 Option 4 : 13 8

Ques 80 : Choose the correct answer
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?
Option 1 : Use for Option 2 : Use Option 4 : Use
Option 3 : Use arrays
loops functions classes

file:///C:/Users/snovaspace2/Downloads/comp.htm 21/39
11/28/2014 comp.htm

Ques 81 : Choose the correct answer
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?
Option 3 : Code A and
Option 4 : None
Option 1 : Code A Option 2 : Code B Code B will run with the
of these
same speed

Ques 82 : Choose the correct answer
Consider the following code:

function modify(a,b)
{
  integer c, d = 2
  c = a*d + b
  return c
}

function calculate( )
{
  integer a = 5, b = 20, c
  integer d = 10
  c = modify(a, b);
  c = c + d
  print c
}

Assume that a and b were passed by value. What will be the output of the function calculate( )
?
Option 1 : 80 Option 2 : 40 Option 3 : 32 Option 4 : 72

Ques 83 : Choose the correct answer
Consider the following code:

function modify(w,u)
{
  w = w + 2
  u = u ­ 3
  return (w ­ u)
}

function calculate( )
{
  integer a = 10, b = 20, c
  c = modify(a, b);
  print a
  print space
  print b

file:///C:/Users/snovaspace2/Downloads/comp.htm 22/39
11/28/2014 comp.htm

Assume that a was passed by value and b was passed by reference. What will be the output of
the program on executing function calculate( ) ?
Option 1 : 12 17 Option 2 : 10 17 Option 3 : 12 20 Option 4 : 10 20

Ques 84 : Choose the correct answer
Consider the following function:

function run( )
{
  integer a = 0 // Statement 1
  while (a < 5)
  {
    integer c = 0   // Statement 2
    c = c + 1   // Statement 3
    a = a + 1
  }
  print c   // Statement 4
}

At which statement in this program will the compiler detect an error?
Option 4 :
Option 1 : Statement 1 Option 2 : Statement 2 Option 3 : Statement 3
Statement 4

Ques 85 : Choose the correct answer
Which one of the following is the lowest level format to which the computer converts a higher
language program before execution?
Option 1 : English Option 2 : Machine Option 3 : Assembly Option 4 : System
code Code Language Language

Ques 86 : Choose the correct answer
If you want to write a function that swaps the values of two variables, you must pass them by:
Option 2 : Reference Option 4 : Neither
Option 1 : Value only Option 3 : Either A or B
only A nor B

Ques 87 : Choose the correct answer
Consider the following code:

if (condition 1) {
  if (condition 2) 
  {   // Statement A   }
  else 
    if (condition 3) 
    { // Statement B }
    else 
    { // Statement C }
else 

file:///C:/Users/snovaspace2/Downloads/comp.htm 23/39
11/28/2014 comp.htm

  if (condition 4) 
  { // Statement D }
  else 
  { // Statement E}
}
Which of the following conditions will allow execution of statement C?
Option 4 :
condition1 AND
Option 1 : condition1 Option 2 : condition1 Option 3 :
AND condition3 AND condition4 AND NOT(condition2) AND NOT(condition2)
!condition2 NOT(condition3) AND
NOT(condition3)

Ques 88 : Choose the correct answer
Consider the following code:

if (condition 1) {
if (condition 2) 
  { // Statement A }
  else 
    if (condition 3) 
    { // Statement B}
    else 
    {// Statement C }
else 
  if (condition 4) 
  {// Statement D}
  else 
  {// Statement E}
}

Which of the following conditions will allow execution of statement E?
Option 4 :
Option 2 : condition1 AND
Option 3 :
Option 1 : condition1 NOT(condition1) condition4 AND
NOT(condition2) AND
AND condition3 AND condition2 AND NOT(condition2)
NOT(condition3)
NOT(condition4) AND
NOT(condition3)

Ques 89 : Choose the correct answer
Consider the following code:

if (condition 1) {
if (condition 2) 
  { // Statement A }
  else 
    if (condition 3) 
    { // Statement B}
    else 
    {// Statement C }
else 
  if (condition 4) 
file:///C:/Users/snovaspace2/Downloads/comp.htm 24/39
11/28/2014 comp.htm

  {// Statement D}
  else 
  {// Statement E}
}

Which of the following condition will allow execution of statement A?
Option 2 : condition1 Option 4 :
Option 1 : NOT(condition1)
AND condition4 AND Option 3 : condition1
NOT(condition2)
NOT(condition2) AND condition2 AND AND condition2
AND AND
AND condition4
NOT(condition3) NOT(condition4)
NOT(condition3)

Ques 90 : Choose the correct answer
What does the following function do?

function operation (int a, int b) 
{
if (a < b)   
  { return operation(b, a) }
else 
  { return a }
}
Option 4 : Always
Option 1 : Returns the Option 2 : Returns the
Option 3 : Loops forever returns the second
max of (a,b) min of (a,b)
parameter

Ques 91 : Choose the correct answer
What does the following function do?

function operation (int a, int b) 
{
  if (a > b) 
  { return operation(b, a) }
  else 
  { return a; }
}
Option 1 : Always
Option 2 : Returns the Option 3 : Returns the Option 4 : Loops
returns the first
min of (a,b) max of (a,b) forever
parameter

Ques 92 : Choose the correct answer
function g(int n)
{
if (n > 0) return 1;
else return ­1;

function f(int a, int b)
file:///C:/Users/snovaspace2/Downloads/comp.htm 25/39
11/28/2014 comp.htm

{
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?
Option 4 : 0 if a
Option 2 : 1 if a > b, ­1 Option 3 : ­1 if a > b, 1 if
Option 1 : Always ­1 if a < b, 0 otherwise equals b, ­1
a < b, 0 otherwise
otherwise

Ques 93 : Choose the correct answer
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?
Option 4 : ­1 if a
Option 1 : 1 if a > b, Option 3 : 0 if a equals b,
Option 2 : Always +1 > b, 1 if a < b, 0
­1 if a < b, 0 otherwise +1 otherwise
otherwise

Ques 94 : Choose the correct answer
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?
Option 4 : 0 if a
Option 2 : 1 if a > b, ­1 Option 3 : ­1 if a > b, 1 if
Option 1 : Always +1 equals b, ­1
if a < b, 0 otherwise a < b, 0 otherwise
otherwise

file:///C:/Users/snovaspace2/Downloads/comp.htm 26/39
11/28/2014 comp.htm

Ques 95 : Choose the correct answer
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?
Option 4 : 0 if a
Option 2 : ­1 if a > b, 1 Option 3 : 1 if a > b, ­1 if
Option 1 : Always +1 equals b, ­1
if a < b, 0 otherwise a < b, 0 otherwise
otherwise

Ques 96 : Choose the correct answer
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?
Option 4 : (n ­ m
Option 3 : 1 + (n ­ m)/2
Option 1 : (n ­ m + Option 2 : 1 + (n ­ + 1)/2 if m is
if m is even, (n ­ m +
1)/2 m)/2 even, 1 + (n ­
1)/2 if m is odd
m)/2 if m is odd

Ques 97 : Choose the correct answer
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?
Option 4 : (n ­ m
Option 3 : 1 + (n ­ m)/2
Option 1 : (n ­ m + Option 2 : 1 + (n ­ + 1)/2 if m is
if m is even, (n ­ m +
1)/2 m)/2 even, 1 + (n ­
1)/2 if m is odd
m)/2 if m is odd

Ques 98 : Choose the correct answer
Assuming n > 2, What value does the following function compute for odd n?

function f (int n)
{

file:///C:/Users/snovaspace2/Downloads/comp.htm 27/39
11/28/2014 comp.htm

if (n equals 1) { return 1 }
if (n equals 2) { return f(n­1) + n/2 }
return f(n­2) + n;
}
Option 4 : 1 + (1
Option 1 : 1 + 2 + 3 + Option 2 : 1 + 3 + 5 + Option 3 : n/2 + (1 + 3 +
+ 3 + 5 + 7 + ... +
4 + ... + n 7 + ... + n 5 + 7 + ... + n)
n)

Ques 99 : Choose the correct answer

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 
}
Option 1 : 1 + 2 + 3 + Option 2 : 1 + (2 + 4 + Option 3 : 1 + n/2 + (4 + Option 4 : 2 + 4 +
4 + ... + n 6 + 8 + ... + n) 6 + 8 + ... + n) 6 + 8 + ... + n

Ques 100 : Choose the correct answer
The for loop is equivalent to a while loop when
Option 1 : There is no
Option 2 : There is no Option 3 : A and B Option 4 : It is
initialization
increment expression combined are true never equivalent
expression

Ques 101 : Choose the correct answer
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?
Option 1 : a < 1.0 Option 2 : a < sqrt(10) Option 3 : a > sqrt(10) Option 4 : a = 0

Ques 102 : Choose the correct answer
int area(double radius)
{
return PI*radius*radius;
}

Which of the following is always true about the function area?
Option 3 : It returns the
Option 1 : It returns Option 2 : It returns
area of a circle within the
the area of a circle the area of a circle Option 4 : None
limits of precision of
within the limits of within the limits of the of the above.
double, or the constant
double precision. constant PI.
PI, whichever is lower.

Ques 103 : Choose the correct answer
file:///C:/Users/snovaspace2/Downloads/comp.htm 28/39
11/28/2014 comp.htm

What does this function compute for positive n?

function   f(int n)
{
  if (n equals 1) 
  { return 1 }
  else 
  { return f(n­1)/f(n­1) + n }
}

Option 2 : 1 + 2 + 3 + Option 3 : 1 + n, if n > 1, Option 4 : None


Option 1 : 1 + n
... + n 1 otherwise of the above

Ques 104 : Choose the correct answer
Which of these is not a data type?
Option 1 : integer Option 2 : character Option 3 : boolean Option 4 : array

Ques 105 : Choose the correct answer
The construct "if (condition) then A else B" is for which of the following purposes?
Option 4 : Object
Option 1 : Decision­
Option 2 : Iteration Option 3 : Recursion Oriented
Making
Programming

Ques 106 : Choose the correct answer
In a sequential programming language, code statements are executed in which order?
Option 1 : All are
Option 2 : From top to Option 3 : From bottom Option 4 : None
executed
bottom to top of these
simultaneously

Ques 107 : Choose the correct answer
A for­loop is used for which of the following purposes?
Option 1 : Decision­ Option 4 : None
Option 2 : Iteration Option 3 : Recursion
Making of these

Ques 108 : Choose the correct answer
There are two loops which are nested. This implies which one of the following?
Option 4 : Two
Option 3 : One loop with
Option 1 : Two loop, Option 2 : Two loops, loops with the
two different iteration
one after the other one inside the others same iteration
counts
count

Ques 109 : Choose the correct answer
How will 47 be stored as an unsigned 8­bit binary number?
Option 4 :
Option 1 : 10111101 Option 2 : 00101111 Option 3 : 10111000
00101101

file:///C:/Users/snovaspace2/Downloads/comp.htm 29/39
11/28/2014 comp.htm

Ques 110 : Choose the correct answer
An integer X is saved as an unsigned 8­bit number, 00001011.What is X?
Option 4 : None
Option 1 : 22 Option 2 : 11 Option 3 : 10
of these

Ques 111 : Choose the correct answer
A variable cannot be used…
Option 1 : Before it is Option 2 : After it is Option 3 : In the function Option 4 : Can
declared declared it is declared in always be used

Ques 112 : Choose the correct answer
What is implied by the argument of a function?
Option 1 : The
Option 2 : The value it Option 3 : The execution Option 4 : Its
variables passed to it
returns on execution code inside it return type
when it is called

Ques 113 : Choose the correct answer
Which of the following is true about comments?
Option 3 : A good Option 4 : They
Option 1 : They are Option 2 : They are
program does not contain increase program
executed only once. not executed
them execution time.

Ques 114 : Choose the correct answer
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?
Option 4 :
Option 1 : Header
Option 2 : Iteration Option 3 : Comments Preprocessor
files
directive

Ques 115 : Choose the correct answer
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?
Option 1 : Faster Option 2 : Lower Option 3 : Correction of Option 4 : Better
Execution memory requirement errors readability

Ques 116 : Choose the correct answer
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?
Option 2 : Code A is
file:///C:/Users/snovaspace2/Downloads/comp.htm 30/39
11/28/2014 comp.htm

Option 1 : Code B is better because the Option 3 : Code A will Option 4 : Code B


better because variable names are run correctly, while Code will run correctly,
variable names are understandable and B will give an error. while Code A will
shorter non­confusing give an error.

Ques 117 : Choose the correct answer
For solving a problem, which of these is the first step in developing a working program for it?
Option 1 : Writing the
Option 2 : Writing a
program in the Option 3 : Compiling the Option 4 : Code
step­by­step algorithm
programming libraries required. debugging
to solve the problem.
language

Ques 118 : Choose the correct answer
A robust program has which one of the following features?
Option 1 : It runs Option 3 : It can handle
Option 2 : It is robust Option 4 : None
correctly on some incorrect input data or
to hardware damage of these
inputs data types.

Ques 119 : Choose the correct answer
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?
Option 2 : Decision­ Option 4 : None
Option 1 : Iteration Option 3 : Recursion
making of these

Ques 120 : Choose the correct answer
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?
Option 1 : Top­down Option 2 : Bottom­Up Option 3 : Procedural Option 4 : None
Approach Approach Programming of these

Ques 121 : Choose the correct answer
The time complexity of linear search algorithm over an array of n elements is
Option 1 : O (log2 n) Option 2 : O (n) Option 3 : O (n log2 n ) Option 4 : O (n2)

Ques 122 : Choose the correct answer
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:
Option 4 : O (n
Option 1 : O (1) Option 2 : O (log2 n) Option 3 : O (n)
log2 n )

Ques 123 : Choose the correct answer
The time required to insert an element in a stack with linked list implementation is

file:///C:/Users/snovaspace2/Downloads/comp.htm 31/39
11/28/2014 comp.htm

Option 1 : O (1) Option 2 : O (log2 n) Option 3 : O (n) Option 4 : O (n


log2 n )

Ques 124 : Choose the correct answer
In the following sorting procedures, which one will be the slowest for any given array?
Option 4 : Bubble
Option 1 : Quick sort Option 2 : Heap sort Option 3 : Merge Sort
sort

Ques 125 : Choose the correct answer
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?
Option 1 : O(1) Option 2 : O(n2) Option 3 : O(log n) Option 4 : O(n)

Ques 126 : Choose the correct answer
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 by using the key. What
is this search mechanism?
Option 1 : Linear Option 2 : Binary Option 3 : Hash Coded Option 4 : None
Search search Search of these

Ques 127 : Choose the correct answer
The order of magnitude of the worst case performance of a hash coded search (over N
elements) is
Option 2 : N log2 N Option 3 : log2 N Option 4 : not
Option 1 : N
dependent upon N

Ques 128 : Choose the correct answer
A sorting algorithm traverses through a list, comparing adjacent elements and switching them
under certain conditions. What is this sorting algorithm called?
Option 1 : insertion Option 4 : bubble
Option 2 : heap sort Option 3 : quick sort
sort sort

Ques 129 : Choose the correct answer
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?
Option 1 : insertion Option 2 : selection Option 4 : quick
Option 3 : heap sort
sort sort sort

Ques 130 : Choose the correct answer
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
Option 1 : selection Option 2 : insertion Option 4 : quick
Option 3 : heap sort
sort sort sort
file:///C:/Users/snovaspace2/Downloads/comp.htm 32/39
11/28/2014 comp.htm

Ques 131 : Choose the correct answer
The average time required to perform a successful sequential search for an element in an array
A(1 : n) is given by
Option 1 : (n+1) / 2 Option 2 : log2n Option 3 : n(n+1) / 2 Option 4 : n2

Ques 132 : Choose the correct answer
How many comparisons are needed to sort an array of length 5 if a straight selection sort is
used and array is already in the opposite order?
Option 1 : 1 Option 2 : 10 Option 3 : 50 Option 4 : 20

Ques 133 : Choose the correct answer
Queues serve a major role in
Option 3 : simulation of Option 4 :
Option 1 : simulation Option 2 : simulation
limited resource expression
of recursion of arbitrary linked list
allocation evaluation

Ques 134 : Choose the correct answer
The average search time of hashing with linear probing will be less if the load factor
Option 1 : is far less Option 3 : is far greater Option 4 : none of
Option 2 : equals one
than one than one these

Ques 135 : Choose the correct answer
Number of vertices of odd degree in a graph is
Option 1 : is always Option 3 : either even or Option 4 : always
Option 2 : always odd
even odd zero

Ques 136 : Choose the correct answer
The algorithm design technique used in the quick sort algorithm is
Option 1 : Dynamic Option 2 : Back Option 3 : Divide and Option 4 : Greedy
programming tracking conquer Search

Ques 137 : Choose the correct answer
Linked lists are not suitable for
Option 1 : Insertion Option 2 : Binary Option 3 : Queue Option 4 : None
sort search implementation of these

Ques 138 : Choose the correct answer
A connected graph is the one which
Option 1 : Cannot be Option 2 : Can be Option 4 : Has
Option 3 : does not
partitioned without partitioned without even number of
contain a cycle
removing an edge removing an edge vertices

file:///C:/Users/snovaspace2/Downloads/comp.htm 33/39
11/28/2014 comp.htm

Ques 139 : Choose the correct answer
Stack is useful for implementing
Option 1 : radix Option 2 : breadth first Option 4 : none of
Option 3 : recursion
search search these

Ques 140 : Choose the correct answer
Which of the following is useful in traversing a given graph by breadth first search?
Option 1 : stack Option 2 : set Option 3 : list Option 4 : queue

Ques 141 : Choose the correct answer
Which of the following is useful in implementing quick sort?
Option 1 : stack Option 2 : set Option 3 : list Option 4 : queue

Ques 142 : Choose the correct answer
Which of the following abstract data types can be used to represent a many­to­many relation?
Option 1 : Tree Option 2 : Stack Option 3 : Graph Option 4 : Queue

Ques 143 : Choose the correct answer
Two lists, A and B are implemented as singly linked link­lists. The address of the first and last
node are stored in variables firstA and lastA for list A and firstB and lastB for list B. Given the
address of a node is given in the variable node, the element stored in the node can be accessed
by the statement node­>data and the address to the next node can be accessed by node­>next.
Pankaj wants to append list B at end of list A. Which of the following statements should he
use?
Option 1 : lastB ­> Option 2 : lastA = Option 3 : lastA­>next = Option 4 : lastB =
next = firstA firstB firstB firstA

Ques 144 : Choose the correct answer
Which of the following sorting algorithms yield approximately the same worst­case and
average­case running time behaviour in O (n log n)?
Option 4 : Tree
Option 1 : Bubble sort Option 2 : Heap sort Option 3 : Quick sort and
sort and Median­
and Selection sort and Merge sort Radix sort
of­3 Quick sort

Ques 145 : Choose the correct answer
A complete binary tree with 5 levels has how many nodes? (Root is Level 1)
Option 1 : 15 Option 2 : 25 Option 3 : 63 Option 4 : 31

Ques 146 : Choose the correct answer
The maximum number of nodes on level I of a binary tree is which of the following? (Root is
Level 1)
Option 1 : 2l­1 Option 2 : 3l­1 Option 3 : 2l Option 4 : 2l ­ 1

file:///C:/Users/snovaspace2/Downloads/comp.htm 34/39
11/28/2014 comp.htm

Ques 147 : Choose the correct answer
Consider an array on which bubble sort is used. The bubble sort would compare the   element
A[x] to which of the following elements in a single iteration.
Option 4 : All of
Option 1 : A [x+1] Option 2 : A [x+2] Option 3 : A [x+2x]
these.

Ques 148 : Choose the correct answer
In an implementation of a linked list, each node contains data and address. Which of the
following could the address field possibly contain?
Option 4 :
Option 1 : Address of Option 2 : It's own Option 3 : Address of
Address of first
next node in sequence address last node
node

Ques 149 : Choose the correct answer
Surbhi wants to implement a particular data structure using a static array. She uses the
concept of circular list to implement the data structure, because this allows her to efficiently
use all fields of the array. Which data structure is Surbhi implementing?
Option 4 : None
Option 1 : a stack Option 2 : a queue Option 3 : Binary Tree
of these

Ques 150 : Choose the correct answer
Which of the following is a bad implementation for a queue?
Option 1 : Circular Option 2 : Doubly Option 3 : Singly linked Option 4 : Linear
List linked list List Static Array

Ques 151 : Choose the correct answer
Which of the following statements are true about a doubly­linked list?
Option 3 : it will occupy
Option 1 : it may be same memory space as
Option 2 : it must that of linear linked list, Option 4 : None
either linear or
contain a header node both having same of these
circular
number of nodes

Ques 152 : Choose the correct answer
Which of the following data structure may give overflow error, even though the current
number of element in it is less than its size ?
Option 2 : Queue
Option 1 : Queue Option 3 : Stack
implemented in a Option 4 : none of
implemented in a implemented in a linear
circularly connected these
linear array array
array

Ques 153 : Choose the correct answer
Number of possible ordered trees with 3 nodes A, B, C is
Option 1 : 16 Option 2 : 12 Option 3 : 13 Option 4 : 14

file:///C:/Users/snovaspace2/Downloads/comp.htm 35/39
11/28/2014 comp.htm

Ques 154 : Choose the correct answer
The best sorting methods if number of swapping done is the only measure of efficiency is
Option 2 : Selection Option 4 : Quick
Option 1 : Bubble sort Option 3 : Insertion sort
sort sort

Ques 155 : Choose the correct answer
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
Option 2 : insertion Option 4 : heap
Option 1 : bubble sort Option 3 : selection sort
sort sort

Ques 156 : Choose the correct answer
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 is
Option 1 : 0.6 Option 2 : 0.1 Option 3 : 0.2 Option 4 : 0.5

Ques 157 : Choose the correct answer
A full binary tree with n leaves contains
Option 1 : 2n + 1 Option 2 : log2 n Option 4 : 2n
Option 3 : 2n ­ 1 nodes
nodes nodes nodes

Ques 158 : Choose the correct answer
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?

Option 1 : 2 Option 2 : 3 Option 3 : 4 Option 4 : 5

Ques 159 : Choose the correct answer
An array of 5 numbers has the following entries in order: 7 4 5 10 8. Prashant uses selection
sort to sort this array in descending order. What will the array contain after two iterations of
selection sort?
Option 4 : None
Option 1 : 10 8 7 5 4 Option 2 : 10 8 5 7 4 Option 3 : 8 10 5 7 4
of these

Ques 160 : Choose the correct answer
Srishti writes a program to find an element in the array A[5] with the following elements in
order: 8 30 40 45 70. 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?
Option 1 : 40 Option 2 : 8 Option 3 : 70 Option 4 : 30

Ques 161 : Choose the correct answer
The array A has n elements. We want to determine the position of X in the array. We know
that X is present in the array A and X can be present at any location in the array with equal
file:///C:/Users/snovaspace2/Downloads/comp.htm 36/39
11/28/2014 comp.htm

probability. How many comparisons will be required on average to find the element X using
linear search?
Option 1 : n Option 2 : (n+1)/2 Option 3 : 2*n Option 4 : n^2

Ques 162 : Choose the correct answer
A is an empty stack. The following operations are done on it.
PUSH(1)
PUSH(2)
POP
PUSH(5)
PUSH(6)
POP
What will the stack contain after these operations. (Top of the stack is underlined)
Option 1 : 5 6 Option 2 : 1 5 Option 3 : 5 6 Option 4 : 1 5

Ques 163 : Choose the correct answer
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+1
    A[top] = E
  }
  else
  {
    print "Overflow"
  }
  return top
}

Fill in the condition X

Option 1 : top< N Option 2 : top Option 3 : top > 0 Option 4 : top > 1

Ques 164 : Choose the correct answer
A stack is implemented as a linear array A[0…N­1]. Noor writes the following functions for
popping an element from the stack.
function POP( top, N )
{
  if(X)
  {
    top = top ­ 1
  }
  else
  {
    print "Underflow"
  }
  return top

file:///C:/Users/snovaspace2/Downloads/comp.htm 37/39
11/28/2014 comp.htm

Fill in the condition X
Option 4 : top >=
Option 1 : top< N­1 Option 2 : top Option 3 : top>1
0

Ques 165 : Choose the correct answer
Q is an empty queue. The following operations are done on it:
ADD 5
ADD 7
ADD 46
DELETE
ADD 13
DELETE
DELETE
ADD 10
What will be the content of Q after these operations. Front is marked by (F) and Rear is
marked by (R).
Option 4 : 10(R)
Option 1 : 10(R) 13(F) Option 2 : 5(R) 10(F) Option 3 : 13(R) 10(F)
5(F)

Ques 166 : Choose the correct answer
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?
Option 4 : None
Option 1 : Front Option 2 : Rear Option 3 : Both
of these

Ques 167 : Choose the correct answer
A stack is implemented as a (singly­linked) linked­list, where each node contains data and
address of another node. The top node will contain the address of which node?
Option 2 : The node Option 3 : The node
Option 1 : No node. It containing the first containing the element Option 4 : None
will be empty element pushed into which was pushed just of these
the stack. before the top element.

Ques 168 : Choose the correct answer
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, DELETE 
After this set of operations, what is the maximum capacity of the queue?
Option 4 : None
Option 1 : 6 Option 2 : 7 Option 3 : 10
of these

Ques 169 : Choose the correct answer

file:///C:/Users/snovaspace2/Downloads/comp.htm 38/39
11/28/2014 comp.htm

A queue is implemented as a (singly linked) linked­list. Each node has an element and pointer
to another node. Rear and Front contain the addresses of the rear and front node respectively.
If the condition (rear isequal front) is true and neither is NULL, what do we infer about the
linked list?
Option 1 : It has no Option 2 : It has one Option 3 : There is an Option 4 : None
elements element error of these

Ques 170 : Choose the correct answer
Jaswinder 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 Jaswinder use to represent the ticket booklet?
Option 1 : Queue Option 2 : Stack Option 3 : Array Option 4 : Graph

file:///C:/Users/snovaspace2/Downloads/comp.htm 39/39

You might also like