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 in full 12-weeks course (6-weeks in the first half + recess + 6-weeks in the second half) instead of the accelerated 8-weeks (week 7-reading week) after students finish IT5001.

Course Registration

This is the going to be the ninth time Prof Halim teaches this 12-weeks IT5003 course for MComp General Track (GT) — the main group of students — (plus a bit of other MSc degree specializations: Digital Financial Technology (DFT) + Biomedical Informatics (BMI) + NEW: Industry 4) and also a few (usually around 30-ish) Graduate Certificates in Computing Foundations (GC-CF). 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 S2 AY 2024/25, Prof Halim is expected around ~200+ IT5001 S1 AY 2024/25 students to join IT5003 in S2 AY 2024/25.
Prof Halim prepares for a [175-200]-ish class size.
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.4 (above average) to 4.6 (very good) out of a maximum of 5.0 for these offerings, with a running average rating of 4.486 (very good).
  2. Teaching staffs:
    Associate Professor Steven Halim, the key man behind VisuAlgo that is used very extensively in this course.
    The primary goal for this S2 AY 2024/25 is for Prof Halim to properly teach IT5003 especially around Week 06 - Recess Week - Week 07, when Prof Halim is expected to be super busy hosting ICPC Asia Pacific Championship 2025 @ SoC.

    Rating
    (out of 5.0)
    Jan-May 25
    (n≥???/175+)
    ≥50+%
    Aug-Nov 24
    (n≥17/33)
    ≥52%
    Mar-May 24
    (n=66/122)
    54%
    Oct-Dec 23
    (n=82/200)
    41%
    Mar-May 23
    (n=61/115)
    53%
    Oct-Dec 22
    (n=100/178)
    56%
    Course feedback (SoC avg lvl 5000 ~4.1) [4.3..4.4] (tgt) [4.3..4.4] (tgt) 4.3 == 4.3 4.5 (PB) 4.4 ==
    Course difficulty (SoC avg lvl 5000 ~3.6) [4.0..4.1] (tgt) [4.0..4.1] (lower a bit) 4.2 ▲ (uh oh) 3.9 == 3.9 == 3.9
    Prof Halim's teaching (SoC avg lvl 5000 ~4.3) [4.4..4.5] (tgt) [4.4..4.5] (tgt) 4.4 4.3 4.6 == (PB) 4.6 == (PB)

    TAs:

    Date, Time Live Session (Venue) (#Stu/#Cap) No TA
    a/Sat, 1000-1200 COM1-0120 (PL6) — for part-time students (??/22) B1A TBC
    a/Sat, 1000-1200 COM4-02-03 (WSLab1) — for part-time students (??/22) B1B TBC
    a/Sat, 1000-1200 COM4-02-05 (WSLab2) — for part-time students (??/22) B1C TBC
    a/Sat, 1000-1200 COM4-02-04 (WSLab3) — for part-time students (??/22) B1D @prof_halim
    b/Mon, 1400-1600 COM1-B112 (PL1) — for full-time students (??/22) B2A @jeanette
    b/Mon, 1400-1600 COM1-B109 (PL2) — for full-time students (??/22) B2B TBC
    b/Mon, 1600-1800 COM1-B112 (PL1) — for full-time students (??/22) B3A TBC
    b/Mon, 1600-1800 COM1-0120 (PL6) — for full-time students (??/22) B2B TBC

    List of TAs for Jan-May 2025 (two confirmed so far, looking for 6 more part-time TAs):

    1. @prof_halim, Associate Professor Steven Halim (IT5003 course lecturer 9x)
    2. @jeanette, Tan Yu Wei (IT5003 full-time TA from last few semesters)

    Part-time TAs applications (will select best 6 among these known applicants, contact @prof_halim if you are interested to TA):

    1. @.myrcella., Shen Zihan (EGOI 2023 Gold Medallist, currently at the top side of CS2040S S1 AY 2024/25, can speak Chinese)
    2. Tan Chee Xiang (has TA-ed before: CS2040S (17 students) with rating 5.0 out of 5.0, can speak Chinese)
    3. @saddle196883, Timothy Wan Kai Yang (peak rating: 4.8/CS2040S; either Sat 10am-12nn slot or Mon 2-4pm)
    4. Woo Wen Jun (has TA-ed IT5003 before, can speak Chinese; only available on Sat 10am-12nn slot)
    5. Looking for at a few more part-time TA applicants (so I can choose the best six)
  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: I want to, but we do not have enough class contact time for that, so no.
Q: Will there be a mid-semester Midterm Test for your version of IT5003?
A: I also want to, but we do not have enough class contact time for that, especially that CNY period will cut 1 week out of our 12 weeks, so no.
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 January 2025?
A: Yes, that is a very good idea, use December 2024 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 ~3900+ 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 S2 AY 2024/25 compared to your most recent semester (S1 AY 2024/25) version?
A: Not much, with average teaching feedback rating of ~4.5 so far (not much change is expected from the small (33 pax) S1 AY 2024/25 feedback), there is not much left to change.... Prof Halim only plan to change these variables this time (all others are planned to be kept roughly constant):
  1. Prof Halim has a feeling that he 'fails to reduce' course difficulty rating for S1 AY 2024/25, i.e., it will likely ≥4.1... So, he will try one more time to make this course has difficulty rating in [4.0-4.1] range instead of ≥ 4.1 (overshoot again), 4.2 (overshoot) in his last two iterations...
  2. Unlike S1 AY 2024/25 where Prof Halim left his IT5003 students a record THREE times to attend three international competitions on Week 04+06+09, there is no scheduled overseas competition that Prof Halim has to attend overseas between January-May 2024. However, Prof Halim expects to be extremely busy hosting the ICPC Asia Pacific Championship 2025 during recess week of S2 AY 2024/25, thus his concentration around Week 06 and his (mental) health state on Week 07 will be compromised...

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 S2 AY 2024/25 (Draft)

The 4 units IT5003 syllabus will be delivered over 12 weeks, and we will be back to official exam period for final assessment.
This course is approximately 24/39 ~= 62% of the content of CS2040S (but Prof Halim does not teach CS2040S in S2 AY 2024/25).
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),
    2. Mondays (4 sessions),
  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 @ LT8 (start on time at 6.30pm and end by around [8.05-8.10]pm - no other class after us), we will roughly do: 5m (admins) + 40m (fast in class review of the more difficult parts of the designated VisuAlgo e-Lecture topics) + 7m (break) + 40m (application 1 - solving at least 1 Online Judge problem live) + 8m (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),
    2. (Optional Onsite) Recitation: every Fri 2-4pm @ Venue TBC (resumed again in S2 AY 2024/25 due to expected larger class size, TBC)
  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 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 S2 AY 2024/25 timetable below is still tentative, especially those that are highlighted with pink color.

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,
30 Dec-03 Jan
Has Not Started Has Not Started,
but please revise your CS1101S/IT5001/equivalent
Prof Halim assumes that all of you have taken
or exempted from this course/its variants

