🇵🇰 CSS Computer Science · subject
CSS Computer Science Algorithms & Data Structures Syllabus
The Algorithms & Data Structures syllabus for CSS Computer Science in full: 5 chapters and 16 topics, every one listed below, plus 56 Algorithms & Data Structures flashcards with answers.
Algorithms & Data Structures syllabus: all 5 chapters
Expand any chapter to see its topics and sub-topics.
-
Algorithm Analysis
3 topics- Properties & Criteria of Algorithms
- Asymptotic Notation
- Recursion
-
Linear Data Structures
4 topics- Abstract Data Types
- Lists & Linked Lists
- Stacks
- Queues & Circular Queues
-
Searching & Sorting
3 topics- Linear & Binary Search
- Comparison Sorts
- Hash Tables & Hashing
-
Trees & Graphs
4 topics- Binary Trees & BST
- Balanced Trees
- Graph Representations & Traversals
- Heuristic & Genetic Search
-
Cryptographic Algorithms
2 topics- Symmetric Encryption (DES)
- Asymmetric Encryption (RSA)
CSS Computer Science Algorithms & Data Structures flashcards — 56 questions with answers
What are the five required properties of a well-defined algorithm?
Input (zero or more), Output (at least one), Definiteness (each step is precise/unambiguous), Finiteness (terminates after finite steps), and Effectiveness (each step is basic enough to be carried out).
What distinguishes correctness, efficiency, and generality as criteria for evaluating an algorithm?
Correctness: produces the right output for all valid inputs. Efficiency: uses minimal time and space resources. Generality: solves the whole class of problems, not just one instance.
Define Big-O notation formally.
f(n) = O(g(n)) if there exist positive constants c and n0 such that 0 ≤ f(n) ≤ c·g(n) for all n ≥ n0. It is an asymptotic upper bound on growth rate.
What does Big-Omega (Ω) notation describe?
An asymptotic lower bound: f(n) = Ω(g(n)) if there exist constants c, n0 > 0 such that f(n) ≥ c·g(n) for all n ≥ n0.
What does Big-Theta (Θ) notation mean?
A tight bound: f(n) = Θ(g(n)) means f is bounded both above and below by g asymptotically, i.e. f(n) = O(g(n)) AND f(n) = Ω(g(n)).
Order these complexities from fastest to slowest growth: O(n²), O(log n), O(n log n), O(1), O(2ⁿ), O(n).
O(1) < O(log n) < O(n) < O(n log n) < O(n²) < O(2ⁿ).
What is the difference between best-case, worst-case, and average-case complexity?
Best-case: minimum running time over all inputs of size n. Worst-case: maximum running time (the usual guarantee). Average-case: expected running time over the distribution of inputs.
What are the two essential components every recursive algorithm must have?
A base case (terminating condition that stops recursion) and a recursive case (which calls itself on a smaller subproblem moving toward the base case).
What is the difference between direct and indirect recursion?
Direct recursion: a function calls itself. Indirect (mutual) recursion: function A calls function B, which in turn calls A.
What is tail recursion and why is it useful?
Recursion where the recursive call is the last operation in the function. It can be optimized by the compiler into a loop, reusing the same stack frame (constant stack space).
Write the recurrence relation for the time complexity of binary search and give its solution.
T(n) = T(n/2) + O(1), which solves to O(log n).
What does the Master Theorem solve, and what is its general form?
It gives the asymptotic solution of divide-and-conquer recurrences of the form T(n) = a·T(n/b) + f(n), comparing f(n) to n^(log_b a) across three cases.
Define an Abstract Data Type (ADT).
A mathematical model defining a data type by its values and the operations on them (the interface/behavior), independent of any particular implementation.
How does an ADT differ from a data structure?
An ADT specifies WHAT operations exist and their behavior (logical view); a data structure specifies HOW those operations are implemented and how data is stored (physical view).
Name three common ADTs and one primary operation of each.
Stack (push/pop), Queue (enqueue/dequeue), List (insert/delete/access). Others: Set, Map/Dictionary, Tree, Graph.
What is the difference between an array (contiguous list) and a linked list in memory layout?
An array stores elements contiguously with index-based O(1) access; a linked list stores nodes scattered in memory connected by pointers, giving O(n) access but O(1) insertion/deletion at a known node.
Give the time complexity for access, search, insertion at head, and deletion at head for a singly linked list.
Access: O(n); Search: O(n); Insertion at head: O(1); Deletion at head: O(1).
What does a node in a doubly linked list contain, and what advantage does it offer?
It contains data, a pointer to the next node, and a pointer to the previous node. Advantage: it can be traversed in both directions and allows O(1) deletion given a node reference.
What is a circular linked list?
A linked list where the last node's next pointer points back to the first node (head) instead of NULL, forming a closed loop.
What are the advantages of a linked list over an array?
Dynamic size (grows/shrinks at runtime), efficient O(1) insertion/deletion without shifting elements, and no need for contiguous memory.
Show the other 36 Algorithms & Data Structures flashcards
What is the LIFO principle and which ADT uses it?
Last-In-First-Out: the most recently added element is removed first. Used by the Stack ADT.
Name the core stack operations and their time complexities.
push (add to top) O(1), pop (remove from top) O(1), peek/top (view top) O(1), isEmpty O(1).
Give three real applications of a stack.
Function call management (call stack/recursion), expression evaluation and conversion (infix to postfix), undo operations, and backtracking/DFS.
What is stack overflow and stack underflow?
Overflow: attempting to push onto a full stack (fixed-size). Underflow: attempting to pop from an empty stack.
What is the FIFO principle and which ADT uses it?
First-In-First-Out: the earliest added element is removed first. Used by the Queue ADT.
Name the core queue operations and the two ends they act on.
Enqueue adds at the rear/tail; Dequeue removes from the front/head; plus peek/front and isEmpty. All O(1).
What problem does a circular queue solve compared to a linear array queue?
It reuses freed space at the front by wrapping the rear pointer around to the start, avoiding the false-full condition where a linear queue wastes vacated front slots.
In a circular queue of size N, how is the rear index advanced and how is fullness detected?
rear = (rear + 1) % N. The queue is full when (rear + 1) % N == front (when one slot is left empty to distinguish full from empty).
What is a priority queue and how does it differ from a normal queue?
Elements are dequeued based on priority rather than insertion order; the highest- (or lowest-) priority element is removed first. Often implemented with a heap.
What is a deque (double-ended queue)?
A queue allowing insertion and deletion at both the front and the rear ends.
Describe linear (sequential) search and its time complexity.
Check each element sequentially from start until the target is found or the list ends. Time: O(n) worst/average, O(1) best. Works on unsorted data.
Describe binary search, its prerequisite, and its time complexity.
Repeatedly compare the target to the middle element of a SORTED array, discarding the half that cannot contain it. Time: O(log n). Prerequisite: the data must be sorted.
When is linear search preferable to binary search?
When the data is unsorted, the list is very small, or the data structure does not allow random access (e.g. a linked list).
How many comparisons does binary search need in the worst case for n elements?
⌊log₂ n⌋ + 1 comparisons, i.e. O(log n).
State the time complexity (best/average/worst) and space of Bubble Sort.
Best O(n) with optimization, average and worst O(n²); space O(1). Stable, in-place.
State the time complexity and key property of Selection Sort.
O(n²) in all cases (best/average/worst); space O(1); in-place; generally NOT stable; performs the minimum number of swaps (O(n)).
State the time complexity of Insertion Sort and when it performs best.
Best O(n) (nearly sorted data), average and worst O(n²); space O(1); stable, in-place. Efficient for small or almost-sorted arrays.
State Merge Sort's time complexity, space, stability, and core technique.
O(n log n) in all cases; space O(n) (needs auxiliary array); stable; uses divide-and-conquer by splitting, recursively sorting, and merging.
State Quick Sort's average and worst time complexity, and what causes the worst case.
Average O(n log n), worst O(n²); space O(log n) for recursion. Worst case occurs with poor pivot choices (e.g. already-sorted data with first/last pivot). In-place, typically not stable.
State Heap Sort's time complexity, space, and stability.
O(n log n) in all cases; space O(1) (in-place); NOT stable. Builds a max-heap then repeatedly extracts the max.
What makes a sorting algorithm 'stable'?
It preserves the relative order of records with equal keys. Examples: Merge Sort, Insertion Sort, Bubble Sort. Unstable: Quick Sort, Heap Sort, Selection Sort.
What is the lower bound for comparison-based sorting and why?
Ω(n log n) comparisons in the worst case, because a comparison sort's decision tree must have n! leaves and a binary tree of n! leaves has height ≥ log₂(n!) = Ω(n log n).
What is a hash table and what is its average-case lookup time?
A data structure mapping keys to values using a hash function to compute an index into a bucket array. Average-case insert/search/delete is O(1); worst case O(n).
What is a collision in hashing and name two general resolution strategies.
A collision occurs when two distinct keys hash to the same index. Resolution: separate chaining (linked lists per bucket) and open addressing (probing for another slot).
Compare separate chaining and open addressing for collision resolution.
Chaining stores colliding elements in a linked list at each bucket (handles high load factors, uses extra pointers). Open addressing stores all elements in the array itself and probes for empty slots (better cache use, but degrades as it fills).
Name three open-addressing probing techniques.
Linear probing (check next slot sequentially), quadratic probing (offsets grow as i²), and double hashing (use a second hash function for the step size).
Define the load factor of a hash table and its significance.
Load factor α = n/m (number of stored elements / number of buckets). Higher α increases collisions; tables are typically resized/rehashed when α exceeds a threshold (e.g. 0.7).
What properties make a good hash function?
It should be deterministic, fast to compute, distribute keys uniformly across buckets, and minimize collisions (avalanche effect).
Define a binary tree and the maximum number of nodes at level i (root at level 0).
A tree where each node has at most two children (left and right). Maximum nodes at level i is 2^i; a tree of height h has at most 2^(h+1) − 1 nodes.
What is the defining ordering property of a Binary Search Tree (BST)?
For every node, all keys in its left subtree are smaller and all keys in its right subtree are larger than the node's key.
Which BST traversal yields keys in sorted ascending order, and what is its order of visiting?
In-order traversal (Left, Root, Right) yields keys in ascending sorted order.
Give the time complexity of search/insert/delete in a BST for balanced vs degenerate trees.
Balanced: O(log n). Degenerate (skewed, like a linked list): O(n). Average for random insertion: O(log n).
What is a balanced tree and why is balancing needed?
A tree whose height is kept O(log n) by limiting the height difference between subtrees. Balancing prevents degeneration into a linked list, guaranteeing O(log n) operations.
What is the balance condition of an AVL tree and how is balance restored?
For every node the heights of its left and right subtrees differ by at most 1 (balance factor ∈ {-1,0,1}). Balance is restored by single or double rotations (LL, RR, LR, RL) after insert/delete.
List the key properties of a Red-Black tree.
1) Every node is red or black. 2) The root is black. 3) Red nodes cannot have red children (no two reds in a row). 4) Every root-to-NULL path has the same number of black nodes (equal black-height). This guarantees O(log n) height.
Compare AVL trees and Red-Black trees.
AVL trees are more strictly balanced, giving faster lookups but more rotations on insert/delete. Red-Black trees are less rigidly balanced, allowing faster insertions/deletions with fewer rotations—preferred when modifications are frequent (e.g. C++ std::map).
CSS Computer Science Algorithms & Data Structures FAQ
What is in the CSS Computer Science Algorithms & Data Structures syllabus?
CSS Computer Science Algorithms & Data Structures is split into 5 chapters: Algorithm Analysis, Linear Data Structures, Searching & Sorting, Trees & Graphs and Cryptographic Algorithms. Together they contain 16 topics.
How many chapters are in CSS Computer Science Algorithms & Data Structures?
5 chapters, containing 16 topics. The largest chapter is Linear Data Structures, with 4 topics.
Are there flashcards for CSS Computer Science Algorithms & Data Structures?
Yes — a 56-card Algorithms & 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.