Lists - Chapter 2 Flashcards

1
Q

A blank is a common ADT for holding ordered data, having operations like append a data item, remove a data item, search whether a data item exists, and print the list

A

list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Inserts x at end of list

A

Append(list, x)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Inserts x at start of list

A

Prepend(list, x)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Inserts x after w

A

InsertAfter(list, w, x)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Removes x

A

Remove(list, x)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Returns item if found, else returns null

A

Search(list, x)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Prints list’s items in order

A

Print(list)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Prints list’s items in reverse order

A

PrintReverse(list)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Sorts the lists items in ascending order

A

Sort(list)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Returns true if list has no items

A

IsEmpty(list)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Returns the number of items in the list

A

GetLength(list)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

common approach for implementing a linked list is using what two data structures

A

List data structure:
List node data structure:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

A blank is a data structure containing the list’s head and tail, and may also include additional information, such as the list’s size.

A

list data structure

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

The blank maintains the data for each list element, including the element’s data and pointers to the other list element.

A

list node data structure

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

A blank is not required to implement a linked list, but offers a convenient way to store the list’s head and tail.

A

list data structure

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

A blank is a data structure for implementing a list ADT, where each node has data and a pointer to the next node.

A

singly-linked list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

A singly-linked list’s first node is called the blank, and the last node the blank.

A

head
tail

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

A singly-linked list is a type of blank A list where elements contain pointers to the next and/or previous elements in the list.

A

positional list:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Blank is a special value indicating a pointer points to nothing.

A

null

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Given a new node, the blank operation for a singly-linked list inserts the new node after the list’s tail node.

A

Append

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Blank: If the list’s head pointer is null (empty), the algorithm points the list’s head and tail pointers to the new node.

A

Append to empty list:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Blank: If the list’s head pointer is not null (not empty), the algorithm points the tail node’s next pointer and the list’s tail pointer to the new node.

A

Append to non-empty list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Given a new node, the blank operation for a singly-linked list inserts the new node before the list’s head node.

A

Prepend

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Blank: If the list’s head pointer is null (empty), the algorithm points the list’s head and tail pointers to the new node.

A

Prepend to empty list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

Blank: If the list’s head pointer is not null (not empty), the algorithm points the new node’s next pointer to the head node, and then points the list’s head pointer to the new node.

A

Prepend to non-empty list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

Given a new node, the blank operation for a singly-linked list inserts the new node after a provided existing list node.

A

InsertAfter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

Blank: If the list’s head pointer is null, the algorithm points the list’s head and tail pointers to the new node.

A

Insert as list’s first node

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

Blank: If the list’s head pointer is not null (list not empty) and curNode points to the list’s tail node, the algorithm points the tail node’s next pointer and the list’s tail pointer to the new node.

A

Insert after list’s tail node

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

Blank: If the list’s head pointer is not null (list not empty) and curNode does not point to the list’s tail node, the algorithm points the new node’s next pointer to curNode’s next node, and then points curNode’s next pointer to the new node.

A

Insert in middle of list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

Given a specified existing node in a singly-linked list, the blank operation removes the node after the specified list node.

A

RemoveAfter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

In RemoveAfter, the existing node is specified with the curNode parameter. If curNode is null, RemoveAfter removes the list’s blank.

A

first node

32
Q

Blank: If curNode is null, the algorithm points sucNode to the head node’s next node, and points the list’s head pointer to sucNode. If sucNode is null, the only list node was removed, so the list’s tail pointer is pointed to null (indicating the list is now empty).

A

Remove list’s head node (special case)

33
Q

Blank: If curNode’s next pointer is not null (a node after curNode exists), the algorithm points sucNode to the node after curNode’s next node. Then curNode’s next pointer is pointed to sucNode. If sucNode is null, the list’s tail node was removed, so the algorithm points the list’s tail pointer to curNode (the new tail node).

A

Remove node after curNode

34
Q

Given a key, a blank algorithm returns the first node whose data matches that key, or returns null if a matching node was not found.

A

search

35
Q

A blank algorithm checks the current node (initially the list’s head node), returning that node if a match, else pointing the current node to the next node and repeating. If the pointer to the current node is null, the algorithm returns null (matching node was not found).

A

simple linked list search

36
Q

In Python, classes are used for both blank and blank that comprise the list.

A

the linked list and the nodes

37
Q

The append() method adds a node to the blank of a linked list, making the node the tail of the list. The append() method has two parameters, the second of which is the new node to be appended to the list.

A

end

38
Q

A blank is a data structure for implementing a list ADT, where each node has data, a pointer to the next node, and a pointer to the previous node. The list structure typically points to the first node and the last node.

A

doubly-linked list

39
Q

A doubly-linked list is similar to a singly-linked list, but instead of using a single pointer to the next node in the list, each node has a pointer to the blank and blank.

A

next and previous nodes

40
Q

A doubly-linked list is a type of blank: A list where elements contain pointers to the next and/or previous elements in the list.

A

positional list

41
Q

A blank is a linked list where the tail node’s next pointer points to the head of the list, instead of null.

A

circular linked list

42
Q

A circular linked list can be used to represent blank. Ex: Ocean water evaporates, forms clouds, rains down on land, and flows through rivers back into the ocean.

A

repeating processes

43
Q

The head of a circular linked list is often referred to as the blank.

A

start node

44
Q

A traversal through a circular linked list is similar to traversal through a standard linked list, but must terminate after reaching the a second time, as opposed to terminating when reaching null.

A

head node

45
Q

A blank algorithm visits all nodes in the list once and performs an operation on each node.

A

list traversal

46
Q

