๐ Data Structure and Algorithm ยท subject
Data Structure and Algorithm Data Structures Syllabus
The Data Structures syllabus for Data Structure and Algorithm in full: 8 chapters and 51 topics, every one listed below, plus 51 Data Structures flashcards with answers.
Data Structures syllabus: all 8 chapters
Expand any chapter to see its topics and sub-topics.
-
Arrays
6 topics- Introduction to Arrays
- 1-D Arrays
- 2-D Arrays
- Dynamic Arrays
- Array Operations
- Array Applications
-
Linked Lists
6 topics- Introduction to Linked Lists
- Singly Linked List
- Doubly Linked List
- Circular Linked List
- Linked List Operations
- Linked List Applications
-
Stacks
5 topics- Introduction to Stacks
- Stack Operations
- Array Implementation of Stack
- Linked List Implementation of Stack
- Stack Applications
-
Queues
8 topics- Introduction to Queues
- Queue Operations
- Array Implementation of Queue
- Linked List Implementation of Queue
- Circular Queue
- Priority Queue
- Deque (Double Ended Queue)
- Queue Applications
-
Trees
9 topics- Introduction to Trees
- Binary Trees
- Binary Search Trees
- AVL Trees
- Red-Black Trees
- Segment Trees
- Fenwick Trees
- Tree Traversal Techniques
- Tree Applications
-
Heaps
6 topics- Introduction to Heaps
- Binary Heaps
- Min-Heap
- Max-Heap
- Heap Operations
- Heap Applications
-
Graphs
6 topics- Introduction to Graphs
- Graph Representations
- Graph Traversal Algorithms
- Shortest Path Algorithms
- Minimum Spanning Tree Algorithms
- Graph Applications
-
Hashing
5 topics- Introduction to Hashing
- Hash Functions
- Collision Resolution Techniques
- Hash Table Operations
- Hash Table Applications
Data Structure and Algorithm Data Structures flashcards โ 51 questions with answers
What is an array in data structures?
An array is a linear data structure that stores a fixed-size, contiguous collection of elements of the same data type, accessed by an index. Elements occupy adjacent memory locations.
How is the memory address of an element calculated in a 1-D array?
For a 1-D array, the address of element at index $i$ is $$\text{Address}(A[i]) = B + (i - L) \times w$$ where $B$ is the base address, $L$ is the lower bound of the index, and $w$ is the size (in bytes) of each element.
What is the time complexity of accessing an element by index in an array, and why?
$O(1)$ โ constant time. Because elements are stored contiguously, the address of any index is computed directly with arithmetic, allowing random access without traversal.
What are the time complexities of insertion and deletion at an arbitrary position in a static array?
Both are $O(n)$ in the worst case, because up to $n$ elements may need to be shifted to maintain contiguity.
What is the difference between a static array and a dynamic array?
A static array has a fixed size set at compile/allocation time and cannot grow. A dynamic array can resize at runtime, automatically reallocating to a larger block when it becomes full.
How does a dynamic array grow when it runs out of capacity?
It allocates a new, larger block (commonly double the current capacity), copies all existing elements into it, then frees the old block. This doubling keeps appends amortized $O(1)$.
What is the amortized time complexity of appending to a dynamic array, and why is it not $O(n)$?
Amortized $O(1)$. Although an occasional resize costs $O(n)$ to copy, the doubling strategy spreads that cost across many cheap $O(1)$ appends, averaging to constant time per operation.
In row-major order, how is the address of element $A[i][j]$ computed for a 2-D array?
$$\text{Address}(A[i][j]) = B + \big((i - L_r)\times N_c + (j - L_c)\big)\times w$$ where $B$ is the base address, $N_c$ is the number of columns, $L_r, L_c$ are the lower bounds of rows and columns, and $w$ is the element size.
In column-major order, how is the address of element $A[i][j]$ computed for a 2-D array?
$$\text{Address}(A[i][j]) = B + \big((j - L_c)\times N_r + (i - L_r)\big)\times w$$ where $N_r$ is the number of rows, $L_r, L_c$ are the lower bounds, $w$ is the element size, and $B$ the base address.
What is the difference between row-major and column-major storage order for 2-D arrays?
Row-major stores elements row by row (entire first row, then second, etc.), used by C/C++/Python. Column-major stores column by column, used by Fortran/MATLAB.
How many elements does an $m \times n$ 2-D array contain, and what is its total memory size?
It contains $m \times n$ elements. Total memory is $m \times n \times w$ bytes, where $w$ is the size of each element.
List three common operations performed on arrays.
Traversal (visiting each element), insertion (adding an element at a position), deletion (removing an element), searching (finding an element), and updating (modifying an element's value).
What is array traversal and what is its time complexity?
Traversal is visiting each element of the array exactly once, typically with a loop. Its time complexity is $O(n)$ for $n$ elements.
Name three real-world applications of arrays.
Implementing other data structures (stacks, queues, heaps, hash tables), storing matrices/tables, lookup tables, image pixel grids, and serving as the basis for sorting and searching algorithms.
What is a key limitation of static arrays regarding size?
Their size is fixed at creation; you cannot grow them without allocating a new array and copying. This wastes memory if oversized or causes overflow if undersized.
What is a linked list?
A linked list is a linear data structure where elements (nodes) are stored non-contiguously, each node holding data and one or more pointers/references to other nodes, linked together to form a sequence.
What two fields does a node in a singly linked list contain?
A data field (the value) and a next pointer that references the following node (or null at the end of the list).
What is the time complexity of accessing the $k$-th element in a linked list, and why does it differ from an array?
$O(n)$ in the worst case. Unlike arrays, linked lists have no random access; you must traverse from the head node following next pointers, since nodes are non-contiguous.
What are the main advantages of a linked list over an array?
Dynamic size (grows/shrinks at runtime without reallocation) and $O(1)$ insertion/deletion at a known node without shifting elements. No need for contiguous memory.
What are the main disadvantages of a linked list compared to an array?
No random ($O(1)$) access โ access is $O(n)$; extra memory overhead for storing pointers; poor cache locality due to non-contiguous storage.
Show the other 31 Data Structures flashcards
What distinguishes a doubly linked list from a singly linked list?
Each node in a doubly linked list has two pointers โ next and prev (previous) โ allowing traversal in both directions. A singly linked list has only a next pointer and is one-directional.
What is the extra memory cost of a doubly linked list versus a singly linked list?
One additional pointer (the prev pointer) per node, increasing per-node overhead by the size of one reference.
What defines a circular linked list?
A linked list in which the last node points back to the first node (head) instead of null, forming a closed loop. It can be singly or doubly circular.
In a circular doubly linked list, what do the head's prev pointer and the tail's next pointer reference?
The head's prev pointer references the tail (last node), and the tail's next pointer references the head, forming a bidirectional loop.
What is the time complexity of inserting a node at the head (beginning) of a singly linked list?
$O(1)$ โ constant time. The new node's next is set to the current head, and the head pointer is updated to the new node; no traversal needed.
What is the time complexity of inserting a node at the end of a singly linked list without a tail pointer?
$O(n)$, because you must traverse the entire list to reach the last node before linking the new node. With a maintained tail pointer it becomes $O(1)$.
To delete a given node in $O(1)$ time, which type of linked list makes this easiest and why?
A doubly linked list, because the node's prev pointer lets you directly relink the previous and next nodes without traversing from the head to find the predecessor.
Why is deleting a node (given a pointer to it) $O(n)$ in a singly linked list?
Because the singly linked node has no prev pointer; you must traverse from the head to find the predecessor in order to update its next pointer to bypass the deleted node.
Name three applications of linked lists.
Implementing stacks and queues, dynamic memory management (free lists), undo/redo functionality, hash table chaining for collision handling, polynomial representation, and adjacency lists for graphs.
How are linked lists used to implement polynomials?
Each node stores a term's coefficient and exponent, and nodes are linked in order of exponents. This allows efficient representation and addition/multiplication of sparse polynomials.
What is a stack and which principle governs it?
A stack is a linear data structure that follows the LIFO (Last-In, First-Out) principle: the most recently inserted element is the first one removed.
Name the two primary operations of a stack and what each does.
Push โ adds (inserts) an element to the top of the stack. Pop โ removes and returns the element from the top of the stack.
What do the peek (top) and isEmpty operations do on a stack?
peek/top returns the element at the top without removing it. isEmpty returns true if the stack contains no elements (top indicator points below the first position).
What is the time complexity of push, pop, and peek operations on a stack?
All are $O(1)$ โ constant time โ since they only operate on the top element.
In an array implementation of a stack, what does the 'top' variable represent and what is its initial value for an empty stack?
'top' is the index of the topmost element. For an empty stack it is initialized to $-1$ (no elements). It increments on push and decrements on pop.
What is stack overflow in an array-based stack implementation?
Stack overflow occurs when a push is attempted while the stack is full โ i.e., when $top = size - 1$ โ and there is no room for a new element.
What is stack underflow?
Stack underflow occurs when a pop or peek is attempted on an empty stack (when $top = -1$), so there is no element to remove or return.
What is the main disadvantage of an array implementation of a stack?
Its size is fixed (static), so it can overflow when full, and it may waste memory if the allocated capacity is larger than needed. Resizing requires copying.
In a linked list implementation of a stack, where are push and pop performed and why?
At the head (front) of the list, because insertion and deletion at the head are $O(1)$, giving constant-time push and pop without traversal.
What is the advantage of a linked list implementation of a stack over an array implementation?
It is dynamic โ it grows and shrinks as needed, so there is no fixed-capacity overflow (limited only by available memory) and no wasted preallocated space.
Compare array vs linked list implementations of a stack in terms of memory.
The array version uses contiguous fixed memory with no per-element pointer overhead but may waste or overflow space. The linked list version uses dynamic memory with extra pointer overhead per node but no fixed capacity.
Name three applications of stacks.
Function call management (call stack/recursion), expression evaluation and conversion (infix to postfix/prefix), balanced parentheses checking, undo/redo operations, backtracking, and depth-first search (DFS).
How is a stack used in evaluating arithmetic expressions?
A stack holds operands (and/or operators) during evaluation of postfix/prefix expressions, and is used to convert infix to postfix, ensuring correct operator precedence and order of operations.
Why is a stack used to manage recursive function calls?
Each function call pushes an activation record (parameters, local variables, return address) onto the call stack; when a call returns, its record is popped โ matching the LIFO nature of nested calls.
What does the algorithm for checking balanced parentheses use a stack for?
It pushes each opening bracket and pops on each closing bracket, checking the popped bracket matches. A balanced expression leaves the stack empty at the end with all matches correct.
What is a queue and which principle governs it?
A queue is a linear data structure that follows the FIFO (First-In, First-Out) principle: the first element inserted is the first one removed.
What are the two ends of a queue called, and which operation happens at each?
The rear (or back/tail), where enqueue (insertion) occurs, and the front (or head), where dequeue (removal) occurs.
Name the two primary operations of a queue and what each does.
Enqueue โ adds an element at the rear of the queue. Dequeue โ removes and returns the element from the front of the queue.
What is the key behavioral difference between a stack and a queue?
A stack is LIFO (last-in, first-out) โ insertion and removal occur at the same end (top). A queue is FIFO (first-in, first-out) โ insertion at the rear and removal at the front, opposite ends.
Name three real-world applications of queues.
CPU/process scheduling, print/job spooling, handling requests in web servers, breadth-first search (BFS), buffering data streams (I/O buffers), and call-center request handling.
What problem does a circular queue solve compared to a simple linear array queue?
A circular queue reuses freed front slots by wrapping the rear index around to the start, preventing the 'false overflow' where a linear array queue reports full even though dequeued space exists at the front.
Data Structure and Algorithm Data Structures FAQ
What is in the Data Structure and Algorithm Data Structures syllabus?
Data Structure and Algorithm Data Structures is split into 8 chapters: Arrays, Linked Lists, Stacks, Queues, Trees, Heaps, Graphs and Hashing. Together they contain 51 topics.
How many chapters are in Data Structure and Algorithm Data Structures?
8 chapters, containing 51 topics. The largest chapter is Trees, with 9 topics.
Are there flashcards for Data Structure and Algorithm Data Structures?
Yes โ a 51-card 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.