Computer Programming Questions
Computer Programming Questions
1. Optical fibre transports signal on the basis of total internal reflection principle.
2. Refractive index of core should be less than that of cladding.
3. Every beam which strikes the interface of core and cladding is reflected back.
TFF
TTT
TFT
FFF
2. Passage
Vijay wants to print the following pattern on the screen:
1
12
123
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
}
print end-of-line // takes the cursor to the next line
i=i+1
}
Question:
a. Statement 1
b. Statement 2 -ANS
c. Statement 3
d. Statement 4
e. Program does not have error
3. Passage:
Abhinav wants to find the largest number in a given list of 20 numbers. which of
the following options is an efficient approach to do this?
1) use bubble sort to sort the list in descending order and then print the first number
of the series.
2) use selection sort to sort the list in descending order and then print the first
number of the series
3) implement one iteration of selection sort for descending order and print the first
number in the series.-ANS
4) none of these
passage:
what is implied by the argument of a function?
question
1. the variables passed to it when it is called-ANS
2. the value it returns on execution
3. the execution code inside it
4. its return type
passage: there are two loops which are nested. this implies which one of the
following?
question
1.
2.
3.
4.
Passage:
Mary is making a database of animals in a zoo and their properties. The possible
animals are dog, lion and zebra. Each one has as attributes is herbivorous, colour
and is nocturnal. She uses the object oriented programming paradigm for this.
How will she conceptualize the system?
Question
1.
2.
class: Animal; objects: isHerbivorous, colour and isNocturnal; data
members: dog, lion and zebra
3.
classes: dog, lion and zebra; objects: Animal; data members:
isHerbivours,colour and IsNocturnal
4.
none of these
passage
what is space complexity of a program?
Question
1. amount of hard-disk space required to store the program
2. amount of hard-disk space required to compile the program
3. amount of memory required by the program to run-ans
4. amount of memory required for the program to compile
passage:
function MuFunc1(integer n)
{
return n*2
}
Function MyFunc2( integer n)
{
Print the value is n
}
Question:
Passage:
Zenab and shashi independently write a program to find the mass of one mole
of water,which includes mass of hydrogen and oxygen. Zenab defines the
cariables:
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?
Question
1. Code B is better because variable names are shorter
2. Code A is better because the variable names are understandable and nonconfusing-ans
3. Code A will run correctly, while Code B will give an error.
4. Code B will run correctly, while code A will give an error.
Passage:
A derived class may inherit from the base class which of the following
(consider assumptions as in C++)
Question
1. Data members
2. Member functions
3. Constructors and destructors
4. Both data members and member functions-ans
Passage:
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 is equal front) is true
and neither is NULL, What do we infer about the linked list?
Question:
1. It has no elements
2. It has one elements-ans
3. There is an error
4. None of these
Passage:
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 statement1,sum(30). How many times will the
function sum be called to compute this sum?
Question
1. 1
2. 30
3. 15-ans
4. 16
Passage:
What is implied by the argument of a function?
Question
1. The variables passed to it when it is called-ans
2. The value it returns on execution
3. The execution code inside it
4. its return type
Passage:
For solving a problem, which of these is the first step in developing a working
program for it?
Question
1. writing the program in the programming language
2. writing a step-by-step algorithm to solve the program-ans
3. compiling the libraries required.
4. Code debugging.
Passage:
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)
Question
1. Differ by 80 ans
2. Same
3. Differ by 50
4. Differ by 160
Passage
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
Question
1. Bubble sort
2. Insertion sort-ans
3. Selection sort
4. Heap sort
Question
Which one of the following is not a program control instruction?
1. JMP
2. CALL ANS
3. RET
4. INC
QUESTION
For q relation R(A,B,C,D,E,F) given are functional dependencies on R
1. AB
2. CD
3. DBF
4. FC
Which of the following functional dependencies is not true for R?
1. DAF
2. CB
3. AFDB
4. FD
PASSAGE:
Integer num1,num2
Input num1,num2
Integer k=0,final=num1
//missing statements
Print final
Choose the correct answer:
A pseudo-code is used which is self explanatory.
// in pseudo code refers to comment
Question
Reema wanted to multiply two numbers but the * key of her keyboard is
broken.she decides to write the program without using ^ operator. She writes the
given code,where some statements are missing.
What should be the missing statements in the given code?
1. While(k++ < num1)
final+=num1
2. While(k++ < num2-1)
Final+=num1
3. While(k++ <=num2)
Final+=num1
4. While (k++ < num2)
Final+=num2
Passage:
Function modify(y,z)
{
y=y+1;
z=z+1;
return y z
}
Function calculator()
{
Integer a=5, b=10, c
C=modify(a,b);
Print a
Print space
Print c
}
Consider the code given in the passage. Assume that a and b are passed by
value. What will the output of the program be when the function calculate() is
executed?
1. 11/05/15
2. 10/05/15
3. 06/05/15
4. 05/05/15-ans
A programmer wants the program given below to print the largest number out of
three numbers entered by the user:
Int number1,number2,number3,temp;
Input number1,number2,number3;
If(number1>number2)
temp = number1
else
temp = number2
end if
if(??) // statement1
temp=number 3
end if
print temp
which of the following should be substituted in place of ?? in statement 1 in
the code?
1.number3>number2
2. number3>temp
3. number3<temp
4. number3>number1
Question
Which of the following is not a data type
1. Integer
2. Character
3. Boolean
4. Array-ans
Question
Nalanda wants to implement virtual functions. which of the following options
will she have to following in order to bring out the same?
1. Dynamic dispatching
2. Static dispactching
3. Static binding
4. Anonymous class
Question
How can the largest number in a list of twenty numbers be found?
1. Use bubble sort to sort the list in a descending order and then print the first
number of the series
2. Use selection sort to sort the list in a descending order and then print the first
number of the series
3. Implement one iteration of selection sort for descending order and print the first
number in the series-ans
Question
What is the minimum numbers of stacks of size n required to implement a
queue of size n?
1. 1
2. 2
3. 3
4. 4
Question
Preeti writes a program in a low level language, now she wants to translate it
into a higher language without rewriting the program, what another program she
must use for this purpose?
1. Compiler-ans
2. Decompiller
3. Interpreter
4. Executer
5. Cross compiler
Question
Assume the following precedence (high to low). Operators in the same row have
the same precedence.
(.)
*/
+ AND
OR
The precedence is from left to right for the operators with equal precedence.
What will the output of the following code statements?
Integer a=50, b=25, c=5
Print a*b/c+c
1. 120
2. 125
3. 255
4. 250
Question
A programmer writes a program to find an element in the array A[5] With
elements 8 30 40 45 70. The program is run to find a number X, that is found
in the first iteration of binary search.what is the value of x?
1. 40-ans
2. 8
3. 70
4. 30
Question
How many nodes does a full binary tree with n non-leaf nodes contain?
1. log n
2. n + 1
3. 2n+1
4. 2n
Question
A programmer tries to debug a code of 10,000 lines. It is know that there is a
logical error in the first 25 lines of the code. Which of the following is an
efficient way to debug the code?
1. Compile the entire code and check it line by line
2. Use an interpreter on the first 25 lines of code-ans
3. Compile the entire code and run it
4. None of the above can be used to debug the code.
Passage
function main()
{
integer i=0.7
static float m =0.7
if (m equals i)
22
11-ANS
10
None of the above
Question;
A full binary tree with n non leaf nodes contains
(logn) nodes
n+1 nodes
2n+1 nodes ANS
2n nodes
Question ;
Ravi is writing a program in C++, C++ uses the for keyword for loops . Due to
distraction ,Ravi writes gor intead of for.What will this result to?
Insertion
Selection
Exchange
Deletion-ANS
Passage
class brush
{
private:
integer size ,c
rcode
function getdata(){..}//Statement1
public:
integer name//Statement2
function putdata(){.}
}
fuction main
{
brush b1,b2
printb1.name //Statement 3
b2.getdata()//Statement 4
}
Question;
Refer to the pseudocode given in the Passage . The code is similar to that in C++
and is self-explanatory. An accessible member function and a data member for an
object are accessed by statements objectname.functionname and
objectname.datamembername, respectively. Which statement should be deleted
from the code to rectify the eroor in it?
Statement 1
Statement 2
Statement 3
Statement 4-ANS
Question;
The program to print the sum of all cubes that lie between 0 and 100 is given below.
Does this program have an error? If yes ,which statement should be modified to
correct the program?
integer i=0,a //Statement 1
integer sum =0;
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
Statement 1
Statement 2 ANS
Statement 3
Statement 4
No error
Question ;
Which of the following data structures may produce an overflow error even though
the current number of elements in its lower than its size?
Question;
Function main is the starting point of execution of a program. Which of the
following option shall help in making an executable program without the use of
main function in the program?
Any function can be made and marked as starting point using a language
dependent syntax
Two macros can be used. One to hold the name of a function and its working and
the other to call the first macro-ANS
Any program without a main function shall not do anything but can only
produce a blank screen
Inheritance
Overriding ANS
Overloading
Encapsulation
Qusetion;
The function given below takes a number n as the input and calculates the sum of
first n naural numbers. Which of the following statements should be inserted in
place of ?? to get the required output?
function sum (n)
{
if (??)
return 1
else
return(n+sum(n-1))
end
}
n equals 1 ANS
n equals 2
n>=1
n>1
Question;
Which of the following algorithms is called the shortest-remaining-time-first
scheduling?
Question;
Which of the following option is not a necessary condition for Deadlock to occur?
Mutual exclusion
Hold and wait
No preemption
Circular wait
None of these-ANS
Question;
What will happen if some indentations are made in some statements of a code
written in C++?
Question;
Consider the code given in the Passage. Assume that a and b are passed by the
value. What wil be the output of the program be when the function calculate() is
executed?
80
40 ANS
32
72
Question;
Trisha wants to use a data structure in which the cost of deleting, adding and
traversing its elements is the same and constant. Which of the following data
structures should she use?
B -Tree
AVL Tree
Queue
Stack
Question;
The program to print the larger of the two numbers entered by the user is given
below. Which of the following should be substituted in place of ?? in Statement 1
of the code to get the desired output?
int number1, number2
input number1, number2
if (??) //Statement1
print number1
else
print number2
endif
Option;
number1>number2 ANS
number2>number1
number2 equals number1
number1<=number2
Passage:
integer i,k,j,n =5
for i=n to 1 decreament 1
{
for j=n to i+1 decreament1
{
print blanks pace
}
for k=1 to ((2*i)-1) increament 1
{
print*
}
print end-of-line //takes the cursor to the next line
}
Question;
What will be the output when the given code is executed?
a)*****
****
***
**
*
b)*****
****
***
**
*-ANS
C)*****
****
*****
****
*****
d)
*
**
***
****
*****
e)*********
*******
*****
***
Question;
Consider the given conditions in regards to binary search performed on an named
MyArray1.
2.
3.
Beg >end
Beg<=end
MyArray[mid]!= item_to_be_searched
Which of the given conditions forms the termination condition of an iterative binary
search when the variables Beg,End and mid have their usual meanings?
Only 1 ANS
Only 2
Only 3
Both 2 and 3
All 1,2 and 3
Question;
Assume the following procedure (high,low). Operators in the same row have the
same procedure.
(.)
*/
+AND
OR
The precedence is from the left to right in the expression for the operators with the
equal precedence,
Which of the following statements is TRUE about the output of the code statements
given below?
From pg num:37 to 46
Passage
function modify(y,z)
{
z=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
}
Question;
Consider the code given in the passage.assume thata and b are passed by
value .what will the output of the program be when the function calculate () is
executed?
11/05/15
10/05/15
06/05/15
05/05/15 (ans)
Question
How many nodes in a tree with n nodes have no ancestors?
0
1
2
Log n(ans)
Question
A programmer wants the program given below to print the largest number out of
three numbers entered by the user .
int number 1,number2,number3,temp;
input number1,number 2,number3;
if(number1>number2)
temp=number1
else
temp=number2
end if
if(??)//statement1
temp=number3
end if
print temp
which of the following should be substituted in place of ?? in statement 1 in
the code?
number3>number 2
number3>temp (ans)
number3<temp
number3>number1
question
A sorting mechanism uses the binary tree concept such that any number in the
tree is larger than all the numbers in the sub-tree below it . what is this method
called?
Selection sort
Insertion sort
Heap sort (ans)
Quick sort
Question
Which of the following implies that there are two loops that are nested?
Question
Which of the following can be inherited by a derived class from a base class?
Data members
Member functions
Constructors and destructors
Data members and member functions
(ans)
Question
Which of the given function prototypes can be considered to be overloaded (no
ambiguity)?
a.function myfunc (integer num, float me)// does not return anything
b.function myfunc(integer num, double me) //does not return anything
c.function myfunc(character num,float me) //does not return anything
d.function myfunc(integer num, float me )//returns an integer
A and B
A,B and C
A,C and D
B,C and D
Both 2 and 4
Question
Which of the following describes a tree ?
An unconnected graph
A connected graph
A connected acyclic graph
A complete graph
(ans)
Question
How many nodes does a full binary tree with n non leaf nodes contain?
log n
n+1
2n+1
2n
(Ans)
Question
What is the minimum number of stacks of size n required to implement a
queue of size n?
1
2 (ans)
3
4
Question
Two programmers independently write a program to find the mass of one mole
of water , that includes the masses of hydrogen and oxygen .
Question
X and Y are asked to write a program to sum the rows of a 2x2 matrix stored in
an array A.
X writes the code (code A) as follows:
for n=0 to 1
sum Row1[n]= A[n] +A[n][2]
end
Y writes the code (Code B) as follows:
sumRow1[0] =A[0][1] +A[0][2]
sumRow1[1] =A[1][1] +A[1][2]
which of the following statements is correct about these codes if no loop
unrolling is done by the compiler?
Code A would execute faster than Code B.
Code B would execute faster than Code A. (ANS)
Question
Which of the following abstract data type can be used to represent a many- tomany relation?
Tree
Stack
Graph (ans)
Queue
Question
For which of the following purposes is the construct given below used?
if (condition) then A else B
question :
A librarian has to rearrange the library books on a shelf in aproper order at the
end of each day. Which of the following sorting techniques should be the
librarians ideal choice?
Bubble sort
Insertion sort (ans)
Selection sort
Heap sort
Question:
W hich of the following sorting techniques has the worst case functioning time
less than O(n*n)?
Heap sort
Quick sort
Insertion sort
Selection sort
Passage:
Stack is useful for implementing.
Radix search
Breadth first search
Recursion (Ans)
None of these
Question:
What is the term given to the variable whose scope is beyond all the scopes
.i.e..,it can be accesses by all the scopes ?
Universal variable
Global variable (ans)
External variable
Auto variable
Both 2 and 3
Question:
Yashi wants to implement priority queues using arrays. What is the minimum
number of arrays that she should use to serve the purpose?
1
2 (ans)
3
4
Passage:
For solving a problem which of these is the first step in developing a working
program for it?
(ans)
Passage:
How can a call to an overload function to ambiguous?
By misspelling the name .
There might be two or more functions with the same name .
There might be two or more functions with equally appropriate signatures
(ans)
None of these
(ans)
Question :
Which of the following options is an exception to being a part of composite data
types?
Union
Array
Structure
Stack
(ans)
Question:
Which of the following options is both necessary and sufficient condition for
preparing binary search?
Array must be sorted,direct access to the middle element should be
provided. (ans)
Array should be in ascending order .
Direct access to the middle element must be provided.
Array should be sorted.
Question:
Which of the following statement is not true in the context of anonymous union
data type?
(ans)
Page no:47-56
Why is an algorithm concerned primarily about the run time and not the compile
time while calculating time complexity of an algorithm?
Two programmers independently write the program to find the mass of one mole
of water, that includes the masses of hydrogen and oxygen.
Parthiv has included several classes and their several objects in his projects.Now
he wants to use something that will hold all these objects(of different
classes).which one of the following option provides him with the best alternate?
In a linear list of elements , a deletion can be made from one end (front) and an
insertion can be made at the other end(rear).what is this linear list known as?
Queue (ans)
Stack
Tree
Branch
What is the first step for developing working program to solve a problem?
To write the program in the programming language
To write a step-by-step algorithm to solve the problem (ans)
Every element of an data structure has an address and a key associated with it. A
search mechanism deals with the two or more values assigned to the same
address by using the key . what is this search mechanism?
Linear search
Binary search
Hash code search (ans)
None of the above
How many nodes does a complete binary tree with 5 levels have , if the root is
considered to be at 1?
16
25
63
31 (ans)
Passage
Union myunion
{
Structure mystructure
{
Integer m;
Float n:
Character 0
} mystr
Integer p;
}myunion
Given that the size of integer is 2 units , float is 4 units character is 1 unit , what
will be the amount of memory occupied by the myunion object?
2 units
6 units
7 units
9 units (ans)
Insertion
Selection
Exchange
Deletion (ans)
Which one the following gives the maximum nodes at level I of a binary
tree ?
2I-1 (ans)
3I-1
2I
2I-1
The function given below takes a number n as the input and calculate the sum
of first n natural numbers . which one the following statements should be
inserted in place of ?? to get the required output ?
Function sum(n)
{
If(??)
Return 1
Else
Return (n+sum(n+1))
End
}
N equals 1 (ans)
N equals 2
n>=1
n>1
Which one of the following implies that there are two loops that are nested?
Two loops , one after another
Passage
Fun mybinarysearch(array arr , integer low , integer high , integer item)
{
If( low >high )
{
Return -1
}
Integer mid =(low + high )/2
If(arr[mid]= equals item)
{
Return mid
}
Elseif (arr[mid]>item)
{
Return
}
Else
{
Return
}
Harshul uses the given code to implement the binary search respectively . find
the statement that will replace missing statement 1 in the given code such that it
works efficiently ?
Int number1,number2
Input number1,number2
If(??)
print number1
else
print number2
end if
number1>number2 (ans)
number2>number1
number1=number2
number1<=number2
A programmer writes a program to find an element In the array A[5] with the
elements : 8 30 40 45 70 . the program is run to find the number x that is
found in the first iteration of binary search . what is the values of x?
40 (ans)
8
70
30
Passage
Class brush
{
Private:
Integer size , c
Rcode
Function getdata ()
Public:
Integer name
Function putdat ()
}
Function main
{
Brush b1, b2
Printb1.name
B2.getdata
}
Refer to the pseudocode given in the passage . this code is similar to that in c++
and ic self-explanatory . an accessible member function and a data member for
an object accessed by the statements object name .function name and
objectname.datamembername respectively . which statement should be deleted
from the code to rectify the error in it ?
Statement 1
Statement 2
Statement 3
Statement 4 (ans)
The function given below takes the number n as the input and calculate the
sum of first n natural number . which one of the following statement should be
inserted in place of ?? to get the required output?
Function sum(n)
{
If(??)
Return 1
Else
Return (n+sum(n-1))
End
}
N equals 1
N=2
n>=1
n>1
passage
function preordertraverse (node)
{
Printnode
If (condition x)
{preordertransverse(node left)}
If (condition y)
{preordertransverse(node right)}
Return }
}
Print end-of-line //takes the cursorto the next line
I=i+1
}
a) 0
0 3 (ans)
b) 0 3
036
c) 0
036
0369
d) 0 3 6
0369
0 3 6 9 12
What will the output of the following pseudo code statements be?
(Note: Assume that when two data types are processed through an
operator.the answer maintains the same data type as that of the input.Also
all the data types have enough range to accommodate any number.if two
different datatypes are operated upon,the result assumes the data type that
is more expressive.)
Integer a=456,b,c, d=10
b= a/d
c= a-b
print c
a) 410
b) 410.4
c) 411.4
d) 411(ans)
The function given below takes a number n as the input and calculates
the sum of the first n natural numbers. Which of the following statements
should be inserted in place of?? to get the required output?
Function sum (n)
{
if (??)
return 1
else
return (n+ sum (n-1))
end
}
a)
b)
c)
d)
n equals 1 (ans)
n equals 2
n>=1
n>1
Integer
Boolean(ans)
Float
Character
A sorting mechanism uses the binary tree concept such that any number in
the tree is larger than all the numbers in the sub-tree below it. What is this
method called?
a)
b)
c)
d)
Selection sort
Insertion sort
Heap sort (ans)
Quick sort
Refer to the pseudo code given in the passage. The code is similar to that
in C++ and is self-explanatory. An accessible member function and a data
member for an object are accessed by the statements
objectname.functionname and objectname.datamembername, respectively.
Which statement should be deleted from the code to rectify the error in it?
Class brush
{
Private:
Integer size,c
rcode
function getdata(){..}//statement 1
public:
integer name//statement 2
function putdata(){.}
}
Function main
{
Brush b1, b2
Print b1. Name //statement 3
B2.getdata()//statement 4
}
a) statement 1`
b)statement 2
c)statement 3
d) statement 4(ans)
How many nodes does a full binary tree with n leaves contain?
a)
b)
c)
d)
2n+1 nodes
Log2n nodes
2n-1 nodes (ans)
2n nodes
Which of the following data structures may produce an overflow error even
though the current number of elements in it is lower than its size?
a)
b)
c)
d)
The function given below takes a number n as the input and calculates
the sum of the first n natural numbers. Which of the following statements
should be inserted in place of?? to get the required output?
Function sum (n)
{
if (??)
return 1
else
return (n+ sum (n-1))
end
}
a)
b)
c)
d)
n equals 1 (ans)
n equals 2
n>=1
n>1
A programmer writes a code snippet in which a set of three lines occurs ten
times in different parts of the program. When programming concept should
be used to shorten the code length?
a)
b)
c)
d)
For loops
Functions (ans)
Arrays
Classes
Refer to the pseudo code given in the passage. The code is similar to that
in C++ and is self-explanatory. An accessible member function and a data
member for an object are accessed by the statements objectname,
functionname and objectname, datamembername, respectively, what can be
inferred from this code?
Class rocket
{
Pivate:
Integer height,weight
Public: //statement 1
function input(int a , int b)
{
height=a;
weight=b;
}
}
function main ()
{
Rocket rocket1,rocket2
}
a) rocket is a class with rocket 1 and rocket 2as its objects. With
height and weight as its attributes.(ans)
b) rocket is a class with rocket 1 and rocket 2as its objects. With
height and weight as its objects.
c) rocket is a class with rocket 1 and rocket 2 height and weight
as its attributes.
d) rocket is a class with rocket 1 and rocket 2 height and weight
as its objects.
A programmer prepares a questionnaire with true or false type of
questions. He wants to define a data type that stores the responses of the
candidates for the questions. Which of the following is the most suited data
type for this purpose?
a) Integer
b) Boolean(ans)
c) Float
d) Character
Two programmers independently write a program to find the mass of one
mole of water that includes the masses of hydrogen and oxygen.
The first programmer defines the variables as:
Integer hydrogen, oxygen, water//code A
The second programmer defines three quantities as:
Integer a, b, c //code B
Which of the two is a better programming practice and why?
a) Code B is better because variable names are shorter .
b) Code A is better because the variables names are understandable and
non-confusing.(ans)
c) Code A would run correctly while code B`would give an error.
d) Code B would run correctly while Code A would give an error.
}
Return top
}
Which of the following should substitute the condition X?
a)
b)
c)
d)
Top<N-1
Top<N
Top>1
Top>=0(ans)
A function in the base class is redefined in the inherited class. What is the
term used to describe this situation?
a)inheritance
b)overriding(ans)
c)overloading
d) encapsulation
In which of the following situations can a constructor be invoked?
a)
b)
c)
d)
candidates for the questions. Which of the following is the most suited data
type for this purpose?
a)
b)
c)
d)
Integer
Boolean(ans)
Float
Character
A programmer wants the program givren below to print the largest number out
of three numbers entered by the user.
int number1, number2, 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
Which of the following ashould be substituted in place of ?? in the ststement 1
in code?
a)
b)
c)
d)
number3>number2
number3>temp (ans)
number3<temp
number3>number1
The programmer mistakenly writes gor instead of the keyword for used in
loops, while writing a program in C++. What will this result in?
a)
b)
c)
d)
Why is an algorithm designer concered primarily about the run time and not the
compile time while calculating time complexity of an algorithm?
a)
b)
c)
d)
Integer
Boolean
Float
Character
Why is an algorithm designer concered primarily about the run time and not the
compile time while calculating time complexity of an algorithm?
a)
b)
c)
d)
Passage
class brush
{
private:
integer size,c
rcode
function getdata() {..}//Statement 1
public:
integer name//Statement 2
function putdata(){.}
}
function main
{
brush b1,b2
print b1.name //Statement 3
b2.getdata() //Statement 4
}
Refer to the pseudocode given in the Passage. The code is similar to that in
C++ and is self-explanatory. An accessible member function and a data member
for an object are accessed by the statements objectname.functionname and
objectname.datamember name, respectively. Which statement should be deleted
from the code to rectify the error in it.
a) Statement 1
b) Statement 2
c) Statement 3
d) Statement 4
Which of the following gives the maximum number of the nodes at level I of a
binary tree?
a)
2I-1
b)
3I-1
c)
2I
d)
2I 1
Which of the following atatements is TRUE about a breadth first search?
a) Beginning from a node, all the adjacent nodes are traversed first. (ans)
b) Beginning from a node, each adjacent node is fully explored before
traversing next adjacent node.
c) Beginning from a node, the nodes are traversed in cyclic order.
d) None of the above.
The programmer prepares a questionnaire with true or false type of questions.
He wants to define a data type that stores the response of the candidate for the
questions. Which of the following is the most suited data type for this purpose?
a) Integer
b) Boolean
c) Float
d) Character
Why is an algorithm designer concered primarily about the run time and not the
compile time while calculating time complexity of an algorithm?
a)
b)
c)
d)
Integer
Boolwan (ans)
Float
Character
Two programmers independently write a program to find the mass of one mole
of water, that includes the masses of oxygen and hydrogen.
The first programmer defines the variables as:
What is the first step for developing a working program to solve a problem?
a)
b)
c)
d)
Which of the following algorithm design techniques is used in the quick short
algorithm?
a)
b)
c)
d)
Dynamic programming
Back tracking
Divide and conquer
Greedy search
The function given below takes a number n as the input and calculates the sum
of first n natural numbers. Which of the following statements should be
insertedin place of ?? to get the required output?
function sum(n)
{
if(??)
return 1
else
return (n+sum (n-1))
end
}
a)
b)
c)
d)
n equals 1 (ans)
n equa;s 2
n>=1
n>1
A programmer writes a code snippet in which a set of three lines occurs ten
times in different parts of the program. What programming concept should be
used to shorten the code length?
a)
b)
c)
d)
For loops
Functions
Arrays
Classes
Data members
Member functions
Constructor and destructor
Data members and member functions
c) Implement one iteration of selection sort for descending order and print the
first number in the series (ans)
d) None of the above
Assume the following precedence (high to low). Operaters in the same row
have the same precedence
(.)
*/
+AND
OR
The precedence is the from the left to right in the expression for the
operators with equal precedence.
Which of the following statements is TRUE about the output of the code
statements given below?
Integer a = 40, b = 35, c = 20, d=10
Print a*b/c-d
Print a*b/(c-d)
a)
b)
c)
d)
Data members
Member functions
Constructors and destructors
Data members and member function (ans)
How many nodes does a full binary tree with n leaves contain?
a)
b)
c)
d)
2n+1 nodes
Log2n nodes
2n-1 nodes (ans)
2n nodes
Insertion sort
Heap sort
Quick sort
Bubble sort (ans)
Which of the following is the lowest level format to which the computer
converts a program in a higher language before execution?
a)
b)
c)
d)
English code
Machine code (ans)
Assembly language
System language
a)
b)
c)
d)
Radix search
Breadth first search
Recursion (ans)
None of the above
The function given below takes an even integer n as the input and
calculates the sum of first n even natural numbers. The function is called
by the statement sum (30). How many times will the function sum be
called to compute the sum?
Function sum(n)
{
If (n equals 2)
Return 2
else
return (n+ sum(n-2))
end
}
a)
b)
c)
d)
1
30
15 (ans)
16
A developer writes the program given below to print the sum of the first five
whole numbers (04). Is the program correct? If not, which statement
should be modified to correct the 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
a)
b)
c)
d)
An unconnected graph
A connected graph
An connected acyclic graph--A
A complete graph
Which of the following can be inherited from derived class to base class?
Data members
Member functions
Constructors and destructors
Data members and member functionsA
1. Bubble sort
2.Insertion sort---A
3.Selection sort
4.Heap sort
A programmer is making a database of animals in zoo along with their
properties. The possible animals are dog, lion and zebra. Each one has attributes
as herbivores, color and nocturnal. The programmer uses the object-oriented
programming paradigm for this. How will the system be conceptualized?
1.Class: Animal, objects: dog, lion and zebra; data members; herbivores, color
and nocturnal---A
2.Class: Animal; objects: herbivorous, color and nocturnal; data members : dog,
lion and zebra
3.Classes: dog, lion and zebra; objects: Animal; data members: herbivorous,
color and nocturnal
4.None of the above
Which of the following implies that there are two loops that are nested?
1.Two loops, one after the other
2.Two loops, one inside the other--A
3.One loop with two different iterations counts
4.Two loops with same iteration count
Which of the following sorting algorithms yield approximately the same worstcase and average-case running time behavior in 0(n log n)?
1.Bubble sort and selection sort.
2.Heap sort and merge sort.--A
3.Quick sort and radix sort.
4.Tree sort and median of 3 quick sort.
Srujan writes a sorting algorithm. The algorithm takes different amount to sort
two different lists of equal size. What is the possible difference between the two
lists?
1.All number in one list are more than 100, while in the other are less than 100.
2.The ordering of numbers with respect to magnitude in two list has different
properties.--A
3. One list has all negative numbers, while the other has all positive numbers.
4.One list contains 0 as an element, while the other does not.
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.
n equals 1--A
n equals 2
n>=1
n<1
height =a;
weight=b;
}
}
Function main()
{
Rocket, rocket 1, rocket2
}
What can we infer from this code?
Rocket is a class with rocket 1 and rocket2 as its objects. Height and
weight are attributes of rockets.--A
Rocket is a class with rocket1 and rocket2 as its attributes. Height and
weight are objects of the class rocket.
Rocket is a class with rocket1, rocket2, height and weight as its attributes,
Rocket is a class with rocket1, rocket2. Height and weight as its objects.
Himanshu wants to write a program to print the larger of the two inputted
number. He writes the following code:
Int number1,number2
Input number1,number 2
If(??) //statement 1
Print number 1
Else
Print number 2
End if
Top<N-1
Top
Top>1
Top>=0--A
Srishti writes a program to find an element in the aray A{5} with the following
elements in order: 8 30 40 45 70. She runs the protam to find a number X. X is
found in the first itertation fo binary search. What is the value of X?
40--A
8
70
30
Before it is declared--A
After it is declared
In the function it is declared in
Can always be used
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?
Faster execution
Lower memory requirement
Correction of errors
Better readability--A
Integer
Boolean--A
Float
Character
Mary is making a database of animals in a zoo and their properties . The possible
animals are dog. Lion and zebra. Each one has an attributes is herbivorous,
color and is Nocturnal. She uses the object oriented programming paradigm for
this. How will she conceptualize the system?
Class: animal: objects: dog, lion and zebra; data members : is herbivorous,
color and isNocturnal--A
Class animal; objects; isherbivorous,color and isNocturnal; data
members : dog, lion and zebra
Classes: dog,lion and zebra; objects; animal; data members:
isHerbivorous, color and isNocturnal
None of these
Sharmili wants to make a program to print all the sum of all cubes, where the
values of the cubes go from 0 to 100. She writes the program:
Integer i=0,a //statement 1
Integer sum=0;
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 statements will you modify to
correct the program?
Statement 1
Statement2--A
Statement 3
Statement 4
Insertion
Selection
Exchange
Deletion--A
Dynamic programming
Back tracking
Divide and conquer--A
Greedy search.
Mutual exclusion
Hold and wait
No preemption
Circular wait
None of these
Which one of the following is the lowest level format to which the computer
converts a higher language program before execution?
English code
Machine code--A
Assembly language
System language
Ravi is writing a program in c++. C++ uses the keyword for loops due to
distraction. Ravi writes gor instead of for. What will this result to?
A complete binary tree with 5 levels has how many nodes?(Root is level 1)
15
25
63
31--A
PUSH(6)
POP
Ravi is writing a program in c++. C++ uses the for keyword for loops. Due to
distractions, ravi writes gor instead of for. What will this result to?
Srujan writes a sorting algorithm. The algorithm takes different amount of time
to sort two different lists of equal size. What is the possible difference between
the two lists?
All the numbers in one list are more than 100, while in other are less
than 100.
The ordering of numbers with respect to magnitude in the two list has
different properties.--A
One list has all negative numbers, while the other has all positive
numbers.
One list contains 0 as an element, while the other does not.
2^(I-1) (ans)
3^(l-1)
2^(l)
2^(I)-1
Afzal writes a piece of code where a set of 3 lines occur around 10 times in
different parts of the program.What programming concept can he use to shorten
his program code length?
Before it is declared(ans)
After it is declared
In the function it ids declared in
Can always be used
Pragya sells footballs. She has a large container to store footballs which is closed
from below.Footballs are piled one on top of other in a box. Where new balls are
supplied,Pragya puts the balls in the box from the top.When a customer buys a
ball she delivers it at the top of the puile to the customer.Each ball has a
code.She wants to store the ball codes in a data structure to keep track of her
inventory.What data structure must she use?
Queue
Stack(ans)
Array
Graph
In breadth-first search,which of the following options is truie?
Beginning from a node , first all its adjacent nodes are traversed(ans)
Beginning from a node , each adjacent node is fully explored before
traversing the next
Beginning from a node, nodes are traversed cyclically
None of these
Consider a binary tree representation.The root address is is stored in the variable
root. Given the address of a node in variable node.Its value ,right and the root
child node address can be accessed using following atatements respectively.node
-> value, node->right, node->left. Srikanth writes the following function to do a
preorder traversal of the tree.
Function preordertraverse(node)
{
Print node->value
If (condition X)
{preordertraverse(node->left)}
If (condition Y)
{preordertraverse(node->right)}
Return
}
Condition X: node->left isnotequal null
Condition Y :node-> right isnotequal null (ans)
Condition X:node-> right isnotequal null
Condition Y: node->left isnotequal null
Use bubble sort to sort the list in descending order and then print first
number of the series
Use selection sort to sort the list in descending order and print first
number in the series
Implement one iteration of selection sort for descending order and print
first number of the series(ans)
None of these
Faster execution
Lower memory requirement
Correction of errors
Better readability(ans)
Input num1,num2
If(??)// statement 1
Print num1
Else
Print num2
Endif
Fill in the (??)
Num1>num2(ans)
Num2>num1
Num2=num1
Num1<=num2
In which area of a class are data and function directly accessible outside the
class?
Public(ans)
Private
Protected
None of these
Faster execution
Lower memory requirement
Correction of errors
Better readability(ans)
Every element of a data structure has an addresss an a key associated with it.A
search mechanism deals with 2 or more values assigned to the same address by
using the key. What is this search mechanism?
Linear search
Binary search
Insertion
Deletion(ans)
Selection
Exchange
Radix search
Breadth first search
Recursion(ans)
None of these
Tanuj writes the code for a function that takes an input n a nd calcutes the sum of
first n natural numbers.
Function sum(n)
{
If(??)
Return 1
Else
Return(n+sum(n-1))
End
}
N equals 1(ans)
N equals 2
n>=1
n>1
Faster execution
Lower memory requirement
Correction of errors
Better readability(ans)
What is the term given to the variable whose scope is beyond all scopes? Ie. It
can be accessed by all scopes.
Universal variable
Global variable(ans)
External variable
Auto variable
Both 2 and 3
Dynamic programming
Back tracking
Divide and conquer(ans)
Greedy search
In an implementation of a linked list , each node has data and address. Which of
the following could the address field possibly contain?
1
2(ans)
3
4
Before declaring(ans)
After declaring
In the function it is declared in
Can always be used
410
410.4
411.4
411(ans)
A derived class may inherit from the base class which of the following?(consider
assumptions as c++)
Data members
Member functions
Constructors and destructors
Both data members and member functions(ans)
Tanuj writes the code for the function that takes as input n and calculate 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
n equals 1(ans)
n equals 2
n>=1
n>1
shrishti writes the code for a function that computes the factorial of the inputted
number n.
function factorial(n)
{
if(n equal1)
return1
else
-MISSING STATEMENTEnd
}
Fill in the missing statement
Return factorial(n-1)
Return n*factorial(n)
Return n*(n-1)
Return n*factorial(n-1)(ans)
integer
boolean(ans)
float
character
pragya sells footballs.she has a large container to store footballs which is closed
from below. Footballs are piled one on top of the other in the box.When new
balls are supplied,Pragya puts the balls in the box from the top.When customer
buys a ball,she delivers the ball at the top of the pile to the customer.Each ball
has a code,She wants to store the ball codes in a data structure to keep track of
the inventory.What data-structure should she use?
Queue
Stack(ans)
Array
Graph
Assume the following precedence (high to low).Operators in the same row have
the same precedence:
(.)
*/
+AND
OR
For the 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)
Differ by 80(ans)
Same
Differ by 50
Differ by 160
A member function(ans)
An operator
A class function
A method
Which of the following accessibility modes can be the specifier of a top level
class?
1.private
2.protected
3.public
4.No modifier
Only 3(ans)
Only 4
Both 1 and 3
Both 2 and 3
Both 3 and 4
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 options will
be an efficient way of debugging?
Tanuj writes the code for a function that takes as input n and calculates the sum
of first n natural numbers.
Function sum(n0
{
If(??)
return 1
else
return (n+sum(n-1))
end
}
Fill ?? in the code
n equals 1 (ans)
n equals 2
n>=1
n>1
Linear search
Binary search
Hash coded search (ans)
None of these
Queue (ans)
Stack
Tree
Branch
A complete binary tree with 5 level has how many nodes?(Root is level 1)
15
25
63
31 (ans)
Zenab and shashi independently write a program to find 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?
Code B is better because variable names are shorter
Code A is better because the variable names are understandable and nonconfusing(ans)
For solving a problem, which of these is the first step in developing a working
program for it?
Which of the following data types does not belong to the category of abstract
data types?
Hashtable
Set
Object (ans)
Soting is not possible by using which of the following methods?
Insertion
Selection
Exchange
Deletion (ans)
Dynamic programming
Back tracking
Divide and conquer(ans)
Greedy search
Assume the following precedence (high to low). Operators in the same row have
the same precedence.
(.)
*/
+AND
OR
The precedence is from left to right in the expression for the operators with
equal precedence.
Which of the following statements is TRUE about the output of the code
statements given below?
Integer a=40,b=35,c=20,d=10
Print a*b/c-d
Print a*b/(c-d)
If(x)
{
Top= top-1
}
else
{
Printunderflow
Which of the following should substitute the conditionX?
top<N-1
top<N
top>N
top >=0(ans)
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
Selection sort
Insertion sort
Heap sort( ans)
Quick sort
In which area of class are data and function directly accessible outside the class?
Public(ans)
Private
Protected
None of these
Data in private and protected area of a class is not directly accessible and
can only be accessed through member functions in the public area of the
class.(ans)
A single class can have many objects.
Which of the of the following is the lowest level format to which the
computer converts a program in a higher language before execution?
English code
Machine code (ans)
Assembly language
System language
Insertion sort
Heap sort
Quick sort
Bubble sort(ans)
1
1
1
1
101
101
010
010
10101(ans)
10101 1010101
10101
10101 1010101
Afzal writes a piece of code, where a set of three lies occur around 10 times in
different parts of the program.what programming concept can he use to shorten
his program code length?
1.Beg>End
2.Beg<=End
3.MyArray[mid}!=item_to_be_searched
Which of the given conditions forms the termination condition of an iterative
binary search function when the variables Beg.End and mid have their usual
meanings?
Only 1(ans)
Only2
Only 3
Both 2and 3
If(n equals 1)
Return 1
Else
Missing statement
End
}
Return factorial(n-1)
Return n*factorial(n)
Return n*(n-1)
Return n*factorial(n-1)(ans)
Assume the following precedence(high to low).operators in the same row have
the same precedence.
(.)
*/
+ AND
OR
The precedence is from left to right for the operators with equal precedence.
What will be the output of the following code statements?
Integer a=50, b=25,c=5
Print a*b/c/c
120
125
255(ans)
250
Preeti writes a program in a low level language,now she wants to translate it into
a higher language without rewriting the program.what another she must use for
this purpose?
Compilier(ans)
Decompiler
Interpreter
Executer
Cross compilier
Queue(ans)
Stact
Tree
Branch
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?
Linear search
Binary search
Hash coded search(ans)
None of the above
What is the first step fordeveloping a working program to solve a problem?
15
26
63
31(ans)
Tow programmers independently write a program to find the mass of one mole
of water ,that include sthe masses of hydrogen and oxygen
The first programmer defines the variables as:
Integer hydrogen,oxygen,water//code A
The second programmer defines three quantities as :
Integer a, b, c //code B
Which of the two is a better programming practice and why?
Code B is better because4 variable names are shorter
Code A is better because the variable names are understandable and nonconfusing(ans)
codeA would non correctly while code B would give an error
codeB would run correctly while code A would give an error
Raj has a list of n numbers each of a fixed size*he sorts them using radix sort
technique. Which of the following options gives the complexity of this
operation?
O(n-k)
O(nk)(ans)
O(k log n)
K o(log n)
Why is an algorithm designer concerned primarily about the run time and not the
compile time while calculating time complexity of an algorithm?
Insertion
Selection
Exchange
Deletion(ans)
Which of the following algorithm design techniques is used in the quick sort
algorithm?
Dynamic programming
Back tracking
Divide and conquer(ans)
Greedy search
410
410.4
411.4
411(ans)
Function display(string mystr) //statemtnt 1
{
PrintHello My name is
Print Mystr //statement 2
}
Function main()
//statement3
{
String str=mr.beans
Integer num=display(str) //statement 4
}
Consider the given code to print a name on the screen.which statement will
generate an error?
Statement 1
Statement 2
Statement 3
Statement 4(ans)
return 1
else
return(n+sum(n-1))
end}
n equals 1(ans)
nequals 2
n>=1
n>1
integer a=40,b=35,c=20,d=10
comment about the output of the following two statements:
print a*b/c-d
printa*b/(c-d)
assume the following precendence(high to low) operators in the same row have
the same precedences:
()
*/
+AND
OR
For operators with equal precedence the precedence is fromleft to right in
expression.
Differ by 80(ans)
Same
Differ by 50
Differ by 160
Insertion
Selection
Exchange
Deletion(ans)
Which of the following statements is true about the logical view of a database?
It is also known as physical view and there can be one or more logical
views of a database
It is also known as physical view and ter is only one logical view of a
database
It is also known as conceptual view and there can be one or more logical
views of a database
It is also known as conceptual view and there is only one logical view of a
database
Srujan writes a sorting algorithm takes different amount of time to sort two
different lists of equal size.what is the possible difference between the two lists?
All numbers in one list are more than 100.while in the other are less than
100.
The ordering of numbers wit respect to magnitude in the two list has
different properties.(ans)
One list has all negative numbers,while the other has all positive numbers.
One list contains 0 as an element,while the other does not.
Radix search
Breadth first search
Recursion(ans)
None of these
Mary is making database of animals in a zoo and their properties. The poosible
animals are dog,lion and zebra.each one has a attributes in herbivorous,colour
and is nocturnal.she uses the object oriented programming paradigm for this.
How will she conceptualize the system?
Class: animal; objects:dog,lion,zebra; data members:herbivorous,colour,
nocturnal(ans)
Class: animal; objects:herbivorous,colour,nocturnal; data
members:dog,lion,zebra
Class: dog,lion,zebra; objects:animal; data members:herbivorous,colour,
nocturnal
None of these
Only 1
Only 2
Both 1 & 2
Both 2 & 3
All-1,2,3(ans)
Stuti is making a questionaire of true-false questions.she wants to define a datatype which stores the response of the candidate for the question.what is the
most-suited data type for this purpose?
Integer
Boolean(ans)
Float
Character
Zenab and shashi independently write a program to find 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?
Code b is better because variable names are shorter
Code a is better because the variable names are understandable and nonconfusing(ans)
Code a will run correctly,while code b will give an error
Code b will run correctly,while code a will give an error
Statement 1
Statement 2
Statement 3
Statement 4(ans)
Passage:
Class rocket
{
Private:
Integer height,weight
Public://statement 1
Function input(int a,int b)
{
Height =a;
Weight =b;
}
}
Function main()
{
Rocket1,rocket2
}
Refer the psuedocode given in the passage.the code is similar to that in c++ and
is self explanatory . an accessible member function and a data member for an
object are accessed by the statements objectname.functionname and
objectname.datamembername, respectively.what can be inferred from this code?
The program to print the larger of the two numbers entered by a user is given
below. which of the following should be substituted in place of ?? in statement
1 of the code to get the desired o/p?
Int number 1, number 2
Input number1,number2
If(??)//statement1
Print number1
Else
Print number2
End if
Number1>number2(ans)
Number2>number1
Number2=number1
Number1<=number
Each node in a doubly linked list contains the following parts except which one
of the following?
Header(ans)
Address of preceding element
Address of succeeding element
Information of the code
In which of the following areas of a class are data and functions directly
accessible outside the class?
Public(ans)
Private
Protected
None of the above
The functions given below computes the factorial of the number n entered by
a user . what should be the MISSING STATEMENT in order to make the code
work properly?
Function factorial(n)
{
If(n=1)
Return 1
Else
--MISSING STATEMENT
End
}
Return factorial(n-1)
Return n*factorial(n)
Return n*(n-1)
Return n*factorial(n-1)(ans)
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
}
Consider the code given in the passage.assume that a&b are passed by value.
What will the o/p of the program be when the function calculate() is executed?
80
40(ans)
32
72
A football seller stores all the footballs in a large container that Is closed from
the bottom. The footballs are stacked on top of each other in the box. The new
supply of balls is put in the box from the top. When a customer buys a football,
the one at the top of the stack is given to the customer. Each football has a code.
The seller wants to store the codes of the footballs in a data structure to keep
track of the inventory. Which data structure should be used for this purpose?
Queue
Stack(ans)
Array
Graph
Function sum(n)
{
If(??)
Return 1
Else
Return{n+sum(n-1)}
End
}
Fill in ?? in the code
n=1(ans)
n=2
n>=1
n>1
(log n) nodes
n+1 nodes
2n+1 nodes(ans)
2n nodes
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?
Insertion sort
Heap sort
Quick sort
Bubble sort(ans)
There are 2 loops which are nested. This implies which one of the following?
Integer
Boolean(ans)
Float
Character
Group a
Group b
A.distance
vector interior
routing
protocol
1.open shortest
path first(OSPF)
B.distance
vector
exteriorrouting
protocol
2.enhanced
interior gateway
routing
protocol(EIGRP)
C.link state
interior
routing
protocol
3.routing
information
protocol(RIP)
D.hybrid
interior
4.border
gateway
routing
protocol
protocol(BGP)
Match the given routing strategies in group A with their example in group B
A-1,B-2,C-3,D-1
A-1,B-4,C-2,D-3
A-3,B-4,C-1,D-2
A-4,B-3,C-1,D-2
Zenab and shasi independently write a program to find the mass of one mole of
water,which includes mass of hydrogen and oxygen.zenab defines the variables
into per hydrogen ,oxygen,water// code A
While shashi defines the three quantities as:
Integer a,b,c//code B
Which is the better programming practiceand why?
Code B is the better because variable names are shorter
Code A is better because the variable names are understandable and non
confusing(ans)
Code Awil rin correctly,while code B wil give an error
Code Bwil rin correctly,while code A wil give an error
Ravi and Rupali are asked to write a program to sum the rows of a 2*2 matrices
stored in the array A.
Ravi writes the following code(codeA):
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 (assumeno loop unrolling done by complier):
top
top>1
top>=0
Smriti awnts to make a program to print the sum of a square of the first %
wholenumbers(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 wil you modify to correct it?
Choose the correct ans:
Afzal writes a piece of code,where a set of three lines occur around 10 times in
different parts of the program.what programming conc ept can he use to shorten
his [program code length?
Choose the correct ans:
How many nodes does a complete binary tree with 5 levels have,if the root is
considere to be at level 1?
15
25
63
31(ans)
Queue(ans)
Stack
Tree
Branch
What is the first step for developing a working program to solve a problem?
To write the program in the programming language
To write a step-by-step alogrithm to solve the problem(ans)
To compile the required libraries
To debug the code
Consider the given list of sorting algorithms1.selection sort
2.radix sort
3.shell sort
4.heap sort
Which of the above mentioned algorithms uses the selection method for bringing
out the sorting?
Only 1(ans)
Only 3
Both 1 ana 4
Both 2 and 3
Both 2 and 4
Two programmers independently write a program to find the mass of one mole
of water ,that includes the masses of hydrogen and oxygen
The first programmer defines the variables as:
Integer a,b,c //code A
The second programmer defines three quantities as;
Integer a,b,c //code B
Which of the two is a better programming practise and why?
Code Bis better than because variable names are shorter
Code Ais better because the variable names are understandable and non
confusing(ans)
Code A would run correctly while code B would give an error
Code B would run correctly while code A would give an error
In which of the following methods is sorting NOT possilble?
Insertion
Selection
Exchange
Deletion(ans)
Every element of a data structure has an address and a key associated with it.A
search mechanism deals with 2 ior more values assigned to the same address by
using the key.what is the search mechanism?
Linear search
Binary search
Hash coded search(ans)
None of the above
Function MyFunc1(integer n)
{
return n*2
}
Function MyFunc2(integer n0
{
Printthe values is n
}
A pseudo code is used which is self explanatory.
Which of the given 2 functions can be categorized as procedues?
MyFunc 1
MyFunc2
Both MyFunc1 and MyFunc2
A function cannot be a procedure
In which of the following cases .doubly linked list are preferred over singly
linked list?
Searching an item in an unsorted list
Traversing a list
Deleting a node whose location is given (ans)
Interchanging 1 nodes
The program to print the larger of the 2 numbers entered by a user is given
below.which of the following should be substituted in place of ??
Int number1,number2
Input number1,number2
If(//)//statement 1
Print number 1
Else
Print number2
Endif
Number1>number2(ans)
Number 2>number1
Number2 equals number 1
Number1<=number2
A programmer writes a snippet in which a set of three lines occurs ten times in
different parts of the program .what programming concept should be used to
shorten the code length?
For loops
Functions(ans)
Arrays
Classes
The function given below takes number n as the input and calculate the sum of
first n natural numbers.which of the following statements should be inserted in
place of ?? to get the required output?
Function sum(n)
{
If(??)
Return 1
Else
Return(n+sum(n-1)
End
}
n equals 1(ans)
n equals 2
n>= 1
n>1
which of the following options gives the lower bound on running time for an
algorithm?
Best case complexity of the algorithm
Average case complexity of the algorithm
Worst case complexity of the algorithm
Number of iterations taking place in the algorithm
Assume the following precedence (high to low).operations in the same row have
the same precedence.
(.)
*
+ AND
OR
The precedence is from left to right in the expression for the operators with
equal precedence.
Which of the following statements is TRUE about the output of the code
statement given below?
Integer a=40,b=35,c=20,d=10
print a*b/c-d
print a*b/(c-d)
A sorting mechanism uses the binary tree concept such that any number in the
tree is larger than all number in the subtree below it . what is the method called?
Selection sort
Insertion sort
Heap sort(ans)
Quick sort
56
1 5(ans)
56
15
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 the search mechanism?
Linear search
Binary search
Hash coded search(ans)
None of the above
A programmer mistakenly writes gor instead of the key word for used in
loops, while writing a program in c++ . what will this result in?
Tricha needs to store a list of binary data. Which of the following data types
should she use?
Integer
Float
Character
Boolea(ans)
Why is an algorithm designer concerned primarily about the run time and not the
complie time time while calculating time complexity of an algorithm?
Which of the following is the lowest level format to which the computer
converts a program in a higher language before exacution?
English code
Machine code(ans)
Assembly language
System language
What is the name given to the function which has no memory or i/o side effects
>
Pure function(ans)
Subroutine
Procedure
Method
Find out the index of an empty hash table where a key with value 25 needs to be
inserted using quadratic probing with c1=1,c2=9. The size of table is 5 and
primary hash function used is(k mod m)where k=key,m=size of hash table.
0(ans)
1
15
Data insufficient
What will happen if some indentations arte made in some statements of a code
written in c++?
Faster execution of the code
Lower memory requirement for the code
Corrections of errors in the code
Better readability of the code(ans)
Which of the following accessibility modes can be the specifier of a top level
class?
1.private
2.protected
3.public
4.no modifier
Only 3(ans)
Only 4
Both 1and 3
Both 2 and 3
Both 3 and 4
Integer
Boolean(ans)
Float
character
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
}
Consider the code given in the passage . assume that a and b are passed by
value . what will the output of the program be when the function calculate() is
executed?
80
40(ans)
32
72
How many nodes does a complete binary tree with levels have, if the root is
considered to be at level 1?
15
25
63
31(ans)
How many nodes does a full binary tree with n non-leaf nodes contais?
Log n
n+1
2n+1(ans)
2n
Function main()
{
Automatic variable var
Print var
}
What will be the output generated when the given code is executed?
0(ans)
1
Garbage value
This code will generate a compile time error
All numbers in one list are more than 100 while in the others are less than
100
The ordering of numbered with respect to the magnitude in the two lists
has different properties(ans)
One list has all negative numbers while the others has all positive numbers
One list contains 0 as an element while the others does not.
What will happen if some indentations arte made in some statements of a code
written in c++?
45(ans)
50
90
99
A programmer wants the program given below to print the largest munber out of
three numbers entered by the user.
Int number 1,number 2,number 3,temp;
Input number 1,number 2,number 3;
If(number 1> number 2)
Temp=number 1
Else
Temp = number 2
End if
If(??)//statement 1
Temp = number 3
End if
Print temp
Which of the following should be substituded in place of ?? in statement 1 in
the code?
Ritika was asked to include concrete objects in her project . which of the
following statement clearly states about the concrete objects?
A queue is implemented as asingly linked list . each node has an element and a
pointer to another node . the rear and the front contain the addresses of the
rear and the front nodes, respectively . what can be inferred about the linked list
if the condition (rear isegual is true?
It has no element(ans)
It has one element
There is an error
None of the above
Insertion sort
Heap sort
Quick sort
Bubble sort(ans)
Which of the following data types does not belong to the category of abstract
data types?
Hashtable
Set
Object(ans)
stack
An unconnected graph
A connected graph
A connected acyclic graph(ans)
A complete graph
Two programmers independently write a program to find the mass of one mole
of water , that includes the masses of hydrogen and oxygen
The first programmer defines the variable as :
Integer hydrogen , oxygen , water //code A
The second programmer defines three quantities as:
Integer a,b,c, // code B
Which of these two is better programming practice and why?
Queue
Stack(ans)
Array
Graph