1.
What are the basic components of a linked list?
Correct Answer
B. Data members for the information to be stored and a link to the next item
Explanation
A linked list is a data structure that consists of nodes, where each node contains data and a reference to the next node. Therefore, the correct answer is "data members for the information to be stored and a link to the next item." This answer accurately describes the essential components of a linked list. The head and tail are important, but they are not the only components. The option of mentioning a generic class is incorrect as it does not pertain to the basic components of a linked list.
2.
What is a node used for in a linked list?
Correct Answer
A. To store the information and the link to the next item
Explanation
A node is used in a linked list to store the information of an item and also to store the link or reference to the next item in the list. Each node contains the data and a pointer/reference to the next node, creating a chain-like structure that allows for efficient traversal and manipulation of the list. Therefore, the correct answer is "to store the information and the link to the next item."
3.
A linked list is different from an array because
Correct Answer
C. An array is fixed in size, but a linked list is dynamically sizable.
Explanation
A linked list is different from an array because an array has a fixed size, meaning that the number of elements it can hold is predetermined and cannot be changed once it is created. On the other hand, a linked list is dynamically sizable, which means that it can grow or shrink in size as needed. This flexibility allows a linked list to efficiently handle situations where the number of elements can change dynamically, unlike an array.
4.
In addition to the info and link components, the linked list must also contain what other components?
Correct Answer
B. Head and tail pointers to the first and last nodes
Explanation
A linked list must contain head and tail pointers to the first and last nodes in order to keep track of the beginning and end of the list. These pointers are necessary for efficiently traversing the list and performing operations such as adding or removing nodes. The other options, sorting information about the list and the current node that was last accessed, are not essential components of a linked list.
5.
What is the proper code for accessing the information of the second item in a linked list?
Correct Answer
B. Head.link.info
Explanation
To access the information of the second item in a linked list, we need to start from the head node and follow the link to the next node. Since we want the information of the second item, we need to follow the link once. Therefore, the proper code for accessing the information of the second item in a linked list is "head.link.info".
6.
Giving the fixed size of an array is not important. Which class is more efficient at storing and retrieving information?
Correct Answer
B. An array because of the reduced code and efficient storage allocation
Explanation
An array is more efficient at storing and retrieving information compared to a linked list because of the reduced code and efficient storage allocation. Arrays provide direct access to elements using their index, which allows for faster retrieval. Additionally, arrays allocate contiguous memory blocks, making memory management more efficient. In contrast, linked lists require additional memory for node pointers and do not offer direct access to elements, resulting in slower retrieval times.
7.
A linked list class is defined with the following heading.
public class UnorderedLinkedList<T> extends LinkedListClass<T>
What is the proper syntax for creating a reference variable of the linked list to hold strings?
Correct Answer
B. UnorderedLinkedList list;
Explanation
The proper syntax for creating a reference variable of the linked list to hold strings is "UnorderedLinkedList list;". This creates a reference variable named "list" of type "UnorderedLinkedList" which can hold strings.
8.
What does the following fragment of code do with a linked list?
current = head;
while (current != null) { current = current.link; }
Correct Answer
C. It traverses the list
Explanation
The given fragment of code traverses the linked list. It starts by assigning the head of the linked list to the variable "current". Then, it enters a while loop that continues as long as the "current" variable is not null. Inside the loop, the "current" variable is updated to the next node in the linked list by accessing its "link" property. This process continues until the end of the linked list is reached, effectively traversing the entire list. Therefore, the correct answer is that the code traverses the list.
9.
Which of the following code fragments properly insert 50 into the linked list at the position after node p?
A) newNode = new Node(); newNode.info = 50; p.link = newNode; newNode.link = p.link;
B) newNode = new Node(50, p);
C) newNopde = new Node(); newNode.info = 50; newNode.link = p.link; p.link = newNode;
Correct Answer
C. Code C
Explanation
The correct way to insert a new node after a given node p in a linked list is to first create the new node, set its info to the desired value (50 in this case), set its link to point to the node that p was pointing to, and then update p’s link to point to the new node. This is exactly what is done in Code C. Please note that understanding the principles of data structures, such as linked lists, is crucial for effective software development. Always ensure to follow best coding practices when working with data structures.
10.
Internally, a linked list is implemented with an array for the storage of the information?
Correct Answer
B. False
Explanation
Internally, a linked list is not implemented with an array for the storage of the information. Instead, a linked list is implemented using nodes, where each node contains a data element and a reference to the next node in the list. This allows for dynamic memory allocation and efficient insertion and deletion operations, unlike an array which has a fixed size and requires shifting elements when inserting or deleting. Therefore, the correct answer is False.
11.
A linked list must contain a maximum size component to manage the last item?
Correct Answer
B. False
Explanation
A linked list does not require a maximum size component to manage the last item. In a linked list, each element (node) contains a reference to the next element, forming a chain. The last element in the list points to null, indicating the end of the list. Therefore, the size of a linked list can vary dynamically and is not restricted by a maximum size.
12.
Which of the following code fragments properly delete the item at node p?
A) p.link = null; System.gc();
B) q = p.link; p.link = q.link; q = null; System.gc();
C) q = p.link; p.link = q.link; System.gc();
Correct Answer
B. Code B
Explanation
Code B properly deletes the item at node p. It assigns the link of node p to node q, then updates the link of node p to the link of node q. Finally, it sets node q to null, indicating that it is no longer needed. The System.gc() call is unnecessary for deleting the item at node p.
13.
What is the difference between building a linked list FORWARD and BACKWARDS?
Correct Answer
B. Nothing, only the insertion of the information at the head or tail of the linked list
Explanation
The correct answer is that there is no difference between building a linked list forward and backward, except for the insertion of information at the head or tail of the linked list. The order or direction in which the elements are linked does not affect the structure or functionality of the linked list.
14.
What does ADT stand for?
Correct Answer
C. Abstract Data Type
Explanation
ADT stands for Abstract Data Type. It is a high-level description of a set of data values and the operations that can be performed on those values. ADTs are defined independently of any specific programming language and provide a way to organize and manipulate data in a structured manner. They are used to encapsulate data and the operations that can be performed on that data, providing a level of abstraction that allows for easier implementation and maintenance of code. The other options, Automatic Data Template and Anonymous Data Template, are not commonly used terms in the context of data structures and programming.
15.
What is the purpose of using an ADT for the linked list class?
Correct Answer
C. To force a specific set of methods to be used for the subclasses.
Explanation
The purpose of using an ADT (Abstract Data Type) for the linked list class is to force a specific set of methods to be used for the subclasses. By using an ADT, we can define a set of operations or methods that must be implemented by any class that inherits from the linked list class. This ensures consistency and standardization in the implementation of linked lists, making it easier to manage and maintain the codebase. The other options mentioned in the question, such as unnecessarily complicating the design or being the only method for building linked lists, are not valid reasons for using an ADT for the linked list class.
16.
What does the following code represent?
public interface LinkedListADT<T> extends Cloneable
Correct Answer
D. None of the above
Explanation
The code public interface LinkedListADT<T> extends Cloneable and represents an interface in Java that can be used to define the Abstract Data Type (ADT) for a linked list. It’s not a ready-to-use class (option A), an abstract method (option B), or an abstract class (option C). It’s an interface that can be implemented by a class to define the operations for a linked list. The <T> indicates that this interface is generic, meaning it can be used with any type. The extended Cloneable part means that any class implementing this interface will have the ability to create clones of its objects. Please note that understanding the principles of object-oriented programming, such as the concept of interfaces and generics, is crucial for effective software development. Always ensure to follow best coding practices when working with programming languages.
17.
The following heading appears for the node class of a linked list class.
protected class LInkedListNode<T> implements Cloneable
What is the proper syntax for the link component of this class?
Correct Answer
D. First and second choices above
Explanation
The proper syntax for the link component of this class is the first and second choices above, which are "public LinkedListNode link;" and "protected LinkedListNode link;". Both of these choices define a variable named "link" of type LinkedListNode, with the first choice being public and the second choice being protected.
18.
The instance variables first and last (or head and tail) below to which class of a linked list?
Correct Answer
C. Class LinkedListClass
Explanation
The instance variables first and last (or head and tail) belong to the class LinkedListClass. This can be inferred from the fact that the question is asking about the class to which these variables belong, and the correct answer is LinkedListClass.
19.
What should the default constructor of the LinkedListClass perform?
Correct Answer
B. Initialize the first and last (or head and tail) and set count to zero
Explanation
The default constructor of the LinkedListClass should initialize the first and last (or head and tail) pointers to null and set the count variable to zero. This is necessary because the default constructor is called when a new instance of the LinkedListClass is created, and it ensures that the linked list starts with no elements and the pointers are properly set to indicate an empty list.
20.
What is a circular linked list?
Correct Answer
A. The last node in the linked list points to the first
Explanation
A circular linked list is a type of linked list where the last node in the list points back to the first node, creating a circular structure. This means that the next pointer of the last node is not null, but instead points to the first node in the list. This allows for efficient traversal of the list from any point, as it eliminates the need to check for the end of the list.