A blank visits all nodes starting with the list’s tail node and ending after visiting the list’s head node.

A

reverse traversal

47
Q

A blank also supports a reverse traversal

A

doubly-linked list

48
Q

Insertion sort’s typical runtime is blank. If a list has N elements, the outer loop executes N - 1 times. In the best case scenario, the list is already sorted, and the runtime complexity is blank.

A

O(N^2)
O(N)

49
Q

Since a singly-linked list only supports inserting a node after an existing list node, the ListFindInsertionPosition algorithm searches the list for the insertion position and returns the list node after which the current node should be inserted. If the current node should be inserted at the head, ListFindInsertionPosition returns blank.

A

null

50
Q

The average and worst case runtime of ListInsertionSortSinglyLinked is blank. The best case runtime is blank which occurs when the list is sorted in descending order.

A

O(N^2)
O(N)

51
Q

Sorting algorithms for arrays, such as blank and blank, require constant-time access to arbitrary, indexed locations to operate efficiently. Linked lists do not allow indexed access, making for difficult adaptation of such sorting algorithms to operate on linked lists.

A

quicksort and heapsort

52
Q

Operates similarly on doubly-linked lists. Requires searching from the head of the list for an element’s insertion position for singly-linked lists.

A

Insertion sort

53
Q

Finding the middle of the list requires searching linearly from the head of the list. The merge algorithm can also merge lists without additional storage.

A

Merge sort

54
Q

Jumping the gap between elements cannot be done on a linked list, as each element between two elements must be traversed.

A

Shell sort

55
Q

Partitioning requires backward traversal through the right portion of the array. Singly-linked lists do not support backward traversal.

A

Quicksort

56
Q

Indexed access is required to find child nodes in constant time when percolating down.

A

Heap sort

57
Q

What aspect of linked lists makes adapting array-based sorting algorithms to linked lists difficult?

A

Lack of indexed access

58
Q

Which sorting algorithm uses a gap value to jump between elements, and is difficult to adapt to linked lists for this reason?

A

Shell sort

59
Q

Why are sorting algorithms for arrays generally more difficult to adapt to singly-linked lists than to doubly-linked lists?

A

Several sorting algorithms traverse backward through list elements, which cannot be done with a singly-linked list.

60
Q

current_node = self.head.next
while current_node != None:
next_node = current_node.next
search_node = current_node.prev

    while ((search_node != None) and 
           (search_node.data > current_node.data)):
        search_node = search_node.prev
  
    # Remove and re-insert curNode
    self.remove(current_node)
        
    if search_node == None:
        current_node.prev = None
        self.prepend(current_node)      
    else:
        self.insert_after(search_node, current_node)

    # Advance to next node
    current_node = next_node
A

Insertion sort algorithm for doubly-linked lists.

61
Q

before_current = self.head
current_node = self.head.next
while current_node != None:
next_node = current_node.next
position = self.find_insertion_position(current_node.data)
if position == before_current:
before_current = current_node
else:
self.remove_after(before_current)
if position == None:
self.prepend(current_node)
else:
self.insert_after(position, current_node)
current_node = next_node

def find_insertion_position(self, data_value):
position_a = None
position_b = self.head
while (position_b != None) and (data_value > position_b.data):
position_a = position_b
position_b = position_b.next
return position_a

A

Insertion sort algorithm for singly-linked lists

62
Q

A linked list implementation may use a blank (or header node): A node with an unused data member that always resides at the head of the list and cannot be removed.

A

dummy node

63
Q

Using a dummy node simplifies the algorithms for a linked list because the blank and blank are never null.

A

head and tail pointers

64
Q

An blank consists of the dummy node, which has the next pointer set to null, and the list’s head and tail pointers both point to the dummy node.

A

empty list

65
Q

ListAppend, ListPrepend, and ListInsertAfter do not need to check if the list’s head is null, since the list’s head will always point to the dummy node. ListRemoveAfter does not need a special case to allow removal of the blank, since the blank is after the dummy node.

A

first list item

66
Q

A dummy node can also be used in a doubly-linked list implementation. The dummy node in a doubly-linked list always has the prev pointer set to blank.

A

null

67
Q

A doubly-linked list implementation can also use 2 dummy nodes: blank and blank Doing so removes additional conditionals and further simplifies the implementation of most methods.

A

one at the head and the other at the tail.

68
Q

Blank through a linked list can be implemented using a recursive function that takes a node as an argument.

A

Forward traversal

69
Q

A blank is implemented similar to forward traversal. Each call examines 1 node. If the node is null, then null is returned. Otherwise, the node’s data is compared to the search key. If a match occurs, the node is returned, otherwise the remainder of the list is searched recursively.

A

recursive linked list search

70
Q

Forward traversal visits a node first, then recursively traverses the remainder of the list. If the order is swapped, such that the recursive call is made first, the list is traversed in blank.

A

reverse order

71
Q

An blank is a list ADT implemented using an array.

A

array-based list

72
Q

An array-based list must be blank if an item is added when the allocation size equals the list length. A new array is allocated with a length greater than the existing array. Allocating the new array with twice the current length is a common approach. The existing array elements are then copied to the new array, which becomes the list’s storage array.

A

resized

73
Q

Because all existing elements must be copied from 1 array to another, the resize operation has a runtime complexity of blank

A

O(N)

74
Q

Because all existing array elements must be moved up by 1, the prepend operation has a runtime complexity of blank.

A

O(N)

75
Q

The InsertAfter operation has a best case runtime complexity of blank and a worst case runtime complexity of blank.

A

O(1)
O(N)

76
Q

Both the search and remove operations have a worst case runtime complexity of blank

A

O(N)