CSC148 Test Study Terms with Complete solutions
(
time of inserting and deleting in front of a list is proportional to its length
class _Node - ANSWER represents a single element of a list, and stores its item and the
next item after
class _node design - ANSWER item: Any
next: Optional[_Node]
def __init__(self, item: Any) -> None:
self.item = item
self.next = None
Linked List Class - ANSWER a list implementation of the List ADT
implementation - ANSWER _first: Optional[_Node]
def __init__(self) -> None: self._first = None
creating a linked list - ANSWER >>> linky = LinkedList()
, >>>node1 = _Node(10)
>>>node2 = _Node(20)
>>>node3 = _Node(30)
>>>node1.next = node2
>>>node2.next = node3
>>>node1.next is node2
>>>link._first = node1
>>>linky._first.item
10
>>>linky._first.next.item
20
>>>linky._first.next.next.item
30
linked list memory diagram - ANSWER
iterate through the linked list - ANSWER class LinkedList:
def iterate(self) -> None
curr = my_linked_list._first
while curr is not None:
...curr.item...
curr = curr.next
are linked lists stored in consecutive locations in memory? - ANSWER no
array_based list - ANSWER store references to elements in contiguous blocks
(
time of inserting and deleting in front of a list is proportional to its length
class _Node - ANSWER represents a single element of a list, and stores its item and the
next item after
class _node design - ANSWER item: Any
next: Optional[_Node]
def __init__(self, item: Any) -> None:
self.item = item
self.next = None
Linked List Class - ANSWER a list implementation of the List ADT
implementation - ANSWER _first: Optional[_Node]
def __init__(self) -> None: self._first = None
creating a linked list - ANSWER >>> linky = LinkedList()
, >>>node1 = _Node(10)
>>>node2 = _Node(20)
>>>node3 = _Node(30)
>>>node1.next = node2
>>>node2.next = node3
>>>node1.next is node2
>>>link._first = node1
>>>linky._first.item
10
>>>linky._first.next.item
20
>>>linky._first.next.next.item
30
linked list memory diagram - ANSWER
iterate through the linked list - ANSWER class LinkedList:
def iterate(self) -> None
curr = my_linked_list._first
while curr is not None:
...curr.item...
curr = curr.next
are linked lists stored in consecutive locations in memory? - ANSWER no
array_based list - ANSWER store references to elements in contiguous blocks