Basics Flashcards
What is the difference between an array and a linked list?
Arrays allow random access (O(1)) but have fixed sizes; linked lists allow dynamic memory allocation but require sequential access (O(n)).
What is the time complexity of accessing an element in an array?
O(1) (constant time).
What is the time complexity of accessing an element in a linked list?
O(n) (linear time).
What are the advantages of a doubly linked list over a singly linked list?
Doubly linked lists allow backward traversal and easier deletion but use extra memory.
What is a stack? What are its key operations?
LIFO (Last In, First Out), operations: push(), pop(), peek().
What is a queue? How does it differ from a stack?
FIFO (First In, First Out), operations: enqueue(), dequeue().
How does a priority queue work?
Elements are dequeued in order of priority rather than order of insertion.
What is the difference between a min-heap and a max-heap?
Min-Heap: smallest element at root; Max-Heap: largest element at root.
What are hash tables used for?
Store key-value pairs for fast lookups (O(1) on average).
What are common collision resolution techniques for hash tables?
Chaining, Open Addressing (Linear Probing, Quadratic Probing, Double Hashing).