Register at Kattis (use full name as in Matric card),
read Python specific instructions @ Kattis,
pick up basic Python by yourself,
and solve the selected Online Judge (OJ)
Problem Set 0 (PS0) by yourself (CS1101S/IT5001/equivalent level)
(solving many 'trivial problems' from this set
---trackable by Prof Halim, indirectly tells him
about your CS1101S/IT5001/equivalent rough grade)
PS0: Easy Coding Challenges
(01-15 Jan)
Already graded to speed up
registration admins
Solve any 3 out of 10 trivial tasks for 1%
00,
06-10 Jan
Has Not Started Has Not Started
Continue attempting PS0 (hints in class Discord)
PS0, continued
Remember, solve any 3 for 1%
01,
13-17 Jan
Has Not Started 01a. Course Admin, (Re-)Introduction to Python
Setting the tone for a flipped classroom course
VisuAlgo + this Private Canvas + Kattis (NUS) + Kattis (open)
Basic Python review/new feature introduction
Kattis problem(s) discussed today:
A few PS0 tasks (just for warm-up)

In the middle of 01a: VisuAlgo Online Quiz 0 (1%)
There was 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 simple algorithms on unsorted array
(Slide 1 to 6-1) before the next 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, 15 Jan 25, 07.59pm

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

Last flipped classroom reminder:
Read all sorting e-Lecture slides before next lecture
We defer PS1 end time
to before CNY 2025, and PS2 start time
to after CNY 2025
03,
27-31 Jan
T01+L01: tut01.pdf
Introduction,
OOP review (List ADT, ListArray.py | java)
Algorithm Analysis,
Hands-on, a basic List ADT task,
PS1 Debrief (short),
PS2 Discussion (algorithmic)
No class due to Chinese New Year 2025
CNY Eve: 28 Jan 2025 PM (Tue)
Day 1: 29 Jan 2025 (Wed)
Day 2: 30 Jan 2025 (Thu)
PS1 (2%)
Due: Mon, 27 Jan 25, 11.59pm
(a few hours after the first Mon tut01)

