IT5003 - Data Structures and Algorithms (Python)

Introduction

This course introduces non-computing students to efficient computational problem solving in an accelerated pace*. Students will learn to formulate a computational problem, identify the data required and come up with appropriate data structures to represent them, and apply known strategies to design an algorithm to solve the problem. Students will also learn to quantify the space and time complexity of an algorithm, prove the correctness of an algorithm, and the limits of computation. Topics include common data structures and their algorithms (lists, heap, hash tables, trees, graphs), algorithmic problem solving paradigms (greedy, divide and conquer, dynamic programming), and NP-completeness.

The programming language used for this course is Python 3.

We use very basic object-oriented programming concepts in various data structures implementations, e.g., Stack class inherits LinkedList class.

Note: This introductory message will not be prominent the next time you visit this URL again. This behavior is normal. You can view it again by scrolling to the top of this page.

* Since S1 AY 2024/25, IT5003 is now a full 12-weeks course (6-weeks in the first half + recess (to catch up) + 6-weeks in the second half) instead of the true accelerated 8-weeks (week 7-reading week) after students finish IT5001.

Course Registration

This is the going to be the tenth time Prof Halim teaches this 12-weeks IT5003 course for MComp General Track (GT) — the main/largest group of students — (plus a bit of other MSc degree specializations: Digital Financial Technology (DFT) + Biomedical Informatics (BMI) + Industry 4.0 students) and also a few (usually around [20..30]-ish) Graduate Certificates in Computing Foundations (GC-CF) students. Prof Halim sets IT5003 (in Python) as a 'subset' (obviously, as we only have 12-weeks of 2 hours/week) of his full 13-weeks of 3 hours/week CS2040S Undergraduate version of similar course. The previous iterations were already (very) good. One thing to take note is that Prof Halim's teaching style is flipped classroom that may be quite surprising for some adult learners who are not used to this teaching style in the past.

For S1 AY 2025/26 (August-November 2025), Prof Halim expects a smaller class again, about [30-50] students who have passed IT5001 in S2 AY 2024/25 (or earlier).
This information will be refined as and when the information from IT5001 team and/or Graduate Office is available.

