(5) Lists Flashcards
Definition List/ Linked List
A list or linked list is a dynamic data structure that allows to dynamically manage data.
Pro: arbitrary insertion of elements
Con: more complex management, overhead
Definition Node
Consists of two parts:
- data
- reference to the next node
Every node references its successor node (but doesn’t know predecessor
What are the steps to search for an element in a list?
- current_node = head 2. If current_node == nil
element not found - If current_node.data == e, you are done, element is found
- If current_node.data ≠ e
current_node = current_node.next - Go to step 2 (with the new current_node)
What are the steps to delete a node in a list?
- node_to_delete = current_node.next
- current_node.next = node_to_delete.next
- Delete node_to_delete
- You are done
Which ways exist to insert an element into a list?
- Insert element at head position
- Insert elements while maintaining an order
What are the steps to insert a node at the head of a list?
- current_node = head
- new_node.next = current_node
- head = new_node
- You are done
What does a node consist of?
A node has the two attributes “data” and “next”
What is the time efficiency for searching, inserting and deleting in a list?
Searching: O(n)
Inserting: O(n) (except inserting at head O(1))
Deleting: O(n)