Linked Lists Revision Questions Flashcards

1
Q

What determines the linear order of an array? And what determines the linear order of a linked list?

A

The linear order of an array is determined by the array indices, and the order in a linked list is determined by a pointer in each object.

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

What do the three key attributes of an object (key, next, prev) in a doubly linked list stand for?

A

key = data
next = link to next node
previous = link to previous node (address)

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

What does head stand for?

A

the first element in the list

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

What does NIL mean?

A

No element

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

Under what condition is a linked list empty?

A

If L: head = NIL , the list is empty.

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

What is the difference between a singly linked list and doubly linked list?

A

Singly linked list only go one way, so there is no ‘prev’ pointer.
Doubly linked lists can go in both directions.

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

What is a circular list?

A

A circular list only goes one way, but its tail links back to its head, so it goes in a circle.

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

What does LIST-SEARCH(L, k) algorithm do and how does it work? Why does it takes Θ(n) in the worst case? What is the best case?

A

LIST-SEARCH searches a list for a specific element. It uses a simple linear search.
The worst case is Theta(n), since it may have to search the entire list.

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

What does LIST-INSERT(L, x) algorithm do, and how does it work? Why does it take O(1)?

A

The LIST-INSERT procedure splices an element onto the front of the list.

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

What does LIST-DELETE(L, x) algorithm do, and how does it work? Why does it take O(1)? What is the time complexity measure if we delete an element with a given key?

A

The LIST-DELETE removes an element x from a linked list L . It must be given a pointer to x , and it then “splices” x out of the list by updating pointers.

If we wish to delete an element with a given key, we must first call LIST -SEARCH to retrieve a pointer to the element.
this would add worst-case runtime Theta(n)

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

What is a sentinel L.nil?

What is the benefit of having a circular doubly linked list with a sentinel? And what is the side effect?

A

A sentinel is a dummy object that allows us to simplify boundary conditions.

The gain from using sentinels within loops is usually a matter of clarity of code rather than speed;

We should use sentinels judiciously. When there are many small lists, the extra storage used by their sentinels can represent significant wasted memory.

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