Some other facts:

  1. Prof Halim has implemented flipped classroom (a type of blended learning) techniques, employing machine-teach-(and-auto-test)-students-on-basic-stuffs, along with in-class live discussion of more challenging problems in his IT5003 classes. From AY 2020/21 until the present, he has received teaching feedback ratings from 4.2 (average) to 4.6 (very good) out of a maximum of 5.0 for these offerings, with a running average rating of 4.468 (good).
  2. Teaching staffs:
    Associate Professor Steven Halim, the key man behind VisuAlgo, a tool that is utilized extensively in this course.
    The primary goal for this S1 AY 2025/26 is to integrate as many key/recurring/most liked/popular LeetCode tasks in this course, as LeetCode is currently one of the most popular coding interview website out there for now (in AY 2025/26).
    The secondary goal is to introduce Midterm Test on Week 07 and reduce VisuAlgo Online Quiz weightage.

    Rating
    (out of 5.0)
    Aug-Dec 25
    (n=??/[30..50]??)
    ≥50%
    Jan-May 25
    (n=76/146)
    52%
    Aug-Nov 24
    (n=19/33)
    58%
    Mar-May 24
    (n=66/122)
    54%
    Oct-Dec 23
    (n=82/200)
    41%
    Mar-May 23
    (n=61/115)
    53%
    Course feedback (SoC CS avg lvl 5000 ~4.2) [4.1..4.2] (tgt) 4.1 (PW) 4.3 == 4.3 == 4.3 4.5 (PB)
    Course difficulty (SoC CS avg lvl 5000 ~3.7) [4.0..4.1] (tgt) 4.0 4.2 == (uh oh) 4.2 ▲ (uh oh) 3.9 == 3.9 ==
    Prof Halim's teaching (SoC CS avg lvl 5000 ~4.5) [4.3..4.4] (tgt) 4.2 ▼ (drop) 4.6 4.4 4.3 4.6 == (PB)
    Date, Time Live Session (Venue) (#Stu/#Cap) No TA
    a/Sat, 1000-1200 COM1-B112 (PL1) — for part-time students (??/20) B3A @loveandbejoyful
    b/Mon, 1600-1800 COM1-B109 (PL2) — for full-time students (??/20) B2 @loveandbejoyful

    List of TA (just one) for Aug-Dec 2025:

    1. @loveandbejoyful, Tan Yu Wei (IT5003 full-time TA from the last few semesters)
  3. Have you passed (or exempted from) IT5001 or CS1010 (or its variants)? You have to...

Syllabus

This is what students learn in IT5003 as taught by Prof Halim, compare it with the superset CS2040S version:

Course Registration Additional FAQ

If you have any important questions regarding this course, email dcssh at nus dot edu dot sg. Relevant answers will be posted here to reach wider audiences.

Q: Will there be a Practical Exam (PE) for your version of IT5003?
A: In the past, I want to, but we do not have enough class contact time for that anyway, so no.
Q: Will there be a mid-semester Midterm Test for your version of IT5003?
A: Starting from S1 AY 2025/26, yes, on Week 07.
Q: I am from IT5001 (the most relevant course before this), but I don't think my Python skill is up-to-the-requirement, should I improve my Python coding ability on my own before August 2025?
A: Yes, that is a very good idea, use May-June-July 2025 University holiday for that. We will start with the optional PS0.
Q: Do I have to buy any textbook for this course?
A: Generally, no. But my CS3233 textbook: Competitive Programming book: CP4, Book 1 (get a copy legally from lulu.com (eBook) or lulu.com (physical, need shipping from overseas)) should be a good book to have. The answers for many of my test questions may be inside that book. The problem is... I discuss over ~4900+ problems in that book, near impossible to solve them all in just one semester.
Q: I heard from my friend/senior that your version of IT5003 is a flipped classroom course?
A: You heard that correctly. Get ready :).
Q: What are the potential changes that you will apply to IT5003 in S1 AY 2025/26 compared to your most recent semester (S2 AY 2024/25) version?
A: Prof Halim only plan to change these variables this time (all others are planned to be kept roughly constant):
  1. Prof Halim will have to disappear again, but at least just once this semester (compared to THREE times last S1 AY 2024/25), on Week 04 (ICPC World Finals 2025, Baku, Azerbaijan). There will be substitute lecturer for that week.
  2. Prof Halim started joining LeetCode effectively from CNY 2025 (at this point of writing, he has solved 1219 out of 3600 tasks (~34%)). He plans to reach ~1440 tasks solved (~40%) by the time S1 AY25/26 starts (11 August 2025) and ~1620 tasks solved (~45%) by the time S1 AY25/26 is over (30 November 2025). So, Prof Halim will now mix Kattis (a bit longer/story-based problem statement) and LeetCode more direct interview-style questions in class demos.

Note: This course registration section will not be prominent from Week 1 onwards. This behavior is normal. You can view it again by scrolling to the top of this page.

News

Date News

Lesson Plan

