Data Structure Questions and Answers-Stack using Linked List

 

 Buy/Download all MCQ Ebook   >>>Click Here<<<

Data Structure Questions and Answers-Stack using Linked List

Click on any option to know the CORRECT ANSWERS

Question 1
What is the complexity of searching for a particular element in a Singly Linked List?
A
O(n)
B
O(1)
C
logn
D
nlogn
Home science Questions answers

Question 1 Explanation: 
Singly Linked List allows you to traverse in one direction only, hence if the element to be found is at the tail of the list, the complexity of searching is O(n) to traverse the entire list.

Question 2
Which of the following statements are 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
B
SLL uses lesser memory per node than DLL
C
DLL has more searching power than SLL
D
All of the mentioned
Public administration Questions answers

Question 2 Explanation: 
To insert and delete at known positions requires complete traversal of the list in worst case in SLL, SLL consists of an item and a node field, while DLL has an item and two node fields, hence SLL occupies lesser memory, DLL can be traversed both ways(left and right), while SLL can traverse in only one direction, hence more searching power of DLL.

Question 3
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 pop() operation that can be included in the Stack class. Also 'first' is the top-of-the-stack.

class Node { 	protected Node next; 	protected Object ele; 	Node() 	{ 		this(null, null); 	} 	Node(Object e, Node n) 	{ 		ele=e; 		next=n; 	} 	public void setNext(Node n) 	{ 		next=n; 	} 	public void setEle(Object e) 	{ 		ele=e; 	} 	public Node getNext() 	{ 		return next; 	} 	public Object getEle() 	{ 		return ele; 	} } class Stack { 	Node first; 	int size=0; 	Stack() 	{ 		first=null; 	} }
A

public Object pop() { 	if(size == 0) 	System.out.println("underflow"); 	else 	{ 		Object o = first.getEle();
B

public Object pop() { 	if(size == 0) 	System.out.println("underflow"); 	else 	{ 		Object o = first.getEle();
C

public Object pop() { 	if(size == 0) 	System.out.println("underflow"); 	else 	{ 		first = first.getNext(); 		
D

public Object pop() { 	if(size == 0) 	System.out.println("underflow"); 	else 	{ 		first = first.getNext().getNextEducation Questions answers 

Question 3 Explanation: 
pop() should return the Object pointed to by the node 'first'. The sequence of operations is, first, get the element stored at node 'first' using getEle(), and second, make the node point to the next node using getNext().

Question 4
What does the following function do?

public Object some....func()throws emptyStackException { 	if(isEmpty()) 		throw new emptyStackException("underflow"); 	return first.getEle(); }
A
pop
B
delete the top-of-the-stack element
C
retrieve the top-of-the-stack element
D
none of the mentioned
Biology Questions answers

Question 4 Explanation: 
This code is only retrieving the top element, note that it is not equivalent to pop operation as you are not setting the 'next' pointer point to the next node in sequence.

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

public void display() { 	if(size == 0) 		System.out.println("underflow"); 	else 	{ 		Node current = first; 		while(current != null) 		{ 			System.out.println(current.getEle()); 			current = current.getNext(); 		} 	} }
A
reverse the list
B
display the list
C
display the list excluding top-of-the-stack-element
D
reverse the list excluding top-of-the-stack-element
Civics Test Questions answers

Question 5 Explanation: 
An alias of the node 'first' is created which traverses through the list and displays the elements.

There are 5 questions to complete.

 

 Buy/Download all MCQ Ebook >>>CLICK HERE<<<