Data Structure Questions and Answers-Stack using Linked List

YOU CAN DOWNLOAD 200+ SUBJECTS PDF BOOK FOR COMPETITIVE EXAMINATIONS

CLICK HERE TO DOWNLOAD

Data Structure Questions and Answers-Stack using Linked List

Question 1 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
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
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 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
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
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 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
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().getNext [CLICK ON ANY CHOICE TO KNOW  THE RIGHT ANSWER]
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
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 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
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
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.