Data Structure Questions and Answers-Singly Linked List

DOWNLOAD FREE PDF <<CLICK HERE>>

Data Structure Questions and Answers-Singly Linked List

Congratulations - you have completed Data Structure Questions and Answers-Singly 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]
Which of the following is not a disadvantage to the usage of array?
A
Fixed size
B
You know the size of the array prior to allocation
C
Insertion based on position
D
Accessing elements at specified positions

CLICK HERE FOR ALL SUBJECTS MCQ

Question 1 Explanation: 
Array elements can be accessed in two steps. First, multiply the size of the data type with the specified position, second, add this value to the base address. Both of these operations can be done in constant time, hence accessing elements at a given index/position is faster.

Question 2 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER]
What is the time complexity of inserting at the end in dynamic arrays?
A
O(1)
B
O(n)
C
O(logn)
D
Either O(1) or O(n)

CLICK HERE FOR ALL SUBJECTS MCQ

Question 2 Explanation: 
Depending on whether the array is full or not, the complexity in dynamic array varies. If you try to insert into an array which is not full, then the element is simply stored at the end, this takes O(1) time. If you try to insert into an array which is full, first you will have to allocate an array with double the size of the current array and then copy all the elements into it and finally insert the new element, this takes O(n) time.

Question 3 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER]
What is the time complexity to count the number of elements in the linked list?
A
O(1)
B
O(n)
C
O(logn)
D
None of the mentioned

CLICK HERE FOR ALL SUBJECTS MCQ

Question 3 Explanation: 
To count the number of elements, you have to traverse through the entire list, hence complexity is O(n).

Question 4 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER]
Which of the following performs deletion of the last element in the list? Given below is the Node class.

class Node { 	protected Node next; 	protected Object ele; 	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 SLL { 	Node head; 	int size; 	SLL() 	{ 		size = 0; 	} }
A

public Node removeLast() { 	if(size == 0) 	return null; 	Node cur; 	Node temp; 	cur = head; 	while(cur.getNext() != null) 	
B

public void removeLast() { 	if(size == 0) 	return null; 	Node cur; 	Node temp; 	cur = head; 	while(cur != null) 	{ 		temp = cur
C

public void removeLast() { 	if(size == 0) 	 return null; 	Node cur; 	Node temp; 	cur = head; 	while(cur != null) 	{ 		cur =
D

public void removeLast() { 	if(size == 0) 		return null; 	Node cur; 	Node temp; 	cur = head; 	while(cur.getNext() != null

CLICK HERE FOR ALL SUBJECTS MCQ

Question 4 Explanation: 
Since you have to traverse to the end of the list and delete the last node, you need two reference pointers. 'cur' to traverse all the way and find the last node, and 'temp' is a trailing pointer to 'cur'. Once you reach the end of the list, setNext of 'temp' to null, 'cur' is not being pointed to by any node, and hence it is available for garbage collection.

Question 5 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER]
What is the functionality of the following code?

public void function(Node node) { 	if(size == 0) 		head = node; 	else 	{ 		Node temp, cur; 		for(cur = head; (temp = cur.getNext())!=null; cur = temp); 		cur.setNext(node); 	} 	size++; }
A
Inserting a node at the beginning of the list
B
Deleting a node at the beginning of the list
C
Inserting a node at the end of the list
D
Deleting a node at the end of the list

CLICK HERE FOR ALL SUBJECTS MCQ

Question 5 Explanation: 
The for loop traverses through the list and then inserts a new node as cur.setNext(node);

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>>