Question
Question
Correct Answer : A
2. Which of the following stable sorting algorithm takes the least time when applied to an
almost sorted array?
a) Quick sort
b) Insertion sort
c) Selection sort
d) Merge sort
Answer: d
b)
c)
}
}
d)
Answer: b
4. Consider the original array 17 8 12 4 26. How many comparisons are needed to
construct the BST on the original array?
a) 5
b) 4
c) 7
d) 10
Answer: d
Answer: c
Explanation: Binary tree sort is dynamic sorting, that is it gets more efficient as more
the elements are added. So, we can add elements gradually as they become
available. Binary tree sort requires extra memory space, its worst case space
complexity is Θ(n).
Answer: c
Explanation: Greedy algorithm is used to solve this problem. We first sort items
according to their value/weight ratio and then add item with highest ratio until we
cannot add the next item as a whole. At the end, we add the next item as much as
we can.
7.Consider the following heap after buildheap phase. What will be its
corresponding array?
a) 26,53,41,97,58,59,31
b) 26,31,41,53,58,59,97
c) 26,41,53,97,31,58,59
d) 97,53,59,26,41,58,3
Answer: d
a) O(1)
b) O(n)
c) O(log n)
d) O(n log n)
Answer: b
Explanation: Tree sort requires auxiliary space for maintaining a binary search
tree. So the auxiliary space complexity of tree sort is O(n).
a) True
b) False
Answer: a
Explanation: The equality d[u]=delta(s,u) holds good when vertex u is added to set
S and this equality is maintained thereafter by the upper bound property.
Answer: d
b to g, cost is 1
g to e, cost is 4
e to f, cost is 1
11.. In the given graph, identify the shortest path having minimum cost to reach
vertex E if A is the source vertex.
a) a-b-e
b) a-c-e
c) a-c-d-e
d) a-c-d-b-e
Answer: b
Explanation: The minimum cost required to travel from vertex A to E is via vertex C
A to C, cost= 3
C to E, cost= 2
a) 3
b) 4
c) 1
d) 2
Answer: c
Explanation: Use one queue and one counter to count the number of elements in
the queue.
if(size == 0)
System.out.println("underflow");
else
while(current != null)
System.out.println(current.getEle());
current = current.getNext();
}
}
Answer: b
Explanation: An alias of the node ‘first’ is created which traverses through the list
and displays the elements.
14, Given below is the Node class to perform basic list operations and a Stack
class with a no arg constructor. Select from the options the appropriate push()
operation that can be included in the Stack class. Also ‘first’ is the top-of-the-stack.
class Node
Node()
this(null,null);
}
Node(Object e,Node n)
ele=e;
next=n;
next=n;
ele=e;
return next;
}
public Object getEle()
return ele;
class Stack
Node first;
int size=0;
Stack()
first=null;
a)
{
Node temp = new Node(item,first);
first = temp;
size++;
b)
first = temp.getNext();
size++;
c)
first = temp.getNext();
first.setItem(item);
size++;
}
d)
first = temp.getNext.getNext();
first.setItem(item);
size++;
Answer: a
Explanation: To push an element into the stack, first create a new node with the
next pointer point to the current top-of-the-stack node, then make this node as
top-of-the-stack by assigning it to ‘first’.
15. Which of the following statements are not correct with respect to Singly Linked
List(SLL) and Doubly Linked List(DLL)?
a) Complexity of Insertion and Deletion at known position is O(n) in SLL and O(1) in
DLL