PS2: Sorting-related Problems
Out: Sat, 01 Feb 25, 08.00am
(after CNY)
04,
03-07 Feb
No tutorial this week
Due to CNY 2025
03a. Sorting (Slide 10 to 13-2)
O(N log N) Merge Sort algorithm (Java Collections.sort; Python list.sort)
Expected O(N log N) (Rand) Quick Sort algorithm (C++ sort; Java Arrays.sort (primitives))
See the details at SortingDemo.cpp | py | java
Python list, list.sort(), or sorted(list)
Sorting Online Quiz (medium)
Kattis problem(s) discussed today:
sortofsorting (custom comparator, stable sorting library)
PS2, continued
05,
10-14 Feb
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)
04a. List ADT: SLL/Stack/Queue/DLL/Deque (all slides)
Introducing List ADT, (resizeable) array versus SLLDemo.cpp | py | java implementation
Introducing Stack ADT and MyStack implementation (extension of SLLDemo)
Stack, but using (resize-able) Array implementation, i.e., Python list as stack
Introducing Queue ADT and MyQueue implementation (another extension of SLLDemo)
DLL and Deque ADT
(Fixed-size) Python list as queue, circular list, versus Python deque as queue
Linked List Online Quiz (medium)
A few other LL technicalities
PS2 (2%)
Due: Sat, 15 Feb 25, 07.59am

PS3: List+PQ Problems
Out: Sat, 15 Feb 25, 08.00am
06,
17-21 Feb
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)

PS: Sat sessions run tut03.pdf
on Sat, 22 Feb 25
05a. Priority Queue (PQ) ADT: Binary Heap (Slide 1 to 8-2)
Introducing PQ ADT
Introducing basic Binary Heap structure and its Insert+ExtractMax operations
Discussing CreateHeap (two versions) and HeapSort operations
BinaryHeapDemo.cpp | py | java
Python heapq; see priority_queue.cpp | py | java at GitHub repo of CPbook website

Last 20m of 05a: VisuAlgo Online Quiz 1 (11%)
Bring your own laptop that can run at least 20 minutes on battery power.
(we do not provide any spare laptop).
Material: /array (4 Qs), /sorting (4 Qs), /list (4 Qs),
and 4 'new' questions especially on asymptotics.
PS3, continued
Recess Week, 22 Feb - 02 Mar 2025
You can take a break this week :)
Prof Halim will be super busy hosting ICPC Asia Pacific Championship 2025
07,
03-08 Mar
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)
Table ADT and DAT
Basic Hashing Concepts
Easiest Collision Resolution Technique: CA (SC)
Another Collision Resolution Technique: OA (LP)
More Collision Resolution Techniques: OA (QP and DH)
Comparing CA: SC with OA: DH
Other technicalities of Hash Table
Hash Table Online Quiz (easy; a bit too tedious on medium/hard settings)
PS3 (2%)
Due: Mon, 03 Mar 25, 11.59pm
(a few hours after Mon tut04)

PS4: Hash Table Problems
Out: Tue, 04 Mar 25, 08.00am
08,
10-14 Mar
T05+L05: tut05.pdf
Table ADT 1 - unordered,
Basic hashing concepts,
Hash Table issues,
Python set, dict, defaultdict, Counter
PS3 Debrief (short),
VA OQ demo (hashtable),
For IT5003: Hands-on, a hash table application,
PS4 Discussion (algorithmic)
07a. Table ADT part 2: BST (Slide 1 to 12-1)
BST concepts and the various BST operations
The multiset idea
BST (only) Online Quiz (medium)
BSTDemo.cpp | py | java
Randomly built BST and a preview of balanced BST, e.g., AVL Tree
PS4 (2%)
Due: Sat, 15 Mar 24, 07.59am

