CS2040C: ace the component, not just read the notes
Your complete guide to National University of Singapore's data structures and algorithms course. See where the marks are, work real practice questions, and study with an AI tutor that knows CS2040C.
Sia generates CS2040C practice questions, walks through c++ review and analysis of algorithms step by step, and quizzes you on the material the component that weights most heavily.
Find what is wrong
Which statement about the following C++ code is correct?
std::priority_queue<int> pq;
for (int x : {5, 1, 9, 3}) pq.push(x);
std::cout << pq.top();
std::priority_queue<T> uses std::less<T> by default, which yields a max-heap: top() is the largest element.
To get a min-heap, push negated values or declare std::priority_queue<int, std::vector<int>, std::greater<int>>.
Option D confuses a priority queue with a FIFO queue; insertion order does not determine top().
The trap: Assuming C++ behaves like Python's heapq, which is a min-heap. The course page flags this exact contrast. classic slip!
One component decides 60% of your grade. Open book, no electronic device except one calculator. This whole page is built around that.
Overview
What CS2040C is, and where it sits
CS2040C Data Structures and Algorithms is the C++ variant of NUS's second-year data structures course, taken mainly by Computer Engineering, Information Security and exchange students after CS1010. This guide is written from the Semester 2 AY2025/26 offering taught by Steven Halim, whose course website publishes the full lesson plan and weightages; the page now notes that he no longer teaches this variant, so later offerings may differ.
The syllabus runs from algorithms on arrays and sorting, through list, stack, queue and deque, binary heaps, hash tables, union-find disjoint sets, binary search trees and AVL trees, to graph representations, DFS and BFS, single-source shortest paths and minimum spanning trees, closing with a preview of NP-completeness. Because most CS2040C students have not taken CS2030S, more object-oriented C++ is taught than in CS2040S. The format is a flipped classroom built on VisuAlgo, Kattis and LeetCode.
Assessment in that offering was 13% Kattis problem sets, 12% VisuAlgo online quizzes, 3% tutorial and lab participation, a 12% open-book midterm in Week 7 and a 60% open-book final. There is no practical exam; its former weight moved to the final. Two in-semester adjustments (participation 5% to 3%, midterm 10% to 12%) are recorded on the page.
Always treat your own course outline and the exam timetable as authoritative.
Difficulty & time commitment
Is CS2040C hard, and how much time does it take?
CS2040C is manageable if you keep a weekly rhythm and treat the back half as the main event. The pattern is consistent: it starts gently and steepens, and the heaviest assessment is the part that separates grades.
The difficulty curve and the assessment weighting point the same way: the back half is harder and worth more. Front-loading effort there is the highest-return decision in the course.
Is this course for you
Who tends to do well, and who tends to struggle
You will likely do well if
- You are comfortable reading someone else's code and spotting the bug; the final rewards exactly that.
- You solve the Kattis problem set each fortnight rather than the night before.
- You read the VisuAlgo slides before lectures; the flipped format assumes it.
- You keep a graph-algorithms cheat sheet for the open-book final.
You may struggle if
- You skip the online quizzes; 12% is spread over three short sessions.
- You expect the final to be like the midterm; it is twice as long and weighted five times as much.
- You avoid the graph weeks; at least two of the six final questions are on graphs.
- You have not written any C++ before Week 1.
- Implement each data structure once by hand in C++ before using the STL version.
- For every graph algorithm, know the representation it assumes and its complexity on adjacency list versus matrix.
- Practise the past final papers under time, focusing on identifying the single correct solution among near-misses.
- Bring worked examples of Dijkstra's and Kruskal's into the open-book final.
Syllabus
The 12 topics, week by week
The exam-weight marker on each topic shows where the marks concentrate. The amber topics carry the highest exam weight.
T1 · C++ review and unsorted arrays
Week 1Course admin; basic C++; simple array algorithms and complete search.
T2 · Analysis of algorithms and sorted arrays
Week 2Runtime measurement versus asymptotics; O(N²) sorts; binary search on sorted arrays.
T3 · Sorting
Week 3Merge sort, randomised quicksort, counting sort; std::sort and std::stable_sort.
T4 · List ADT
Week 4Singly and doubly linked lists, stack, queue, deque; the matching C++ STL containers.
T5 · Priority queue and binary heap
Weeks 5 and 7Insert, extract-max, create-heap, heapsort; std::priority_queue.
T6 · Union-find disjoint sets
Week 7Union by rank and path compression; reused in MST.
T7 · Hash tables
Week 8Hashing, separate chaining, open addressing; std::unordered_set and unordered_map.
T8 · Binary search trees and AVL trees
Weeks 9-10BST operations, multiset, select and rank; balanced BST; std::set and map.
T9 · Graph data structures and traversal
Weeks 10-11Adjacency matrix, list and edge list; DFS and BFS; connected components.
T10 · Traversal applications
Weeks 11-12Cycle detection, topological sort, flood fill, bipartite check.
T11 · Single-source shortest paths
Week 12BFS on unweighted graphs, Dijkstra's, Bellman-Ford, SSSP on trees and DAGs.
T12 · Minimum spanning tree
Week 13Kruskal's and Prim's algorithms; mix-and-match review.
How it's assessed
Assessment structure
| Component | Weight | Format & timing |
|---|---|---|
| Kattis problem sets (PS0 1% and PS1-PS6 at 2% each) | 13% | Seven Kattis problem sets: PS0 (any 3 of 10 trivial tasks, 1%) and PS1-PS6 (2% each) on the fortnight's topic. Fortnightly, due Saturday mornings. Continuous assessment. |
| VisuAlgo online quizzes (three at 4% each) | 12% | Three 15-minute VisuAlgo online quizzes at the end of lectures in Weeks 5, 10 and 13 (4% each); bring your own laptop. Weeks 5, 10 and 13. Continuous assessment; make-up window in Week 13. |
| Tutorial and lab participation | 3% | Participation in the weekly tutorial-lab combo (adjusted from 5% to 3% during the semester). Weeks 3-13. Continuous assessment. |
| Midterm test (80 minutes, open book) | 12% | 80-minute open-book test on material up to linked lists (adjusted from 10% to 12%); one special box plus three essay application questions. Week 7 (3 Mar 2026). Open book; one make-up in Week 13 for approved cases. |
| Final assessment (2 hours, open book) | 60% | Two-hour open-book written assessment; about six essay application questions worth 10% each, at least two on graphs, in a generative-AI critique format. Examination period (25 Apr 2026). Open book, no electronic device except one calculator. |
- The five components sum to 100 and no separate hurdle is published. Problem sets have fixed Saturday deadlines on Kattis; online quizzes and the midterm have a single make-up window in Week 13 for approved cases. Bell-curve grading applies because the class exceeds 40 students.
- Midterm: 80 minutes, open book, on material up to linked lists (no priority queue), one special box plus three essay application questions. Final: two hours, open book, about six equally weighted application questions in a generative-AI critique format with at least two on graphs; recent past papers are published on the course site.
This is a coursework course. Coursework carries 100% of the grade and the final assessment (2 hours, open book) is the single heaviest piece at 60%, so steady work across the semester decides your result more than any one sitting. Open book, no electronic device except one calculator.
Final exam timing: During the examination period. Confirm the exact date and venue on your exam timetable.
How to actually pass it
A weekly rhythm, two checklists, and the traps to avoid
The course rewards consistency over cramming, and practice over re-reading. Here is the loop that works, then what to have nailed before each exam.
The weekly loop
Before the mid-semester checklist
- Give the complexity of each sorting algorithm and state which are stable.
- Implement stack and queue on a linked list and on an array.
- Reverse or sort a linked list in place.
- Analyse a short C++ loop nest asymptotically.
Before the final heaviest topics
- Trace union-find with path compression.
- Insert and delete in a BST and explain AVL rebalancing.
- Run BFS, DFS, Dijkstra's and Kruskal's by hand on a small graph.
- Recognise which of several candidate solutions is both correct and asymptotically fastest.
The mistakes that cost marks
Tweaking a correct solution. In the final's critique format, modifying the one correct generative-AI answer into a wrong one costs heavily; verify before editing.
std::priority_queue direction. It is a max-heap by default; negate keys or supply a comparator for a min-heap.
Dijkstra's with negative edges. Use Bellman-Ford; the modified Dijkstra's taught in class is not guaranteed to terminate correctly.
Teaching team
Who teaches CS2040C
The bios below are factual. We do not rate lecturers; any star ratings are submitted by students who have taken CS2040C.
Teaching team as listed in the course materials reviewed. AskSia does not rate lecturers; star ratings are submitted by students who have taken CS2040C.
Formula & concept sheet
The vocabulary and formulas you must own
- Abstract data type
- An interface of operations independent of the underlying implementation.
- Stable sort
- A sort that preserves the relative order of equal keys.
- Binary heap
- A complete binary tree with the heap property, backing the priority queue.
- Union-find disjoint sets
- A structure for merging sets and testing membership in near-constant amortised time.
- Open addressing
- Hash-table collision resolution by probing other slots in the same array.
- AVL tree
- A self-balancing BST whose subtree heights differ by at most one.
- Adjacency list
- A graph representation storing each vertex's neighbours.
- Topological sort
- An ordering of a DAG's vertices with every edge pointing forward.
- Dijkstra's algorithm
- A greedy shortest-path algorithm for non-negative edge weights.
- Minimum spanning tree
- A spanning tree of minimum total edge weight, found by Kruskal's or Prim's algorithm.
Set texts
The prescribed reading
The syllabus references map straight onto these.
Competitive Programming 4, Book 1
.
Where it fits
Prerequisites, related courses & why it matters
Prerequisite: CS1010 (or variants). 4 units; not S/U-able; precluded by CS1020, CS1020E, CS2010 and CS2020. Offered in both semesters; this guide follows the Semester 2 AY2025/26 offering.
Your CS2040C study toolkit
Study the course with Sia, not just read about it
Each tool already knows CS2040C: your syllabus, your texts, and where the marks are. Grouped by how you study, from first contact to exam week.
FAQ
Frequently asked questions
Is CS2040C hard?
Moderately hard on the six-factor rubric, driven by the 60% open-book final and bell-curve grading. The continuous assessment is spread thin and is meant to be collected, not to separate students.
What is the assessment breakdown?
In the S2 AY2025/26 offering: Kattis problem sets 13%, VisuAlgo online quizzes 12%, tutorial and lab participation 3%, midterm test 12% and final assessment 60%, as published on the course website. Check the current offering's Canvas page, since staffing has changed.
Is there a practical exam?
No. From AY2025/26 the practical exam was dropped and its weight moved to the final assessment.
Who taught it?
Steven Halim taught the S2 AY2025/26 offering used for this guide, with six lab groups. His page states he no longer teaches CS2040C and now focuses on CS2040S.
Do I need to know C++ already?
Only basic C++ is reviewed in the first weeks; the course page recommends picking it up before the semester if you come from CS1010 (C) or another language.
Can I S/U this course?
No; it is a level-2000 core course with CS1010 as a prerequisite.
Study CS2040C with Sia
Work through c++ review, analysis of algorithms, sorting and the rest of the course with a tutor that knows it and quizzes you on the topics the assessments weight most heavily.
Start studying with Sia