Data Structures Course
- 77Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
- spaceFlip card
- KI knew it
- DI didn't know it
- ←Previous card
- →Next card
What is a data structure?
A way to store, organize, and manipulate data. They are theoretical concepts that can be implemented in any programming language.
Or swipe the card
77 cards
What is a data structure?
A way to store, organize, and manipulate data. They are theoretical concepts that can be implemented in any programming language.
What are the two main categories of data structures?
Linear and non-linear data structures.
List four linear data structures mentioned.
Array, linked list, stack, queue.
List two non-linear data structures mentioned.
Trees and graphs.
What is the difference between a data type and a data structure?
Data types are simple pieces of data like integers, booleans, strings. Data structures store those data types (e.g., an array stores numbers or strings).
What is a fixed-size array?
An array whose size cannot change after initialization. The size is defined when created and cannot be expanded.
What is a dynamic array?
An array that can increase or decrease its size based on the number of elements. In JavaScript, arrays are dynamic.
What is the time complexity to initialize a fixed-size array of size n?
O(n) – because each of the n memory slots needs to be allocated or initialized.
Why can we access any element in an array in constant time O(1)?
Because arrays store elements in contiguous memory locations. Given the starting memory address, we can compute the address of any index by adding the index to the base address.
What is the time complexity of inserting an element at an arbitrary position in a fixed-size array?
O(n) – because elements after the insertion point must be shifted to the right.
What is the time complexity of deleting an element from an arbitrary position in a fixed-size array?
O(n) – because elements after the deletion point must be shifted to the left to fill the gap.
What is the time complexity of appending an element to the end of a dynamic array?
Typically O(1) amortized, but may be O(n) when the array needs to resize (e.g., doubling in size and copying all elements).
What is the time complexity of popping an element from the end of an array?
O(1) – because no shifting is needed; the last element is simply removed.
What are the two types of arrays discussed?
Fixed-size (static) arrays and dynamic arrays.
What is a node in a linked list?
A node contains a value and a pointer (next) to the next node in the list.
What is the head of a linked list?
The head is the first node in the linked list. It provides access to the entire list.
How do you access the last element in a singly linked list?
Traverse from the head until reaching a node whose next pointer is null. That node is the last.
What is the time complexity of accessing an element at an arbitrary index in a singly linked list?
O(n) – because you must traverse from the head to that index.
What is the time complexity of inserting a node at the beginning or end of a singly linked list if you have a reference to the head and tail?
O(1) – constant time.
How do you delete a node in a singly linked list given a reference to the node to delete?
You need access to the previous node. Set previous.next = node.next.
What is a circular linked list?
A singly linked list where the last node's next pointer points back to the head, creating a circle.
What are the advantages of a circular linked list over a regular singly linked list?
Constant time insertion and deletion at both the beginning and end, if you store the tail node.
What is a doubly linked list?
A linked list where each node has a pointer to the next node and a pointer to the previous node.
What is the main advantage of a doubly linked list over a singly linked list?
If you have a reference to a node, you can insert or delete before or after it in O(1) time, because you have access to the previous node.
What is a disadvantage of a doubly linked list compared to a singly linked list?
It uses more memory because each node stores an additional pointer (prev), and operations are more complex due to updating two pointers.
What is the FIFO property of a queue?
First In, First Out – the first element added to the queue is the first one to be removed.
What are the four basic operations of a queue?
Enqueue (put), dequeue (pop), peek (front), and isEmpty.
What is the time complexity of enqueue and dequeue in a queue implemented with a singly linked list (with tail pointer)?
Both are O(1) – constant time.
Why is an array not ideal for implementing a queue if both enqueue and dequeue need to be O(1)?
Because either enqueue (if front is at beginning) or dequeue (if front is at end) would be O(n) due to shifting elements.
What is the LIFO property of a stack?
Last In, First Out – the most recently added element is the first to be removed.
What are the basic operations of a stack?
Push (add), pop (remove), peek (top), and isEmpty.
What is the time complexity of push and pop operations on a stack?
Both are O(1) – constant time.
Can an array be used to implement a stack efficiently?
Yes, because push and pop occur at the same end (the end of the array), which are O(1) amortized operations.
How can two stacks be used to implement a queue?
Use an input stack for enqueue and an output stack for dequeue. To enqueue, pop all from input to output, push new element onto input, then pop all from output back to input. To dequeue, pop from input.
What is a binary tree?
A tree data structure where each node has at most two children, called left and right children.
What is the root of a binary tree?
The topmost node of the tree, which provides access to all other nodes.
What is a leaf node in a binary tree?
A node that has no children (both left and right are null).
What is the height of a binary tree?
The largest number of edges on any path from the root to a leaf node.
What is the depth (or level) of a node?
The number of edges from the node to the root.
Explain breadth-first search (BFS) traversal of a binary tree.
Use a queue. Start by enqueuing the root. While queue not empty: dequeue a node, process it, then enqueue its left and right children (if they exist). This visits nodes level by level.
Explain depth-first search (DFS) traversal of a binary tree.
Use a stack (or recursion). Start by pushing the root. While stack not empty: pop a node, process it, then push its right child (if exists) then left child (if exists) to control order. This goes deep along one branch before backtracking.
What is the time complexity of inserting a node into an arbitrary binary tree (not a binary search tree)?
O(n) – because you may need to traverse the tree using BFS to find the first available empty slot.
How do you delete a node with two children in a binary tree?
Find the deepest rightmost leaf node (or deepest node in the tree), copy its data to the node to delete, then delete that leaf node.
What is the maximum number of nodes in a binary tree of height h?
2h+1−1
What is the maximum height of a binary tree with n nodes?
n−1 (when the tree is essentially a linked list, each node having only one child).
What is an in-order traversal of a binary tree?
Process left subtree, visit current node, then process right subtree.
What is a pre-order traversal of a binary tree?
Visit current node, then process left subtree, then process right subtree.
What is a post-order traversal of a binary tree?
Process left subtree, then process right subtree, then visit current node.
What is a full binary tree?
A binary tree in which every node has either 0 or 2 children (no node has only one child).
What is a complete binary tree?
A binary tree where all levels except the last are completely filled, and all nodes in the last level are as far left as possible.
What is a balanced binary tree?
A binary tree where for every node, the height of its left and right subtrees differ by at most 1.
What is a perfect binary tree?
A binary tree where all internal nodes have exactly two children and all leaf nodes are at the same level (all levels are completely filled).
What is the defining property of a binary search tree (BST)?
For any node, all values in its left subtree are less than the node's value, and all values in its right subtree are greater than (or equal to) the node's value.
What is the time complexity of searching for a value in a BST?
O(h), where h is the height of the tree. In a balanced BST, h = O(log n).
How do you insert a new value into a BST?
Start at the root. Compare the value with the current node: if less, go left; if greater, go right. Repeat until you reach a null child, then insert the new node there.
What are the three cases for deleting a node from a BST?
- Node has no children (leaf): simply remove it. 2. Node has one child: replace the node with its child. 3. Node has two children: find the maximum in the left subtree (or minimum in the right subtree), copy its value to the node, then delete that maximum/minimum node (which falls under case 1 or 2).
What is the time complexity of deletion in a BST?
O(h), where h is the height. In the worst case, you may need to traverse to find the node and then find the replacement.
What is a heap?
A complete binary tree that satisfies the heap property: for a max-heap, every parent node has a value greater than or equal to its children; for a min-heap, every parent has a value less than or equal to its children.
How is a heap typically implemented?
Using an array. Because it is a complete binary tree, we can store nodes level by level and use index arithmetic to find children and parent.
What is the time complexity of inserting an element into a heap?
O(log n) – because you add the element at the end and then sift it up (swap with parent until heap property is restored).
How do you remove the maximum (or minimum) element from a heap?
Replace the root with the last element in the array, remove the last element, then sift down the new root (swap with the larger child in a max-heap) until the heap property is restored.
What is heap sort?
A sorting algorithm that builds a heap from an unsorted array (O(n log n)) and then repeatedly extracts the maximum (or minimum) element to produce a sorted array (O(n log n)). Overall O(n log n).
What is the time complexity of building a heap by inserting n elements one by one?
O(n log n) – each insertion is O(log n), so total O(n log n).
What is a graph?
A non-linear data structure consisting of a set of vertices (nodes) and a set of edges (connections between vertices).
What is an undirected graph?
A graph where edges have no direction; the order of vertices in an edge does not matter. An edge (u, v) implies both u to v and v to u connections.
What is a directed graph (digraph)?
A graph where edges have direction; the order of vertices matters. An edge from u to v does not imply an edge from v to u.
What is a weighted graph?
A graph where each edge has a numerical weight (or cost) associated with it.
What is an unweighted graph?
A graph where edges have no weights; all edges are considered equal.
What is a cyclic graph?
A graph that contains at least one cycle – a path that starts and ends at the same vertex following directed edges.
What is an acyclic graph?
A graph with no cycles.
What is a disconnected graph?
A graph where at least one vertex is not connected to the others by any path.
What is an adjacency matrix representation of a graph?
A 2D array of size V x V, where entry (i, j) is 1 (or weight) if there is an edge from vertex i to vertex j, and 0 otherwise. For undirected graphs, the matrix is symmetric.
What is an adjacency list representation of a graph?
An array of lists, where each list contains the neighbors of a vertex (and optionally edge weights). For a vertex i, the list holds vertices j such that there is an edge from i to j.
What is hashing?
A process that takes input data and passes it through a hash function to produce a fixed-size output (digest or hash). Ideally, each unique input produces a unique output.
What is a perfect hash function?
A hash function that maps every input to a unique output, so no two keys map to the same index (no collisions).
What is a hash collision?
When two different inputs produce the same hash output.
How is hashing used to achieve constant-time lookup in a hash table?
The hash function computes an index from the key. The key-value pair is stored at that index in an array. To retrieve, recompute the hash and access the array at that index.

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