1. A linked list is exactly the same as an ordinary list - there is absolutely no difference.
2. Linked lists are used to implement several other common abstract data types, including lists, stacks, queues, associative arrays, and S-expressions
3. Read the following excerpt and see if you can fill in the blanks.
4. Linked lists have elements or nodes in them. Each element (node) __________________________
5. Each node in a ___________ has two parts: the node item itself, and a single "pointer". The pointer tells the program where the next associated node is located.
6. A _______________will have two pointers. One will reference the location of the next node and the other points to the previous node
7. In a doubly linked list if the _______ node is NULL, then that is the start of the list.
8. if the _____________ pointer is NULL, then that would indicate the end of the list.
9. In a linked list, it is the pointers and the links they make that makes addition and deletion from a list simple - and __________________________.
10. If an item is added or removed from a linked list then_______________________________
11. The main benefit of a linked list over a conventional array is that the list elements can be easily inserted or removed without reorganization of the entire structure because ______________________
12. Linked lists have several advantages over
dynamic arrays. Fill in the blanks for this excerpt that explains an advantage.
13. On the other hand, dynamic arrays (as well as fixed-size array data structures) allow constant-time random access, while linked lists allow only ________________to elements.
14. Singly linked lists can be traversed in only one direction. This makes linked lists highly suitable for applications where it's useful to look up an element by its index quickly, such as heapsort.
15. A disadvantage of linked lists is the __________________________which often makes them impractical for lists of small data items such as characters or boolean values
16. The following diagram shows that inserting a node before an existing one _______________________; instead, one must keep track of the previous node and insert a node after it.
17. In the following code, removeBeginning() sets list.firstNode to __________________________________
18. In the following linked list (python) implementation, what is happening on line 18?
19. In the following linked list (python) implementation, what is happening on line 21?
20. When the following code is executed, what would the output be?
class Node:
def __init__(self, dataval=None):
self.dataval = dataval
self.nextval = None
class SLinkedList:
def __init__(self):
self.headval = None
# Print the linked list
def listprint(self):
printval = self.headval
while printval is not None:
print (printval.dataval)
printval = printval.nextval
def AtBegining(self,newdata):
NewNode = Node(newdata)
# Update the new nodes next val to existing node
NewNode.nextval = self.headval
self.headval = NewNode
list = SLinkedList()
list.headval = Node("Mon")
e2 = Node("Tue")
e3 = Node("Wed")
list.headval.nextval = e2
e2.nextval = e3
list.AtBegining("Sun")
list.listprint()
Mon, Tues, Wed, Sun
Sun
Mon, Tues, Wed
Sun, Mon, Tues, Wed