DSA Flashcards
What is an array?
A fixed-size collection of elements stored in contiguous memory.
What are arrays best used for?
Fast access and iteration when the size is known.
What is a linked list?
A collection of nodes where each node points to the next one.
When is a linked list preferred over an array?
When frequent insertions/deletions at the beginning or middle are needed.
What is a stack?
A Last-In-First-Out (LIFO) data structure.
What are common operations on a stack?
push, pop, peek
What is a queue?
A First-In-First-Out (FIFO) data structure.
What are common operations on a queue?
enqueue, dequeue, peek
What is a hash table?
A structure that maps keys to values using a hash function.
What makes hash tables fast?
Average O(1) lookup, insert, and delete time.
What is a set?
A collection of unique elements, often implemented with a hash table.
What is a tree?
A hierarchical data structure with nodes and parent-child relationships.
What is a binary tree?
A tree where each node has at most 2 children.
What is a binary search tree (BST)?
A binary tree where left < root < right.
What are BSTs good for?
Fast lookups, insertions, and deletions in sorted order.
What is a balanced BST?
A BST that maintains height near log(n), like AVL or Red-Black Trees.
What is a heap?
A tree-based structure where the parent is greater or smaller than children.
What is a min-heap?
A heap where the parent is always ≤ its children.
What is a max-heap?
A heap where the parent is always ≥ its children.
What is a graph?
A set of nodes (vertices) connected by edges.
What are common ways to represent a graph?
Adjacency list and adjacency matrix.
What is BFS (Breadth-First Search)?
A graph traversal method that explores neighbors level by level.
What is DFS (Depth-First Search)?
A traversal that goes as deep as possible before backtracking.
What is Dijkstra’s algorithm used for?
Shortest path in weighted graphs with non-negative edges.