Data Structure Questions and Answers-Stack using Linked List

DOWNLOAD FREE PDF <<CLICK HERE>>

Data Structure Questions and Answers-Stack using Linked List

Congratulations - you have completed Data Structure Questions and Answers-Stack using Linked List.

You scored %%SCORE%% out of %%TOTAL%%.

Your performance has been rated as %%RATING%%


Your answers are highlighted below.
Question 1 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions 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
Computer science (GATE/NET) 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 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions 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
Aptitude test 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 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions 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().getNextGK (GENERAL KNOWLEDGE) 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 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions 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
KBC 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 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions 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
UPSC FREE STUDY
Question 5 Explanation: 
An alias of the node 'first' is created which traverses through the list and displays the elements.

Once you are finished, click the button below. Any items you have not completed will be marked incorrect. Get Results
There are 5 questions to complete.

DOWNLOAD FREE PDF <<CLICK HERE>>

"Present and Skyrocket Your Studying Success"

Hacks to Skyrocket Your Memory Instantly