Data Structures and Algorithms
- 78Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
- spaceFlip card
- KI knew it
- DI didn't know it
- ←Previous card
- →Next card
What is an algorithm?
A step-by-step set of instructions for solving a problem.
Or swipe the card
78 cards
What is an algorithm?
A step-by-step set of instructions for solving a problem.
How can data representation affect an algorithm?
The way data is organized in memory can significantly affect an algorithm’s time, space, and overall efficiency.
Why could an unordered collection of numbers require linear search?
Without information about the values or their order, each element may need to be checked one at a time.
Why does random guessing not provide a reliable search algorithm?
It may succeed quickly by chance, but its efficiency cannot be reproduced consistently.
What advantage does sorting provide before searching?
Sorting provides information that allows the search space to be eliminated systematically.
What is divide and conquer?
A strategy that repeatedly divides a problem into smaller parts and solves those parts separately.
Why must data be stored contiguously for efficient index-based access?
Equal spacing between elements lets a computer calculate an element’s memory address using arithmetic.
What is constant-time access?
Access that takes a fixed number of steps regardless of the size of the data set, denoted O(1).
What is binary search?
A search algorithm that repeatedly checks the middle element of sorted data and discards the half that cannot contain the target.
What condition is required for binary search?
The data must be sorted.
What is the time complexity of linear search in the worst case?
O(n).
What is the time complexity of binary search?
O(log2n).
What does the notation O(f(n)) represent?
An asymptotic upper bound on an algorithm’s running time or resource use.
What does the notation Ω(f(n)) represent?
An asymptotic lower bound on an algorithm’s running time or resource use.
What does the notation Θ(f(n)) represent?
A tight asymptotic bound when the upper and lower bounds have the same growth rate.
What is the best-case complexity of linear search?
Ω(1).
Why is binary search not automatically faster than sorting?
Binary search is fast only after the data has been sorted, and sorting itself requires additional time.
What is an array?
A contiguous block of memory in which values are stored back-to-back.
Why does a computer use indexes beginning at 0?
Index 0 represents the first memory position, with subsequent positions counted by offsets from it.
How can a computer find the middle of seven array positions?
It can calculate ⌊7/2⌋=3, giving the middle index.
How can a computer find the middle of three remaining elements?
It calculates ⌊3/2⌋=1, the middle index of the reduced range.
What is a bit?
A binary unit that represents either 0 or 1.
How many bits are in one byte?
Eight bits.
What does random access memory mean in practice?
A computer can access a particular byte directly in constant time using its address.
What is the main advantage of an array?
Fast random access to any element by index, typically in O(1) time.
What is the main limitation of a fixed-size array?
Its capacity must be chosen in advance, and it may not be able to grow if adjacent memory is occupied.
What is the cost of relocating an array?
All existing elements must be copied to the new memory region, requiring nonzero time.
What is bubble sort?
A sorting algorithm that repeatedly compares adjacent elements and swaps them when they are out of order.
What is the pseudocode for bubble sort?
Repeat until no swaps occur: for i from 0 to n−2, compare elements i and i+1 and swap them if they are out of order.
Why does bubble sort compare only through index n−2?
Because each comparison also examines index i+1, and the final valid pair begins at n−2.
What is selection sort?
A sorting algorithm that repeatedly finds the smallest remaining element and places it in the next position.
What is the pseudocode idea behind selection sort?
For each index i from 0 to n−1, find the smallest element from i through n−1 and swap it with element i.
What is the worst-case time complexity of bubble sort?
O(n2).
What is the worst-case time complexity of selection sort?
O(n2).
Why can lower-order terms be ignored in asymptotic analysis?
For very large n, the highest-order term dominates the growth rate.
What is merge sort?
A sorting algorithm that recursively divides data into halves, sorts the halves, and merges them.
Why is merge sort faster than bubble sort and selection sort?
It divides the problem repeatedly and performs the merging more efficiently, achieving O(nlogn) time instead of O(n2).
What space trade-off does merge sort make?
It uses additional temporary space to store and merge sublists.
What does it mean for a sorting algorithm to operate in place?
It rearranges elements within the existing storage rather than requiring a separate large temporary structure.
What is the main space-time trade-off illustrated by merge sort?
Using more space can reduce the time required to sort the data.
What is a linked list?
A dynamic data structure made of nodes in which each node stores data and a reference to the next node.
What is a node in a linked list?
A unit containing a data value and information identifying the next node.
How does a linked list represent an arrow between nodes?
It stores the memory address or index of the next node as part of the current node.
What is the main advantage of a linked list over a fixed-size array?
It can grow or shrink dynamically without requiring all elements to occupy contiguous memory.
How can an element be removed from a linked list?
Update the preceding node’s pointer so that it skips the removed node.
What is the time complexity of searching an unsorted linked list?
O(n).
Why can’t a linked list use binary search as efficiently as an array?
Its nodes are not guaranteed to be evenly spaced or contiguous, so an index calculation cannot directly locate the middle node.
What space overhead does a linked list add?
Each node requires storage for both its data and a pointer to another node.
What is a tree data structure?
A hierarchical structure in which nodes are connected through parent-child relationships.
What is a binary search tree?
A tree in which each node has at most two children, with smaller values in the left subtree and larger values in the right subtree.
What are the root, left child, and right child of a tree?
The root is the starting node; the left and right children are the nodes reached through its left and right links.
How does a binary search tree support efficient searching?
At each node, the comparison determines whether to continue into the left or right subtree.
What is the ideal search or insertion complexity in a balanced binary search tree?
O(log2n).
How can a binary search tree lose its efficiency?
If values are inserted in an unfortunate order, the tree can become unbalanced and resemble a linked list.
What is tree rebalancing?
Reorganizing a tree to keep its height small and maintain efficient operations.
What is a hash table?
A data structure that uses a hash function to map keys to array locations called buckets.
What is a hash function?
A function that converts a key into an index or bucket location.
How could names be hashed using their first letter?
The first letter can be converted to a character code and adjusted to produce an array index.
What is a collision in a hash table?
A situation in which multiple keys are mapped to the same bucket.
How can a hash table handle collisions?
Store multiple entries in a linked structure associated with the same bucket.
What determines the efficiency of a hash table?
The quality of its hash function and how evenly keys are distributed among buckets.
What is the ideal time complexity of hash-table access?
Approximately O(1).
What is the worst-case time complexity of hash-table access?
O(n).
How does a Python dictionary relate to a hash table?
A Python dictionary is an abstraction that associates keys with values using hash-table principles.
How does a Python list relate to an array?
It provides array-like indexed storage with added support for dynamic growth and shrinking.
What is a Boolean value?
A value representing one of two logical states, typically true or false.
What is a floating-point value?
A representation of a real number that may include a fractional or decimal component.
What is an integer type?
A data type used to represent whole numbers without a fractional component.
What is a string?
A sequence of characters.
What is a set?
A collection of values that contains no duplicates.
What is a tuple?
A grouped collection of values, such as an x,y coordinate or latitude-longitude pair.
Why does a floating-point type have limited precision?
It is allocated a fixed number of bits, so only a finite amount of information can be stored.
What general trade-off connects arrays, linked lists, trees, and hash tables?
Improving time efficiency often requires additional space or sacrifices flexibility elsewhere.
How do arrays and linked lists differ in access and growth?
Arrays provide O(1) indexed access but are difficult to resize; linked lists grow and shrink easily but require O(n) traversal for access.
How do binary search trees improve on linked lists?
They organize values hierarchically so that searching can take O(logn) time when the tree is balanced.
What additional resource does a tree require compared with an array?
Space for pointers to its child nodes.
Why might a program allocate extra unused array capacity?
To allow future growth without immediately relocating the array.
Why is data structure design important in software and databases?
Data structures and algorithms together determine both the correctness and efficiency of operations.

Ask anything
We've read this whole study set, so questions about it get the best answers.