Linked Lists Flashcards

Learn

1
Q

What is a Node in a singly linked list?

A

A Node stores data and a pointer to the next node.

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

How do you insert a node at the beginning of a linked list?

A

Create a new node, point its next to the current head, and update the head.

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

How do you find the length of a linked list?

A

Traverse the list while counting nodes until you reach the end.

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

How do you remove a node with a specific value?

A

Traverse with two pointers and bypass the node when found.

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

What’s the difference between singly and doubly linked lists?

A

Singly has a next pointer only; doubly has both next and previous pointers.

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

What’s the time complexity to access a node in a linked list?

A

O(n), because you have to traverse nodes one by one.

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

How do you reverse a linked list in-place?

A

Use three pointers to reverse the direction of the links.

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

How do pointers change during insert/remove?

A

You update the next pointers to include or exclude specific nodes.

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

How to merge two sorted linked lists?

A

Compare elements from each list and build a merged list in order.

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