Data Structure and Algorithm Quiz 1 Review

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

What is a memory efficient double linked list? a) Each node has only one pointer to traverse the list back and forth b) The list has breakpoints for faster traversal c) An auxiliary singly linked list acts as a helper list to traverse through the doubly linked list d) None of the mentioned

Answer: a Explanation: Memory efficient doubly linked list has been proposed recently which has only one pointer to traverse the list back and forth. The implementation is based on pointer difference.

How does a doubly linked list (DLL) compare to the single linked list (SLL)? A. A DLL will traverse the list much faster than a SLL because of the extra links B. A DLL has two links for traversing the list but does not execute faster when traversing C. none of the above

B. A DLL has two links for traversing the list but does not execute faster when traversing

26. Internally, a linked list is implemented with an array for the storage of the information? A. True B. False

B. False

A linked list is different from an array, because why? A. A linked list can handle more types of information than an array B. An array cannot be sorted but a linked list can be C. An array is fixed in size but a linked list is dynamically sizable.

C. An array is fixed in size but a linked list is dynamically sizable.

What is the purpose of using an ADT for the linked list class? A. To unnecessarily complicate the design B. Using an abstract data type is the only method for building linked lists C. To force a specific set of methods to be used for the subclasses

C. To force a specific set of methods to be used for the subclasses

The instance variables first and last (or head and tail) below to which class of a linked list? A. class LinkedListNode B. class LinkedListADT C. class LinkedListClass

C. class LinkedListClass

What does ADT stand for? A. Automatic Data Template B. Anonymous Data Template C. Abstract Data Type

C. Abstract Data Type

Which of the following is false about a doubly linked list? a) We can navigate in both the directions b) It requires more space than a singly linked list c) The insertion and deletion of a node take a bit longer d) None of the mentioned

Answer: d Explanation: A doubly linked list has two pointers 'left' and 'right' which enable it to traverse in either direction. Compared to singly liked list which has only a 'next' pointer, doubly linked list requires extra space to store this extra pointer. Every insertion and deletion require manipulation of two pointers, hence it takes a bit longer time.

What is a node used for in a linked list? A. to store the information and the link to the next item B. to check for the end of the list C. not used in a linked list

A. to store the information and the link to the next item

What is the space complexity for deleting a linked list? a) O(1) b) O(n) c) Either O(1) or O(n) d) O(logn)

Answer: a Explanation: You need a temp variable to keep track of current node, hence the space complexity is O(1).

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

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

What is the time complexity of inserting a node in a doubly linked list? a) O(nlogn) b) O(logn) c) O(n) d) O(1)

Answer: c Explanation: In the worst case, the position to be inserted maybe at the end of the list, hence you have to traverse through the entire list to get to the correct position, hence O(n).

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

Answer: d 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.

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)

Answer: d 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.

Which of these is an application of linked lists? a) To implement file systems b) For separate chaining in hash-tables c) To implement non-binary trees d) All of the mentioned

Answer: d Explanation: Linked lists can be used to implement all of the above-mentioned applications.

A linked list must contain a maximum size component to managed the last item? A. True B. False

B. False

What should the default constructor of the LinkedListClass perform? A. Nothing since the LinkedListNode class will take care of initialization B. Initialize the first and last (or head and tail) and set count to zero C. Initialize the array to store the information in the linked list

B. Initialize the first and last (or head and tail) and set count to zero

What is the difference between building a linked list FORWARD and BACKWARDS? A. The forward list uses the unordered linked list and backwards uses the ordered linked list B. Nothing, only the insertion of the information at the head or tail of the linked list C. The head and tail are reversed definitions in the backwards list

B. Nothing, only the insertion of the information at the head or tail of the linked list

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? A. LinkedListClass list; B. UnorderedLinkedList list; C. list = UnorderedLinkedList(String)

B. UnorderedLinkedList list;

Given the fixed size of an array is not important, which class is more efficient at storing and retrieving information? A. a linked list because of the nodes B. an array because of the reduced code and efficient storage allocation C. neither is more efficient over the other

B. an array because of the reduced code and efficient storage allocation

What are the basic components of a linked list? A. head and tail are the only important components B. data members for the information to be stored and a link to the next item C. generic class because without this linked list is not possible

B. data members for the information to be stored and a link to the next item

In addition to the info and link components, the linked list must also contain what other components? A. sorting information about the list B. head and tail pointers to the first and last nodes C. the current node that was last accessed

B. head and tail pointers to the first and last nodes

What is the proper code for accessing the information of the second item in a linked list? A. head.info B. head.link.info C. head.link.link.info

B. head.link.info

What does the following code represent? public interface LinkedListADT<T> extends Cloneable A. A linked list class ready to be used in a program B. An abstract method used in a linked list class C. An abstract class used to further define a linked list class

C. An abstract class used to further define a linked list class

What does the following fragment of code do with a linked list? current = head; while (current != null) { current = current.link; } A. it initializes the list B. it counts the number of items in the list C. it traverses the list

C. it traverses the list


Kaugnay na mga set ng pag-aaral

HEY - Unit 1 - p. 18-29 (partial)

View Set

CH 31: Assessment of Immune Function

View Set