CECS Quiz 5
numsList: 2, 8, 1 ListRemove(numsList, list tail) numsList:
2, 8
A remove operation for a list ADT will remove the specified item. Given a list with contents: 2, 20, 30, what is the list contents after the following operation? Remove(list, item 2)
20, 30
numsList: 23, 17, 8 ListInsertAfter (numsList, node 23, node 5) numsList:
23 5 17 8
Given a doubly-linked list with nodes 8, 12, 7, 3, node 7's next pointer points to node
3
numsList: 91, 80, 77, 60, 75 ListRemoveAfter(numsList, node 60) ListRemoveAfter(numsList, node 77) ListRemoveAfter(numsList, null) numsList:
80, 77
numsList: 9, 4, 11, 7 ListRemoveAfter(numsList, node 11) numsList:
9, 4, 11
Inserting an item at the end of a 999-item array requires how many items to be shifted?
999
Items stored in an array can be accessed using a positional index
True
ListTraverse can be used to traverse a doubly-linked list.
True
Removing an element from the beginning of the list is simple.
public void removeFirst() { head = head.next; }
A list ADT's underlying data structure has no impact on the program's execution.
False
numsList: 3, 57, 28, 40 ListRemoveAfter(numsList, null) numsList:
57, 28, 40
Accessing elements: Doubly Linked List
O(n)
Accessing elements: Singly Linked List
O(n)
Removing from back: Singly Linked List
O(n)
Insert an item at the beginning of a 999-item array requires how many items to be shifted?
0
Insert an item at the beginning of a 999-item linked list requires how many items to be shifted?
0
Insert an item at the end of a 999-item linked list requires how many items to be shifted?
0
numsList: 1 ListInsertAfter(numsList, node 1, node 6) ListInsertAfter(numsList, node 1, node 4) numsList:
1 4 6
numsList: 10, 20, 30, 40, 50, 60 ListRemoveAfter(numsList, node 40) ListRemoveAfter(numsList, node 20) numsList:
10, 20, 40, 60
Starting with an empty list, what is the list contents after the following operations? Append(list, 11) Append(list, 4) Append(list, 7)
11, 4, 7
numsList: 2, 5, 9 ListRemoveAfter(numsList, node 5) numsList:
2, 5
Given a doubly-linked list with nodes 4, 7, 5, 1, node 7's previous pointer points to node
4
Given numList is: 5, 8, 2, 1. ListTraverse(numsList) visits _____ node(s).
4
numsList: 5, 9 ListInsertAfter(numsList, node 9, node 4) numsList:
5 9 4
numsList: 70, 82, 41, 120, 357, 66 ListRemove(numsList, node 82) ListRemove(numsList, node 357) ListRemove(numsList, node 66) numsList:
70, 41, 120
numsList: 71, 29, 54 ListRemove(numsList, node 29) numsList:
71, 54
numsList: 77 ListInsertAfter(numsList, node 77, node 32) ListInsertAfter(numsList, node 32, node 50) ListInsertAfter(numsList, node 32, node 46) numsList:
77 32 46 50
Append
Adding a node to the last position requires finding the last element.
A linked list has what key advantage over a sequential storage approach like an array or ArrayList?
An item can be inserted somewhere in the middle of the list without having to shift all subsequent items.
A programmer must know the underlying implementation of the list ADT in order to use a list.
False
ListTraverseReverse can be used to traverse a singly-linked list.
False
ListTraverseReverse visits which node second?
Node 13
Accessing elements: Any Linked list with size attribute
O(1)
Adding to back: Doubly Linked List
O(1)
Adding to back: Singly Linked List
O(1)
Adding to front: Doubly Linked List
O(1)
Adding to front: Singly Linked List
O(1)
Removing from back: Doubly Liked List
O(1)
Removing from front: Doubly Linked List
O(1)
Removing from front: Singly Linked List
O(1)
What is the purpose of a list's head node?
Provides a reference to the first item's node in the list, if such an item exists.
A linked lists stores items in a unspecified order.
True
A list node's data can store a record with multiple subitems.
True
A node in binary tree can have zero, one, or two children.
True
Prepend
add an element to the beginning of the list
Node
encapsulates a data (typically declared as Object) and a pointer next to another Node
Given a doubly-linked list with nodes 20, 67, 11, node 20 is the
head
Node
is a basic unit(class) of data structure, such as linked list.
singly linked list
is a data structure for implementing a list ADT, where each node has data and a pointer to the next node
Doubly linked list
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.
Graph
is a data structure for representing connections among items, and consists of vertices connected by edges.
Binary Tree
is a data structure in which each node stores data and has up to two children, known as a left child and a right child.
Linked List
is a data structure that stores an ordered list of items in nodes, where each node stores data and has a pointer to the next node.
Array
is a data structure that stores an ordered list of items, with each item is directly accessible by a positional index
Hash Table
is a data structure that stores unordered items by mapping (or hashing) each item to a location in an array.
Max Heap
is a tree that maintains the simple property that a node's key is greater than or equal to the node's childrens' keys.
Min Heap
is a tree that maintains the simple property that a node's key is less than or equal to the node's childrens' keys.
Record
is the data structure that stores subitems, with a name associated with each subitem.
Prepend Code
public void addToFirst(Object o) { Node n = new Node(o); n.next = head; head = n; }
Append Code
public void addToLast(Object o) { Node current = head; Node n = new Node(o); if (current != null) { while (current != null) { current = current.next; } current.next = n; } else { head = n; } }
Displaying all the elements code
public void printLinkedList( ) { Node current = head; while (current != null) { System.out.println(current.data); current = current.next;} }
Removing an element from the end is more challenging as it requires finding the element before the last
public void removeLast() { Node current = head;if (current == null) { System.out.println("Nothing to remove"); } else if (current.next == null) { head = null; } else { while (current.next.next != null) { current = current.next; } current.next = null; } }
Edge
represents a connection between two vertices in a graph.
Vertex
represents an item in a graph.
Displaying all the elements of the linked list:
requires iterating over each node
ListTraverse begins with
the list's head node
Each node in a doubly-linked list contains data and _____ pointer(s).
two