PS5: Combo DS Problems
Out: Sat, 15 Mar 24, 08.00am
09,
17-21 Mar
T06+L06: tut06.pdf
Table ADT 2 - ordered,
(balanced) BST advanced stuffs: Select and 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 (algorithmic)
08a. Graph DS (all slides) + DFS Traversal (Slide 1 to 5-8)
Implementations of graph DS and its applications
Graph DS Online Quiz (medium),
No built-in C++ STL container | Python standard library | Java API,
See graph_ds.cpp | py | java at GitHub repo of CPbook website,
Early discussion of the basic forms of Graph Traversal algorithms: DFS first
See dfs_cc.cpp | py | java

Last 20m of 08a: VisuAlgo Online Quiz 2 (11%)
Material: /heap (4 Qs), /hashtable (4 Qs), /bst (4 Qs)
and 4 'new' questions.
PS5, continued
10,
24-28 Mar
T07+L07: tut07.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)
09a. Graph Traversal Applications (Slide 6 to 7-11)
Review DFS and introducing BFS
Focus on a few more basic DFS/BFS applications
(we skip slide 8-12, 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,
Kattis problem(s) discussed today:
reachableroads (AL; count #CC; DFS vs BFS way)
builddeps (AL of Strings + postorder DFS toposort demo)

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

NUS Well-Being Day is Fri, 28 Mar 2025
PS5 (2%)
Due: Thu, 27 Mar 25, 11.59pm
Before Well-Being Day
11,
31 Mar-04 Apr
As Sat, 29 Mar 2025 is part of
NUS long well-being weekend
We move our last two downwards
10a. SSSP Problem (Slide 1 to 8-5)
Review of basic SSSP problem
Preview of O(VE) / O(kE) Bellman-Ford algorithm
QnA on BFS algorithm for unweighted SSSP
SSSP Online Quiz (medium)
QnA on Dijkstra's algorithm (original Dijkstra's first for CS2040S;
but modified Dijkstra's first for IT5003)
See dijkstra.cpp | py | java at GitHub repo of CPbook website
Kattis problem(s) discussed today:
modulosolitaire (SSSP; directed unweighted implicit graph; BFS)
shortestpath1 (basic Dijkstra's; focus on implemetation)
PS6: Graph Problems
Out: Mon, 31 Mar 25, 08.00am
After Well-Being weekend
12,
07-11 Apr
T08+L08: tut08.pdf
BFS Review
DFS/BFS advanced stuffs:
Cycle Detection, Toposort++, Floodfill/CC,
Modeling exercise,
PS5 Debrief (short),
VA OQ demo (dfsbfs),
Hands-on, a Graph Traversal task,
PS6 Discussion (algorithmic)
11a. SSSP, NP-completeness, and Course Wrap-Up
QnA on other special cases of SSSP problem
Showing the limit of computation:
Introduction to the theory of NP-completeness
Course wrap-up

Last 20m of 12a: VisuAlgo Online Quiz 3 (11%)
Material: /graphds (4 Qs), /dfsbfs (4 Qs), /sssp (4 Qs),
and 4 'new' questions.
PS6, continued
13,
14-18 Apr
T09+L09: tut09.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 (3%)
No more lecture

But make-up slot for VA OQ 1 (? pax), OQ 2 (? pax), and OQ 3 (? pax)
Date and Time: Wed, 16 Apr 2025, 6.30-6.50pm; 6.55-7.15pm, or 7.20-7.40pm
Venue: Our own LT8
PS6 (2%)
Due: Sat, 19 Apr 25, 07.59am
Study Week, 19-25 Apr 2054

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, (to be our paper).
Final Assessment (50%)
Date and Time: ???, ?? Apr 2025, likely night (back to exam period)
Venue: TBC
Open book
Non-programmable calculator is allowed (as with Online Quiz), but won't be that useful
40% MCQs (extremely tricky); I use my own OCR form
2 short questions (10% --- do not lose too many marks here), and
3 essay questions, the harder ones (40%)