The 4 units IT5003 syllabus will be delivered over 12 weeks, and we will be back to the official exam period for final assessment.
This course is approximately 24/39 ~= 62% of the content of CS2040S.
The weekly lesson plan of Week X is typically as follows (1+(1+1)+(2+2)+3 = 10 hours/week):

  1. Give yourself about 1-hour/week to self-study as much as you can from various online Python references (follow up from IT5001) and VisuAlgo about the designated topic and attempt the e-Lecture/Online Quiz questions first (flipped classroom),
  2. On Tutorial+Lab day, attempt and then actively participate on 1-hour/week (effective 45 minutes) tutorial slot of past week X-1 topic to improve student's understanding of IT5003 material, short break, then for the second half, students will practice solve a "simple" problem (guided by TA) during the next 1-hour/week (effective 45 minutes) lab session of past week X-1 topic to improve student's coding skills. Currently, we have the following options starting from Sat of Wk02 (for Saturday groups) and from Sat of Wk03 (for Monday groups):
    1. Saturdays (4 sessions, start from Sat of Week 02),
    2. Mondays (4 sessions, start from Mon of Week 03),
  3. There is only one lecture session (two hours) and for larger class: one recitation session weekly starting from Wk01:
    1. 2-hour/week (effective 105m) in-class lecture 1 on Wed, 6.30-8.30pm @ COM1-0212 (start on time at 6.30pm and end by around [8.10-8.15]pm - no other class after us), we will roughly do: 5m (admins) + 45m (fast in class review of the more difficult parts of the designated VisuAlgo e-Lecture topics) + 7m (break) + 45m (application 1 - solving at least 1 Online Judge problem live) + 3m (buffer). Note that attendance is compulsory for those using SkillsFuture Singapore (SSG) funding. PS: SSG-funded students have to declare their lecture attendances via this method),
  4. Attempt a ~two-weeks Problem Set (PS) @ home, approximately 3 hours of work per week on average or (~6++ hours/set), starting from Wk01. The problems will be discussed in algorithmic (high-level) during each Tut+Lab session. You can use ChatGPT (or alternative) tool if you have spent more than 2 hours attempting any PS task without external help (other human or AI, which means in the 2 hours final assessment, you cannot solve this yet), and as long as you eventually (re-)code the solution yourself (this part is for your own good), Plagiarism checker is built-in inside Kattis and extremely similar code can be easily identified,
  5. TOTALLY OPTIONAL: (Re-)solve some Kattis or LeetCode demo problems (or more) that are related to IT5003 using Prof Halim's Methods to Solve page. WARNING: Doing this will significantly increases your study time per week for this course.

Then, repeat this throughout the semester :).

The S1 AY 2025/26 timetable below is still tentative, especially those that are highlighted with pink color.
The Wed evening of IT5003 will be as close as possible with Wed morning of CS2040S.

Week Tutorial+Lab Combo Lecture Interesting Problem Set
Cells with course material that have not been updated are highlighted with pink color, past classes more than one week ago are hidden so that we can focus on the current and future classes, but you can restore them by clicking 'Show Past' button above, future classes are not highlighted
-01,
28 Jul-01 Aug
Has Not Started Has Not Started,
but please revise your IT5001/equivalent
Prof Halim assumes that all of you have taken
or exempted from this course/its variants

Register at Kattis and LeetCode (use full name as in Matric card),
read Python specific instructions @ Kattis,
pick up basic Python by yourself,
and solve the selected Kattis Online Judge (OJ)
Problem Set 0 (PS0) by yourself (IT5001/equivalent level)
and LeetCode OJ programming-skills study plan
(solving many 'trivial problems' from these exercises
---the Kattis one is trackable by Prof Halim, indirectly tells him
about your IT5001/equivalent rough grade)
PS0: Easy Coding Challenges
(01-13 Aug)
Already graded to speed up
registration admins
Solve any 3 out of 10 trivial tasks for 1%
00,
04-08 Aug
Has Not Started Has Not Started
Continue attempting Kattis PS0 and LeetCode programming-skills study plan
(hints in class Discord)

Singapore National Day on Sat, 09 August 2025
PS0, continued
Remember, solve any 3 for 1%
01,
11-15 Aug
Has Not Started 01a. Course Admin, (Re-)Introduction to Python
1. Setting the tone for a flipped classroom course
VisuAlgo + this Private Canvas + LeetCode + Kattis (NUS)
2. Basic Python review/new feature introduction
3. Kattis/LeetCode problem(s) discussed today:
A few PS0 and/or programming-skills problems (just for warm-up)

