Data Structures and Algorithms Flashcards
7 cards from real CCS practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.
Read the first 7 Data Structures and Algorithms flashcards as text
Which data structure follows the LIFO (Last In, First Out) principle?
Answer: Stack
A stack operates on LIFO, where the last element added is the first one removed.
What is the time complexity of accessing an element in an array by index?
Answer: O(1)
Array index access is O(1) because elements are stored at contiguous memory locations.
In a binary search tree (BST), which traversal produces nodes in sorted ascending order?
Answer: In-order
In-order traversal (left, root, right) visits BST nodes in ascending sorted order.
What is the worst-case time complexity of quicksort?
Answer: O(n²)
Quicksort degrades to O(n²) when the pivot is consistently the smallest or largest element.
Which data structure is best suited for implementing a breadth-first search (BFS)?
Answer: Queue
BFS uses a queue to process nodes level by level in FIFO order.
What does a hash table use to map keys to their storage locations?
Answer: Hash function
A hash function converts a key into an index used to store and retrieve values in O(1) average time.
Which sorting algorithm has the best average-case time complexity for large datasets?
Answer: Merge sort
Merge sort consistently achieves O(n log n) in all cases, making it optimal for large datasets.