Data Structure Questions and Answers-Priority Queue

 

 Help authour, Buy PDF Ebook   >>>Click Here<<<

Data Structure Questions and Answers-Priority Queue

Question 1
With what data structure can a priority queue be implemented?
A
Array
B
List
C
Heap
D
All of the mentioned
Civics Test Questions answers
Question 1 Explanation: 
Priority queue can be implemented using an array, a list, a binary search tree or a heap, although the most efficient one being the heap.

Question 2
Which of the following is not an application of priority queue?
A
Huffman codes
B
Interrupt handling in operating system
C
Undo operation in text editors
D
Bayesian spam filter
Commerce Questions answers
Question 2 Explanation: 
Undo operation is achieved using a stack.

Question 3
Select the appropriate code that inserts elements into the list based on the given key value.

(head and trail are dummy nodes to mark the end and beginning of the list, they do not contain any priority or element)

A

public void insert....key(int key, Object item) { 	if(key<0) 	{ 		Systerm.our.println("invalid"); 		System.exit(0)
B

public void insert....key(int key, Object item) { 	if(key<0) 	{ 		Systerm.our.println("invalid"); 		System.exit(0)
public void insert....key(int key, Object item) { 	if(key<0) 	{ 		Systerm.our.println("invalid"); 		System.exit(0)
D
None of the mentioned
Reading comprehension Questions answers
Question 3 Explanation: 
Have two temporary pointers 'dup' and 'cur' with 'cur' trailing behind 'dup'. Traverse through the list until the given key is greater than some element with a lesser key, insert the new node 'temp' in that position.

Question 4
What is the time complexity to insert a node based on key in a priority queue?
A
O(nlogn)
B
O(logn)
C
O(n)
D
O(n2)
Microbiology Questions answers
Question 4 Explanation: 
In the worst case, you might have to traverse the entire list.

Question 5
What is the functionality of the following piece of code?

public Object delete....key() { 	if(count == 0) 	{ 		System.out.println("Q is empty"); 		System.exit(0); 	} 	else 	{ 		Node cur = head.getNext(); 		Node dup = cur.getNext(); 		Object e = cur.getEle(); 		head.setNext(dup); 		count--; 		return e; 	} }
A
Delete the second element in the list
B
Return but not delete the second element in the list
C
Delete the first element in the list
D
Return but not delete the first element in the list
Reasoning Questions answers
Question 5 Explanation: 
A pointer is made to point at the first element in the list and one more to point to the second element, pointer manipulations are done such that the first element is no longer being pointed by any other pointer, its value is returned.

There are 5 questions to complete.

 

 Help authour, Buy PDF Ebook   >>>Click Here<<<