CS 301 & CS 301p Quiz#1
CS 301 & CS 301p Quiz#1 |
Which of the following is a characteristic of a list data structure?
a) It stores elements of different types
b) It is an unordered collection of elements
c) It allows duplicate elements
d) It does not support insertion or deletion operations
Answer: b) It is an unordered collection of elements
Which operation is used to create a new list?
Answer: b) It is an unordered collection of elements
Which operation is used to create a new list?
a) clear()
b) insert()
c) greatest()
d) length()
Answer: c) greatest()
What does the remove() function do in a list?
Answer: c) greatest()
What does the remove() function do in a list?
a) Clears all the elements from the list
b) Returns the length of the list
c) Removes an element at a specific position in the list
d) Copies one list to another
Answer: c) Removes an element at a specific position in the list
How is a specific position in a list referred to using an index-based approach?
Answer: c) Removes an element at a specific position in the list
How is a specific position in a list referred to using an index-based approach?
a) By using a current marker
b) By using a pointer
c) By using a function call
d) By using a numerical index
Answer: d) By using a numerical index
What does the next() function do in a list?
Answer: d) By using a numerical index
What does the next() function do in a list?
a) Moves the current position forward one element
b) Clears all the elements from the list
c) Inserts an element at a specific position
d) Returns the length of the list
Answer: a) Moves the current position forward one element
Which operation is used to replace an element at a given position in a list?
Answer: a) Moves the current position forward one element
Which operation is used to replace an element at a given position in a list?
a) update()
b) find()
c) copy()
d) length()
Answer: a) update()
Which operation is used to determine if an element is present in a list?
Answer: a) update()
Which operation is used to determine if an element is present in a list?
a) copy()
b) insert()
c) length()
d) find()
Answer: d) find()
What does the length() function do in a list?
Answer: d) find()
What does the length() function do in a list?
a) Creates a new list
b) Inserts an element at a specific position
c) Returns the length of the list
d) Removes an element at a specific position
Answer: c) Returns the length of the list
Which function moves the "current" pointer to the very first element in a list?
Answer: c) Returns the length of the list
Which function moves the "current" pointer to the very first element in a list?
a) tail()
b) next()
c) start()
d) back()
Answer: c) start()
Which function moves the "current" pointer to the very last element in a list?
Answer: c) start()
Which function moves the "current" pointer to the very last element in a list?
a) next()
b) back()
c) start()
d) tail()
Answer: d) tail()
Answer: d) tail()
a. Removes an element from the list
b. Moves the current position forward
c. Adds an element to the list
d. Finds a specific element in the array
Answer: c. Adds an element to the list
Which index is used to represent the current position in the array-based list implementation?
a. Index 0
b. Index 1
c. Index 2
d. Index n (where n is the size of the array)
Answer: b. Index 1
What happens when an element is removed from the list in the remove method?
a. The size of the list decreases
b. The current position is shifted to the next element
c. The current position remains unchanged
d. The array is resized to accommodate the removal
Answer: a. The size of the list decreases
Which method sets the current position to the first element of the list?
a. add
b. remove
c. start
d. end
Answer: c. start
How is the length of the list obtained in the array-based implementation?
a. By counting the number of elements in the array
b. By subtracting the current position from the array size
c. By using the length() method
d. By iterating through the array and counting the elements
Answer: c. By using the length() method
Which method is used to update (set) the value at the current position?
a. add
b. remove
c. update
d. find
Answer: c. update
What are the boundary conditions to consider in the array-based list implementation?
a. Handling index out-of-bounds errors
b. Handling empty list scenarios
c. Ensuring proper resizing of the array
d. All of the above
Answers: d. All of the above
What is the purpose of the "start()" method in a linked list implementation?
a. It adds a new node at the beginning of the list.
b. It initializes the currentNode and lastCurrentNode pointers to the first element of the list.
c. It removes the first node from the list.
d. It returns the size of the list.
Answer: b. It initializes the currentNode and lastCurrentNode pointers to the first element of the list.
Answer: b. It initializes the currentNode and lastCurrentNode pointers to the first element of the list.
In a singly-linked list, how many directions can the pointers move?
a. Only forward
b. Only backward
c. Both forward and backward
d. Neither forward nor backward
Answer: a. Only forward
Answer: a. Only forward
What does the statement "lastCurrentNode->setNext(currentNode->getNext())" do in the remove() method?
a. Sets the next pointer of the current node to the next node in the list.
b. Sets the next pointer of the last current node to the next node in the list.
c. Sets the next pointer of the current node to the previous node in the list.
d. Sets the next pointer of the last current node to the previous node in the list.
Answer: b. Sets the next pointer of the last current node to the next node in the list.
Answer: b. Sets the next pointer of the last current node to the next node in the list.
What does the "delete" keyword do in the remove() method?
a. Deletes the currentNode pointer.
b. Deletes the lastCurrentNode pointer.
c. Deletes the current node from memory and releases the allocated memory.
d. Deletes the headNode pointer.
Answer: c. Deletes the current node from memory and releases the allocated memory.
Answer: c. Deletes the current node from memory and releases the allocated memory.
After removing a node from a linked list, what is the next step in the remove() method?
a. Set currentNode to the next node in the list.
b. Set currentNode to the previous node in the list.
c. Set lastCurrentNode to the next node in the list.
d. Set lastCurrentNode to the previous node in the list.
Answer: a. Set currentNode to the next node in the list.
Answer: a. Set currentNode to the next node in the list.
Which private data member of a linked list stores the size of the list?
a. currentNode
b. lastCurrentNode
c. headNode
d. size
Answer: d. size
Answer: d. size
Which private data member of a linked list points to the first node of the list?
a. currentNode
b. lastCurrentNode
c. headNode d. size
Answer: c. headNode
Answer: c. headNode
What can a programmer do with the linked list class?
a. Get the size of the list, add or remove nodes, and move the pointers.
b. Only get the size of the list.
c. Only add or remove nodes in the list.
d. Only move the pointers in the list.
Answer: a. Get the size of the list, add or remove nodes, and move the pointers.
0 Comments