Page 126 - Computer science 868 Class 12
P. 126
return bin_search(l,m-1,v);
else
return bin_search(m+1,u,v);
}
public static void main(String[] args)
{
BinSearch obj = new BinSearch(5);
obj.fillarray();
obj.sort();
System.out.println(“ location: “ + obj.bin_search(0,4,20) );
}
}
4. Define Big ‘O’ notation. State the two factors which determine the complexity of an algorithm. [ISC 2018]
Ans. Big O notation is a measurement of growth rate of an algorithm with increase in its input size. It defines the upper bound of an
algorithm or the maximum time taken by an algorithm for a given input size.
Two factors which determine the complexity of an algorithm are Time and Space(memory).
5. What is exceptional handling? Also, state the purpose of finally block in a try catch statement. [ISC 2018]
Ans. Exceptional Handling: The way to handle anomalous situations during run time. Finally, is a block of code which is executed with
or without exceptions. The exception handling in java is one of the powerful mechanism to handle the runtime errors so that the
normal flow of the application can be maintained.
Java finally block is a block that is used to execute important code such as closing connection, stream etc.
Java finally block is always executed whether an exception is handled or not.
Java finally block follows try or catch block.
6. What is the worst-case complexity of the following code segment: [ISC 2017]
for(int x = 1; x<=a; x++)
{
statements;
}
for(int y = 1; y <= b; y++)
{
for (int z = 1; z <= c; z++)
{
statements;
}
}
Ans. O(a + bc)
7. How would the complexity change if all the three loops went to N instead of a, b and c? [ISC 2017]
Ans. O(n^2)
124124 Touchpad Computer Science-XII

