🌍 Data Structures & Algorithms · subject
Data Structures & Algorithms Linear Data Structures Syllabus
The Linear Data Structures syllabus for Data Structures & Algorithms in full: 4 chapters and 14 topics, every one listed below, plus 50 Linear Data Structures flashcards with answers.
Linear Data Structures syllabus: all 4 chapters
Expand any chapter to see its topics and sub-topics.
-
Arrays & Strings
4 topics- Static and Dynamic Arrays
- Array Techniques
- String Manipulation
- Multidimensional Arrays and Matrices
-
Linked Lists
3 topics- Singly Linked Lists
- Doubly and Circular Linked Lists
- Linked List Techniques
-
Stacks
3 topics- Stack ADT and Operations
- Stack Implementations
- Stack Applications
-
Queues & Deques
4 topics- Queue ADT and Operations
- Queue Variants
- Monotonic Queue
- Queue using Stacks and Vice Versa
Data Structures & Algorithms Linear Data Structures flashcards — 50 questions with answers
What is a static array, and what is its defining constraint?
A static array is a contiguous, fixed-size block of memory holding elements of the same type. Its size is fixed at allocation time and cannot change during execution.
What is a dynamic array and how does it grow?
A dynamic array (e.g., C++ vector, Python list) is a resizable array. When capacity is exceeded, it allocates a larger block (typically doubling), copies existing elements over, and frees the old block.
Why does appending $n$ elements to a dynamic array cost $O(n)$ total despite occasional resizes?
Because doubling makes resizes geometrically rare; the total copy work is $\sum 2^{k} \approx 2n$, giving an amortized cost of $O(1)$ per append and $O(n)$ overall.
What is the time complexity of accessing element at index $i$ in an array, and why?
$O(1)$. The address is computed directly as $\text{base} + i \times \text{size\_of\_element}$, so no traversal is needed.
What is the cost of inserting or deleting at an arbitrary position in an array of size $n$?
$O(n)$, because on average $\frac{n}{2}$ elements must be shifted to fill or make room.
Compare an array and a linked list on random access and insertion at the front.
Array: random access $O(1)$, front insertion $O(n)$. Linked list: random access $O(n)$, front insertion $O(1)$.
Describe the two-pointer technique and a problem it solves.
Two pointers traverse a structure from different positions (e.g., both ends or fast/slow) to reduce complexity. Example: finding a pair summing to a target in a sorted array in $O(n)$ instead of $O(n^{2})$.
What is the sliding window technique used for?
Maintaining a contiguous subrange whose bounds move to satisfy a condition, solving subarray/substring problems (e.g., max sum of size $k$, longest substring without repeats) in $O(n)$.
What is a prefix sum array and how does it enable range-sum queries?
$P[i]$ stores the sum of the first $i$ elements. The sum of range $[l, r]$ is computed in $O(1)$ as $P[r+1] - P[l]$.
How does Kadane's algorithm find the maximum subarray sum?
It scans once, keeping $\text{cur} = \max(x, \text{cur} + x)$ and tracking the best value seen. Runs in $O(n)$ time, $O(1)$ space.
What does it mean for an in-place array algorithm to use $O(1)$ auxiliary space?
It rearranges elements within the original array using only a constant amount of extra memory, regardless of input size (e.g., in-place reversal by swapping ends inward).
In most languages, are strings mutable or immutable, and what is a consequence?
Strings are typically immutable (e.g., Java, Python). Each modification creates a new string, so building a string by repeated concatenation costs $O(n^{2})$; use a mutable builder for $O(n)$.
How do you check if two strings are anagrams efficiently?
Compare character-frequency counts. Using a fixed-size count array over the alphabet gives $O(n)$ time and $O(1)$ extra space.
What is the naive substring-search time complexity, and name a faster algorithm.
Naive search is $O(nm)$ for text length $n$ and pattern length $m$. The KMP algorithm runs in $O(n + m)$ using a prefix (failure) function.
How is a 2D matrix of dimensions $m \times n$ stored in row-major order, and what is the address formula?
Rows are stored consecutively. The element at $(i, j)$ has offset $\text{base} + (i \times n + j) \times \text{size}$.
How do you transpose a square matrix in place?
For all $i < j$, swap $A[i][j]$ with $A[j][i]$. This runs in $O(n^{2})$ time with $O(1)$ extra space.
How can you rotate an $n \times n$ matrix 90° clockwise in place?
Transpose the matrix, then reverse each row. Both steps are $O(n^{2})$ and use $O(1)$ extra space.
What is the total number of elements and the space complexity of an $m \times n$ matrix?
It has $m \times n$ elements and uses $O(mn)$ space.
Define a singly linked list node and its structure.
A node holds a data field and a single pointer 'next' to the following node. The list is accessed via a 'head' pointer; the last node's next is null.
What are the time complexities of insertion at the head vs. search in a singly linked list?
Head insertion is $O(1)$; search (and access by index) is $O(n)$ because nodes must be traversed sequentially.
Show the other 30 Linear Data Structures flashcards
How do you reverse a singly linked list iteratively?
Walk the list with three pointers (prev, cur, next), redirecting each node's next to prev. Runs in $O(n)$ time, $O(1)$ space; return prev as the new head.
How does the slow/fast pointer method find the middle of a linked list?
Advance slow by one and fast by two per step. When fast reaches the end, slow is at the middle. Time $O(n)$, space $O(1)$.
How do you detect a cycle in a linked list (Floyd's algorithm)?
Use slow (one step) and fast (two steps) pointers. If they ever meet, a cycle exists; if fast reaches null, there is no cycle. Time $O(n)$, space $O(1)$.
What distinguishes a doubly linked list from a singly linked list?
Each node has both 'next' and 'prev' pointers, enabling $O(1)$ bidirectional traversal and $O(1)$ deletion of a known node, at the cost of extra memory per node.
What defines a circular linked list?
The last node points back to the first (in singly-circular), so there is no null terminator; traversal can loop indefinitely and any node can serve as a starting point.
Give one advantage and one disadvantage of a doubly linked list vs. a singly linked list.
Advantage: constant-time deletion of a given node and backward traversal. Disadvantage: extra memory for the prev pointer and more pointer updates per operation.
How do you delete a node given only a pointer to it (not the head) in a singly linked list?
Copy the next node's data into the current node, then bypass the next node by setting current.next = current.next.next. This fails only for the tail node.
What is a sentinel (dummy) node and why is it useful in linked lists?
A placeholder node before the head that removes special-case handling of empty lists or head insertions/deletions, simplifying code.
How do you merge two sorted linked lists into one sorted list?
Use a dummy head and repeatedly attach the smaller of the two current nodes, advancing that pointer, until one list is exhausted; append the remainder. Time $O(n + m)$.
Define the Stack ADT and its ordering discipline.
A stack is a linear collection with Last-In-First-Out (LIFO) order: the most recently added element is the first removed.
Name the core stack operations and their time complexities.
push (add to top), pop (remove top), peek/top (view top), isEmpty — all $O(1)$.
What error conditions are associated with stack operations?
Stack overflow (push onto a full fixed-capacity stack) and stack underflow (pop or peek on an empty stack).
Compare array-based and linked-list-based stack implementations.
Array-based: cache-friendly, may need resizing, possible fixed capacity. Linked-list-based: grows dynamically with no resizing, but uses extra memory per node and has poorer locality. Both give $O(1)$ push/pop.
How is a stack used to check balanced parentheses?
Push each opening bracket; on a closing bracket, pop and verify it matches. The string is balanced if every close matches and the stack is empty at the end.
Which traversal order does the call stack impose, and name one stack application in expression handling.
LIFO. Applications include evaluating postfix expressions, converting infix to postfix, and function call management / recursion unwinding.
How do you evaluate a postfix (RPN) expression with a stack?
Push operands; on an operator, pop the top two operands, apply it, and push the result. The final remaining value is the answer. Time $O(n)$.
Define the Queue ADT and its ordering discipline.
A queue is a linear collection with First-In-First-Out (FIFO) order: the earliest added element is the first removed.
Name the core queue operations and their time complexities.
enqueue (add at rear), dequeue (remove from front), front/peek, isEmpty — all $O(1)$ with a proper implementation.
Why is a circular array preferred over a plain array for queue implementation?
A circular array reuses freed front slots by wrapping indices with modulo, giving $O(1)$ enqueue/dequeue without shifting elements or wasting space.
In a circular queue of capacity $C$, how are the rear and front indices advanced?
Using modular arithmetic: $\text{rear} = (\text{rear} + 1) \bmod C$ and $\text{front} = (\text{front} + 1) \bmod C$.
What is a deque (double-ended queue)?
A linear structure allowing insertion and removal at both the front and the rear, each in $O(1)$. It generalizes both stacks and queues.
What is a priority queue and how does it differ from an ordinary queue?
A priority queue dequeues the element with the highest priority rather than the earliest inserted. It is typically backed by a heap, giving $O(\log n)$ insert and extract.
What is a circular queue and one problem it solves?
A queue whose storage wraps around a fixed-size array. It avoids the wasted-space problem of a linear array queue where front advances but freed slots cannot be reused.
What is a monotonic queue and what invariant does it maintain?
A deque that keeps its elements in strictly increasing or decreasing order by discarding elements that violate the order before inserting a new one, enabling $O(1)$ min/max queries.
How does a monotonic deque compute the maximum of every sliding window of size $k$?
Maintain a decreasing deque of indices: pop smaller values from the back before pushing, pop the front if it falls outside the window; the front holds the window max. Total time $O(n)$.
Why does the sliding-window-maximum monotonic-queue algorithm run in $O(n)$ despite nested pops?
Each element is pushed and popped from the deque at most once, so the total number of operations is bounded by $2n$, giving amortized $O(1)$ per element.
How do you implement a queue using two stacks?
Use an 'in' stack for enqueue. For dequeue, if the 'out' stack is empty, pop all elements from 'in' into 'out' (reversing order), then pop from 'out'. Amortized $O(1)$ per operation.
How do you implement a stack using two queues (making push costly)?
On push, enqueue the new element into the empty queue, then move all elements from the other queue behind it, so the newest is always at the front. Push is $O(n)$; pop/top are $O(1)$.
Compare LIFO and FIFO structures with a real-world example of each.
LIFO (stack): browser back button / undo history. FIFO (queue): a printer job queue or people waiting in line. Stack removes newest first; queue removes oldest first.
Summarize the average time complexities for array, linked list, stack, and queue on their primary operations.
Array: access $O(1)$, insert/delete $O(n)$. Linked list: access $O(n)$, head insert/delete $O(1)$. Stack: push/pop/peek $O(1)$. Queue: enqueue/dequeue $O(1)$.
Data Structures & Algorithms Linear Data Structures FAQ
What is in the Data Structures & Algorithms Linear Data Structures syllabus?
Data Structures & Algorithms Linear Data Structures is split into 4 chapters: Arrays & Strings, Linked Lists, Stacks and Queues & Deques. Together they contain 14 topics.
How many chapters are in Data Structures & Algorithms Linear Data Structures?
4 chapters, containing 14 topics. The largest chapter is Arrays & Strings, with 4 topics.
Are there flashcards for Data Structures & Algorithms Linear Data Structures?
Yes — a 50-card Linear Data Structures deck, printed in full in the flashcards section of this page and available in the Examius app with spaced repetition. The free plan covers one exam of your choice, including its flashcards; Examius Pro, a one-time purchase, unlocks every other exam and deck.