Basics 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)).

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 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.

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

What is a stack? What are its key operations?

A

LIFO (Last In, First Out), operations: push(), pop(), peek().

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

What is a queue? How does it differ from a stack?

A

FIFO (First In, First Out), operations: enqueue(), dequeue().

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

How does a priority queue work?

A

Elements are dequeued in order of priority rather than order of insertion.

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

What is the difference between a min-heap and a max-heap?

A

Min-Heap: smallest element at root; Max-Heap: largest element at root.

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

What are hash tables used for?

A

Store key-value pairs for fast lookups (O(1) on average).

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

What are common collision resolution techniques for hash tables?

A

Chaining, Open Addressing (Linear Probing, Quadratic Probing, Double Hashing).

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