CS4961 Attempt 2
Consider a single linked list, which of the following operation depend on the length of the linked list? Add an item after the last item of the linked list Add an item before the first item of the linked list Delete the linked lie first item of thst Delete the last item of the linked list
Add an item after the last item of the linked list Delete the last item of the linked list
Which of the following(s) is/are incorrect description of a balanced binary tree? 1) Data insertion requires O(log n) running time in the worst-case. 2) Data deletion requires O(log n) running time in the worst-case. 3) Data search requires O(log n) running time in the worst-case. 4) Binary tree provides an index to access the elements in the tree.
Binary tree provides an index to access the elements in the tree.
What is the output of the following program: public class testmeth { static int i = 1; public static void main(String args[]) { System.out.println(i+" , "); m(i); System.out.println(i); } public void m(int i) { i += 2; } }
1, 1
A typical Queue implementation has 4 operations: Enqueue() will add an item to the end of the queue. Dequeue() will remove an item from the beginning of the queue Front() will return the value of front-most item. Isempty() will return true if there no elements in the queue What is printed after executing the following code? String A="0123456789" Queue q; for (k = 0; k < A.length(); k++) ( if (k MOD 2 ==1) q.Enque(A[k]) } While (!q.isempty()) { Print (q.Front()) q.Dequeue() }
1,3,5,7,9
Which of the following(s) is/are correct description of a linked list data type?
Linked list requires O(n) running time for data insertion/deletion in the worst-case.
Which Keyword from the following is used to inherit properties from one class into another?
extends
To prevent any method from overriding, we declare the method as
final
When a class serves as base class for many derived classes, the situation is called
hierarchical inheritance
When two or more classes serve as base class for a derived class, the situation is known as
multiple inheritance
The following incomplete function is intended to return the index of the first occurrence of the minimum value in the array A. { int k; int minIndex = 0; for (k = 1; k < A.length(); k++) { if ( <condition> ) { <statement> } } return minIndex; } Which of the following could be used to replace <condition> and <statement> so that function works as intended? <condition> <statement>
A[k] < A[minIndex] minIndex = k;
What will be printed as the output of the following program? public class testincr { public static void main(String args[]) { int i = 0; i = i++ + i; System.out.println("I = " +i); } }
I = 1
Which of the following code segments returns true if there are no duplicate values in an array A of n elements; otherwise, returns false. (I) for (j = 0; j < n - 1; j++) { for (k = j + 1; k < n; k++) if (A[j] == A[k]) return false; } return true; (II) for (j = 1; j < n; j++) { for (k = 0; k < j; k++) if (A[k] == A[j]) return false; } return true; (III) for (j = 0; j < n; j++) { for (k = 1; k < n; k++) if (A[k] == A[j]) return false; } return true;
I and II only
How will a class protect the code inside it?
Using Access specifiers
void printNum(int n, int base) { cout << n MOD base; if (n >= base) printNum( n / base, base ); } What is the output generated for printNum(123, 8);
371
A typical Queue implementation has 3 operations; They are: enqueue(), dequeue(), and Front(). Enqueue() will add an item to the end of the queue. Dequeue() will remove and return an item from the beginning of the queue Front() will return the value of front-most item. What values would be returned after the following sequence of operations: enqueue(4), enqueue(8), dequeue(), enqueue(98), enqueue(15), dequeue(), dequeue(), enqueue(5), enqueue(2), front()
4,8,98,15
The seven elements A, B, C, D, E, F and G are pushed onto a stack in reverse order, i.e., starting from G. The stack is popped five times and each element is inserted into a queue. Two elements are deleted from the queue and pushed back onto the stack. Now, one element is popped from the stack. The popped item is ________.
B
Consider an example of Teacher and Student. What best describes the relationship of "Student" to "Teacher"
Composition
int total = 0; for (k = 0; k < A.length(); k++) { if(A[k] % 2= =0) total=total+1 } return total; Assume that "A" is defined as an integer array; What does the above code return;
Count of the elements which are even
Which of the following statement about exception handling is/are not true?
Exception occurs during the compile time of a program.
Multiple inheritance means,
Multiple inheritance means,
Which of the following concept is often expressed by the phrase, 'One interface, multiple methods'?
Polymorphism