DSA Flashcards

1
Q

What is an array?

A

A fixed-size collection of elements stored in contiguous memory.

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

What are arrays best used for?

A

Fast access and iteration when the size is known.

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

What is a linked list?

A

A collection of nodes where each node points to the next one.

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

When is a linked list preferred over an array?

A

When frequent insertions/deletions at the beginning or middle are needed.

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

What is a stack?

A

A Last-In-First-Out (LIFO) data structure.

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

What are common operations on a stack?

A

push, pop, peek

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

What is a queue?

A

A First-In-First-Out (FIFO) data structure.

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

What are common operations on a queue?

A

enqueue, dequeue, peek

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

What is a hash table?

A

A structure that maps keys to values using a hash function.

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

What makes hash tables fast?

A

Average O(1) lookup, insert, and delete time.

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

What is a set?

A

A collection of unique elements, often implemented with a hash table.

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

What is a tree?

A

A hierarchical data structure with nodes and parent-child relationships.

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

What is a binary tree?

A

A tree where each node has at most 2 children.

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

What is a binary search tree (BST)?

A

A binary tree where left < root < right.

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

What are BSTs good for?

A

Fast lookups, insertions, and deletions in sorted order.

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

What is a balanced BST?

A

A BST that maintains height near log(n), like AVL or Red-Black Trees.

17
Q

What is a heap?

A

A tree-based structure where the parent is greater or smaller than children.

18
Q

What is a min-heap?

A

A heap where the parent is always ≤ its children.

19
Q

What is a max-heap?

A

A heap where the parent is always ≥ its children.

20
Q

What is a graph?

A

A set of nodes (vertices) connected by edges.

21
Q

What are common ways to represent a graph?

A

Adjacency list and adjacency matrix.

22
Q

What is BFS (Breadth-First Search)?

A

A graph traversal method that explores neighbors level by level.

23
Q

What is DFS (Depth-First Search)?

A

A traversal that goes as deep as possible before backtracking.

24
Q

What is Dijkstra’s algorithm used for?

A

Shortest path in weighted graphs with non-negative edges.

25
What is dynamic programming (DP)?
A method for solving problems by storing results of subproblems.
26
What is memoization?
Top-down DP that caches results of recursive calls.
27
What is tabulation?
Bottom-up DP that fills a table iteratively.
28
What is a greedy algorithm?
An algorithm that makes the locally optimal choice at each step.
29
What is binary search used for?
Finding a value in a sorted array in O(log n) time.
30
When should recursion be used?
When a problem can be broken into similar subproblems.
31
What is backtracking?
Trying all possibilities and undoing choices that don't work.
32
What is a trie?
A tree-like structure used to store prefixes efficiently.
33
What is a sliding window technique?
A method to reduce time complexity in problems involving subarrays or substrings.
34
What is two pointers technique?
Using two indices to iterate through a structure from both ends or at different speeds.
35
What is a union-find (disjoint set)?
A structure for tracking a set of elements partitioned into disjoint subsets.
36
What are common operations in union-find?
find, union (with path compression and union by rank)
37
What is topological sorting?
Ordering of nodes in a directed acyclic graph (DAG) such that for every edge u → v, u comes before v.