(5) Lists Flashcards

1
Q

Definition List/ Linked List

A

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

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

Definition Node

A

Consists of two parts:

  • data
  • reference to the next node

Every node references its successor node (but doesn’t know predecessor

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

What are the steps to search for an element in a list?

A
  1. current_node = head 2. If current_node == nil
    element not found
  2. If current_node.data == e, you are done, element is found
  3. If current_node.data ≠ e
    current_node = current_node.next
  4. Go to step 2 (with the new current_node)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the steps to delete a node in a list?

A
  1. node_to_delete = current_node.next
  2. current_node.next = node_to_delete.next
  3. Delete node_to_delete
  4. You are done
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which ways exist to insert an element into a list?

A
  • Insert element at head position

- Insert elements while maintaining an order

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

What are the steps to insert a node at the head of a list?

A
  1. current_node = head
  2. new_node.next = current_node
  3. head = new_node
  4. You are done
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does a node consist of?

A

A node has the two attributes “data” and “next”

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

What is the time efficiency for searching, inserting and deleting in a list?

A

Searching: O(n)
Inserting: O(n) (except inserting at head O(1))
Deleting: O(n)

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