In the middle of 01a: VisuAlgo Online Quiz 0 (1%)
There will be 1 trivial question during the first lecture
Bring your own laptop
This one is put here to speed-up admins (don't skip the first lecture)

Reminder: Read sorting intro, algorithm analysis,
and O(N^2) sorting algorithms
(Slide 1 to 9-3)
before the next lecture
PS0 (1%)
Due: Wed, 13 Aug 25, 07.59pm

PS1: Basic Programming
Out: Wed, 13 Aug 25, 08.00pm
Mentioned at the end of the first lecture
IT5003 students do problem A+B
problem C is optional (extra challenge)
02,
18-22 Aug
Saturday sessions
start from this Week 02
see T01+L01: tut01.pdf below
02a. Analysis of Algorithms (Slide 1 to 9-3)
1. Live SpeedTest.cpp | py | java demo
(measure runtime, count # of operations, vs asymptotic analysis)
2. Fast review of O(N^2) sorting algorithms
3. Kattis/LeetCode problem(s) discussed today:
thanos (analysis: exponential growth, logarithmic steps)
mjehuric (bubble sort simulation)
height (insertion sort simulation)
nothanks (sorting library and linear pass)

At the end of 02a: VisuAlgo Online Quiz 0 (make-up) (1%)
There will be another 1 trivial question (not the same as last week)
Bring your own laptop
Only for those who really absent for the first lecture (for legit reasons)

Last flipped classroom reminder:
Read all sorting e-Lecture slides before next lecture
PS1 (2%)
Due: Sat, 23 Aug 25, 07.59am

PS2: Sorting-related Problems
Out: Sat, 23 Aug 25, 08.00am
03,
25-29 Aug
T01+L01: tut01.pdf
Introduction,
OOP review (List ADT, ListArrayTest.py | java)
Algorithm Analysis,
Hands-on, a basic List ADT task,
PS1 Debrief (short),
PS2 Discussion (algorithmic)
03a. Sorting (Slide 10 to 13-2)
1. O(N log N) Merge Sort (C++ stable_sort; Java Collections.sort; Python list.sort)
2. Exp O(N log N) (Rand) Quick Sort (C++ sort; Java Arrays.sort (primitives); N/A in Python)
Sorting Online Quiz (easy)
White-box: SortingDemo.cpp | py | java
Black-box: Python list, list.sort(), or sorted(list)
3. Kattis/LeetCode problem(s) discussed today:
merge-strings-alternately (variant of merge of Merge sort)
sort-colors (Dutch National Flag problem)
PS2, continued
04,
01-05 Sep
T02+L02: tut02.pdf
Sorting Application(s),
Sorting, mini experiment,
QuickSelect,
ADT/List ADT,
VA OQ demo (sorting),
Hands-on, sorting applications,
PS2 Discussion (algorithmic)
Prof Halim will be at Baku, Azerbaijan,
for the 2025 ICPC World Finals
.
Lec04a will likely be delivered by Jeanette (TBC).

04a. List ADT: SLL/Stack/Queue/DLL/Deque (all slides)
1. Introducing List ADT, (resizeable) array versus Singly Linked List (SLL) way
2. Introducing Stack/Queue ADT
3. Wrapping up with DLL and Deque ADT
Linked List Online Quiz (easy)
White-box: SLLDemo.cpp | py | java implementation
Black-box: Stack, but using (resize-able) Array implementation, i.e., Python list as stack
Python list as queue, circular list, versus Python deque as queue
Kattis/LeetCode problem(s) discussed today: N/A (TBC)
PS2 (2%)
Due: Sat, 06 Sep 25, 07.59am

PS3: List+PQ Problems
Out: Sat, 06 Sep 25, 08.00am
05,
08-12 Sep
T03+L03: tut03.pdf
Linked List, mini experiment,
Applications: Reversing/Sorting a List,
Application: Stack-related,
PS2 Debrief (short),
Python list/deque,
VA OQ demo (list),
Hands-on, a list application,
PS3 Discussion (algorithmic)
05a. Priority Queue (PQ) ADT: Binary Heap (Slide 1 to 8-2)
1. Introducing PQ ADT
2. Introducing basic Binary Heap structure and its Insert+ExtractMax operations
3. Discussing CreateHeap (two versions) and HeapSort operations
Binary Heap Online Quiz (easy)
White-box: BinaryHeapDemo.cpp | py | java
Black-box: priority_queue.cpp | py | java
Kattis/LeetCode problem(s) discussed today:
kth-largest-element-in-an-array (only short way; proper version at home)

Last 15m of 05a: VisuAlgo Online Quiz 1 (7%)
Bring your own laptop that can run at least 20 minutes on battery power.
(we do not provide any spare laptop).
Material: /array (1Q + 2 'new'), /sorting (3 Qs), /list (3 Qs),
and 3 'new' questions especially on asymptotics.
PS3, continued
06,
15-19 Sep
T04+L04: tut04.pdf
Binary Heap,
Max-Min conversion,
Additional ADT PQ Operations,
Python heapq,
VA OQ demo (heap),
Hands-on, a simple problem involving PQ,
PS3 last Discussion (algorithmic)
06a. Table ADT part 1: Hash Table (slide 1 to 10-5)
1. Table ADT, DAT, Basic Hashing; Easiest Collision Resolution (CR): CA (SC)
HashTableDemo.cpp | py | java (all use SC)
2. More CR Techniques: OA (LP, QP, DH); Comparing CA: SC with OA: DH
Hash Table Online Quiz (easy; a bit too tedious on medium/hard settings)
3. Kattis/LeetCode problem(s) discussed today:
design-hashmap (use HashTableDemo)
longest-consecutive-sequence (use set to help checks)
PS3 (2%)
Due: Sat, 20 Sep 25, 07.59am

PS4: Hash Table Problems
Out: Sat, 20 Sep 25, 08.00am
Recess Week, 20-28 Sep 2025
You can take a break this week :)
07,
29 Sep-04 Oct
T05+L05: tut05.pdf [Special]
Past midterm paper(s) discussions
Midterm Test (10%)
Open book
Three essay questions, with sub-boxes
There are a few blank boxes, which will be given 1 mark if left blank,
but 0 if answered (even a single character) and declared (very) wrong
Material: Up to PQ (L05ab on Week 05 + T04+L04 on Week 06), NO Hash Table yet

Midterm Test Past Papers (recent 3 AYs only):
N/A, this will be the first IT5003 midterm test
PS4, continued
08,
06-10 Oct
T06+L06: tut06.pdf
Table ADT 1 - unordered,
Basic hashing concepts,
Hash Table issues,
Python set, dict, defaultdict, Counter
PS3 Debrief (short),
VA OQ demo (hashtable),
Hands-on, a hash table application,
PS4 Discussion (algorithmic)
08a. Table ADT part 2: BST (Slide 1 to 12-1)
1. BST concepts, BST operations, and the multiset idea
BST (only) Online Quiz (medium)
BSTDemo.cpp | py | java
2. Randomly built BST and a preview of balanced BST, e.g., AVL Tree
3. Kattis/LeetCode problem(s) discussed today:
search-in-a-binary-search-tree (implement what we discuss today)
delete-node-in-a-bst (implement the three cases)
PS4 (2%)
Due: Sat, 11 Oct 25, 07.59am

PS5: Graph DS + Traversal Problems
Out: Sat, 11 Oct 25, 08.00am
09,
13-17 Oct
T07+L07: tut07.pdf
Table ADT 2 - ordered,
(balanced) BST advanced stuffs: multiset, select/rank,
PQ ADT alternative implementation,
Comparison with Table ADT 1: unordered vs ordered,
The issue of no equivalent Python standard library,
PS4 Debrief (short),
VA OQ demo (bst)
Hands-on, a combo DS task,
PS5 Discussion (problemset preview only)
09a. Graph DS (all slides) + DFS Traversal (Slide 1 to 5-8)
1. Concept checks: Graph DS Online Quiz (medium),
Implementations of graph DS and its applications
No built-in C++ STL container | Python standard library | Java API,
See graph_ds.cpp | py | java at GitHub repo of CPbook website,
2. Early discussion of the basic forms of Graph Traversal algorithms: DFS first
See dfs_cc.cpp | py | java
3. Kattis/LeetCode problem(s) discussed today:
destination-city (degree checks)

Last 15m of 08a: VisuAlgo Online Quiz 2 (7%)
Material: /heap (3 Qs), /hashtable (3 Qs), /bst (3 Qs)
and 3 'new' questions.
PS5, continued
10,
20-24 Oct
As Mon, 20 Oct 2025 is Deepavali PH
and Tue, 21 Oct 2025 is NUS well-being day
We move our last three downwards
10a. Graph Traversal Applications (Slide 6 to 7-12)
1. Review DFS and introducing BFS
2. Focus on a few more basic DFS/BFS applications
(we skip slide 8-11, out of CS2040/C/S and IT5003 scope)
DFS/BFS Online Quiz (medium)
No built-in C++ STL algorithm | Python standard library | Java API,
See UVa00469.cpp | py | java, and
bfs.cpp | bfs.py | java at GitHub repo of CPbook website,
3. Kattis/LeetCode problem(s) discussed today:
number-of-provinces (AM; count #CC; DFS vs BFS way)
course-schedule-ii (cycle detection and provide one topological order if acyclic)

NUS Online Teaching Feedback opens this Fri
But this timing is too early for our course...
You can wait until you have completed the course
PS5, continued
11,
27-31 Oct
T08+L08: tut08.pdf
Graph DS Review,
Some Graph Properties Discussion,
Graph DS Conversion Exercise,
DFS Review,
Custom graph DS implementation review,
VA OQ demo (graphds,dfsbfs),
Hands-on, a simple Graph DS task,
PS5 Discussion (algorithmic)
11a. SSSP Problem (all slides)
1. Review of basic SSSP problem + O(VE) / O(kE) Bellman-Ford algorithm
2. QnA on BFS algorithm for unweighted SSSP
QnA on Dijkstra's algorithm (original Dijkstra's first;
but focus on modified Dijkstra's for IT5003)
See dijkstra.cpp | py | java at GitHub repo of CPbook website
Quick discussion of SSSP on Tree and on DAG
SSSP Online Quiz (medium)
3. Kattis/LeetCode problem(s) discussed today:
rotting-oranges (SSSP; unweighted undirected implicit grid graph; BFS)
network-delay-time (basic Dijkstra's; focus on easy lazy-minPQ implementation)
PS5 (2%)
Due: Sat, 01 Nov 25, 07.59am

PS6: Graph(-Related) Problems
Out: Sat, 01 Nov 25, 08.00am
12,
03-07 Nov
T09+L09: tut09.pdf
BFS Review
DFS/BFS advanced stuffs:
Cycle Detection, Toposort++, Floodfill/CC, Bipartite Graph Checker
Modeling exercise,
PS5 Debrief (short),
VA OQ demo (dfsbfs),
Hands-on, a Graph Traversal task,
PS6 Discussion (algorithmic)
12a. SSSP, NP-completeness, and Course Wrap-Up
QnA on a few other special cases of SSSP problem
Showing the limit of computation:
Introduction to the theory of NP-completeness
Course wrap-up

Last 15m of 12a: VisuAlgo Online Quiz 3 (7%)
Material: /graphds (3 Qs), /dfsbfs (3 Qs), /sssp (3 Qs),
and 3 'new' questions.
PS6, continued
13,
10-14 Nov
T10+L10: tut10.pdf
BFS/Dijkstra's review
Modeling exercises (continued),
VA OQ demo (sssp),
Hands-on, an SSSP task,
PS6 Discussion (algorithmic)

Tut+Lab participation marks given (5%)
No more lecture

Make-up slot for VA OQ 1 (? pax ), OQ 2 (? pax), and OQ 3 (? pax)
Date and Time: Wed, 12 Nov 2025,
Timing: TBA
Venue: TBA
PS6 (2%)
Due: Sat, 15 Nov 25, 07.59am
Study Week, 15-21 Nov 2025

Final Assessment Discussions at Class Discord

Final Assessment Past Papers (recent 3 AYs only):
AY 2022/23: S1-final.pdf, S2-final.pdf,
AY 2023/24: S1-final.pdf, S2-final.pdf,
AY 2024/25: S1-final.pdf, S2-final.pdf,
AY 2025/26: S1-final.pdf (to be our paper).
Final Assessment (50%)
Date and Time: Wed, 26 Nov 2025, 5-7pm (during exam period)
Venue: TBA
Open book
No electronic device except non-programmable calculator (as with Online Quiz)
11 MCQs (11x2 = 22%, very tricky), and
6 essay questions, the harder ones (6x13 = 78%)