
Data Structures and Algorithms
Arrays, linked lists, stacks, queues, hash tables, trees, graphs, sorting algorithms, searching algorithms, and time and space complexity.
Cards (24)
- 1Front
What is the time complexity of accessing an element by index in an array?
BackO(1) — arrays support constant-time random access because elements are stored in contiguous memory.
- 2Front
What is the worst-case time complexity of inserting an element at the beginning of an array?
BackO(n) — all existing elements must be shifted one position to make room.
- 3Front
What is the key structural difference between a singly linked list and a doubly linked list?
BackA singly linked list node has one pointer (to the next node); a doubly linked list node has two pointers (to the next and previous nodes).
- 4Front
What is the time complexity of searching for an element in an unsorted linked list?
BackO(n) — the list must be traversed from the head until the element is found or the end is reached.
- 5Front
What abstract data type follows the Last-In, First-Out (LIFO) principle?
BackA stack. The most recently added element is the first to be removed.
- 6Front
What are the two primary operations of a stack and what do they do?
BackPush — adds an element to the top of the stack. Pop — removes and returns the top element.
- 7Front
What abstract data type follows the First-In, First-Out (FIFO) principle?
BackA queue. Elements are added at the rear (enqueue) and removed from the front (dequeue).
- 8Front
What is the average-case time complexity of search, insert, and delete in a hash table?
BackO(1) for all three operations on average, assuming a good hash function and low load factor.
- 9Front
What is a hash collision and how does chaining resolve it?
BackA collision occurs when two keys hash to the same index. Chaining resolves this by storing a linked list (or similar structure) of all entries at that index.
- 10Front
In a binary search tree (BST), what property must hold for every node?
BackAll values in the left subtree are less than the node's value, and all values in the right subtree are greater.
- 11Front
What is the worst-case time complexity of search in a binary search tree?
BackO(n) — occurs when the BST is completely unbalanced (degenerated into a linked list).
- 12Front
What is the height of a complete binary tree with n nodes?
BackO(log n) — the height grows logarithmically with the number of nodes.
- 13Front
What traversal order does in-order traversal of a BST produce?
BackAscending (sorted) order — it visits the left subtree, then the root, then the right subtree.
- 14Front
What is the difference between a graph's adjacency list and adjacency matrix representations?
BackAn adjacency list stores neighbors per vertex (space-efficient for sparse graphs); an adjacency matrix is a 2D array marking edges (O(V²) space, O(1) edge lookup).
- 15Front
What algorithm is used to find the shortest path in an unweighted graph?
BackBreadth-First Search (BFS) — it explores nodes level by level, guaranteeing the shortest path in terms of number of edges.
- 16Front
What is the time complexity of BFS and DFS on a graph with V vertices and E edges?
BackO(V + E) for both BFS and DFS.
- 17Front
What is the average and worst-case time complexity of quicksort?
BackAverage: O(n log n). Worst case: O(n²), which occurs when the pivot is consistently the smallest or largest element.
- 18Front
What sorting algorithm has a guaranteed worst-case time complexity of O(n log n)?
BackMerge sort — it always divides the array in half and merges, regardless of input order.
- 19Front
What is the space complexity of merge sort?
BackO(n) — it requires auxiliary space proportional to the input size for the temporary arrays used during merging.
- 20Front
What is the time complexity of binary search, and what precondition must the data satisfy?
BackO(log n). The data must be sorted before binary search can be applied.
- 21Front
What does Big-O notation describe about an algorithm?
BackIt describes the upper bound on the algorithm's growth rate — the worst-case time or space complexity as input size n grows.
- 22Front
What is the difference between time complexity and space complexity?
BackTime complexity measures how the number of operations grows with input size; space complexity measures how the memory usage grows with input size.
- 23Front
What sorting algorithm is most efficient for nearly sorted data due to its adaptive nature?
BackInsertion sort — it runs in O(n) time on nearly sorted data because few elements need to be shifted.
- 24Front
What is a heap, and what time complexity does it provide for extracting the minimum (or maximum) element?
BackA heap is a complete binary tree satisfying the heap property (min-heap: parent ≤ children). Extracting the min/max takes O(log n) after reheapification.
Study this deck free
Create a free account to flip through these flashcards, quiz yourself, play match, and track what you've mastered — or fork the deck to make it your own.