Recall the Insertion Sort algorithm discussed in class, which produces an array whose elements are in increasing / non-decreasing order.
Suppose that we wish to run Insertion Sort on an array containing
Select all of the options below that are true about the Insertion Sort's running time on this array:
Select all possible options that apply.
Select all the true statements from the list below. Each makes a statement on the pros and cons of lists vs. arrays.
Select all possible options that apply.
Consider a doubly linked list with a head pointer, a tail pointer, and
Select all possible options that apply.
Consider a singly linked list with a head pointer, and
Select all possible options that apply.
Consider a null-terminated, singly-linked list with head and tail pointers.
Suppose that every node, in addition to its next pointer, also maintains an additional pointer mid to the node which is halfway in between its own position in the list and the last node in the list.
The mid pointer of each node is subject to these further invariant properties:
nd has even length (i.e. there are two "middle" nodes), then nd's mid pointer points to the node which is closer to the back of the list.mid pointer refers to NULL.Assuming that the length of the list is known (
This best case running time occurs when the list's length before insertion is
Choose the best asymptotic description for each of the following statements. Unless otherwise stated, assume we are referring to the worst-case behavior or structure, and that our algorithms (if any) are the best possible for the scenario.
Enter the letter corresponding to the appropriate asymptotic expression into the boxes. Choices may be used more than once, or not at all.
What is the running time of finding an element in a singly linked list of length
Assume you have a doubly linked list with head and tail pointers, and no sentinels. Pat is trying to write the delete function for a linked list of unique (no duplicates) integers.
/*
@param head - a pointer to the head of the linked list
@param toDelete - a pointer to the node to be deleted from the list
the node is guaranteed to be part of the list
this parameter will never be null or the head or tail of the linked list
*/
void deleteNode(ListNode *head, ListNode *toDelete) {
ListNode *temp = head;
while (temp != NULL) {
if (temp == toDelete) {
ListNode *prevNode = temp->prev;
ListNode *nextNode = temp->next;
nextNode->prev = prevNode;
prevNode->next = nextNode;
delete toDelete;
toDelete = NULL;
break; // this is a break statement! it exits the loop.
}
temp = temp->next;
}
}
What is the problem with Pat’s code?