Arrays & Linked List Flashcards

1
Q

What is the difference between an array and a linked list?

A

Arrays allow random access (O(1)) but have fixed sizes; linked lists allow dynamic memory allocation but require sequential access (O(n)). Doubly linked lists can allow for o(1) ops

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

What is the time complexity of accessing an element in an array?

A

O(1) (constant time).

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

What is the time complexity of accessing an element in a singly linked list?

A

O(n) (linear time).

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

What are the advantages of a doubly linked list over a singly linked list?

A

Doubly linked lists allow backward traversal and easier deletion but use extra memory. Can allow for o(1) operations

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

How do you create a dummy node?

A

Initialize with let dummy = new ListNode(); let current = dummy;.

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

How do you make a deep copy of a linked list?

A
  1. Interleave new nodes with original nodes.
  2. Assign random pointers for copied nodes.
  3. Separate original and copied lists to restore structure.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly