This course introduces students to the design and implementation of fundamental data structures and algorithms. The course covers basic data structures (linked lists, stacks, queues, binary heaps, hash tables, trees, and graphs), searching and sorting algorithms, and basic analysis of algorithms.
The programming language used for this course is Java.
We use very basic object-oriented programming concepts in various data structures implementations, e.g., Stack class inherits LinkedList class (more details of OOP are in CS2030).
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.
Prof Halim is focusing on SoC Computer Science (CS) cohort since S2 AY 2022/23 - present.
That's it, if you take SoC CS, you will either encounter Prof Halim in CS2040S S1 and/or CS3230 S1.
If you reach this page because you are looking for CS2040C information, Prof Halim doesn't teach that version now, contact Prof Alan Cheng.
Some facts:
Rating (out of 5.0) |
Aug-Nov 24 (n=??/145?) ≥ 50% ?? |
Aug-Nov 23 (n=90/128) 70% ▼ |
Aug-Nov 22 (n=162/206) 79% ▲ |
Jan-May 22 (n=101/131) 77% ▲ |
Aug-Dec 21 (n=49/69) 71% ▲ |
Jan-May 21 (n=158/253) 62% ▲ |
Aug-Dec 20 (n=60/115) 52% ▼ |
---|---|---|---|---|---|---|---|
Course feedback (SoC avg lvl 2000 ~3.9) | 4.2 (tgt) | 4.2 == | 4.2 == | 4.2 == (+Alan) | 4.2 == | 4.2 ▲ (+Alan) | 3.8 ▼ (C-19+IOI 20) |
Course difficulty (SoC avg lvl 2000 ~3.8) | 4.1 (tgt) | 4.3 == | 4.3 ▲ | 4.2 == (high) | 4.2 ▲ | 3.9 ▼ (easiest) | 4.6 ▲ (C-19+IOI 20) |
Prof Halim's teaching (SoC avg lvl 2000 ~4.2) | 4.3 (tgt) | 4.4 ▼ | 4.5 ▲ | 4.3 ▼ (+Alan) | 4.5 ▲ | 4.4 ▲ (+Alan) | 4.3 ▼ (C-19+IOI 20) |
Update on 17 Jul 2024
Prof Halim has found best 8 TAs for this semester.
For the other 48-8 = 40 not-successful applicants, try again next semester (Sem2 version of CS2040S is much bigger).
Or pivot to CS2040 (with Dr Ket Fah), CS2040C (with Dr Alan/Sanka) or try the new CS2040DE (with Design and Engineering faculty)
Or consider re-applying to CS3230 (I still need 2 other part-time TAs) if you have also cleared CS3230.
Date, Time | Live Session (Venue) (#Stu/#Cap) | No | TA |
---|---|---|---|
1/Mon, 1000-1200 | COM1-B109 (PL2) (XY/19) | 01 | @pisciprehender |
1/Mon, 1000-1200 | COM1-B108 (PL3) (XY/19) | 02 | @saddle196883 |
1/Mon, 1200-1400 | COM1-B109 (PL2) (XY/19) | 03 | @chiralcentre |
1/Mon, 1200-1400 | COM1-B108 (PL3) (XY/19) | 04 | @ernest__ |
1/Mon, 1400-1600 | COM1-B108 (PL3) (XY/19) | 05 | @sandyk_sk |
1/Mon, 1400-1600 | COM1-B111 (PL4) (XY/19) | 06 | @chronal_02 |
1/Mon, 1600-1800 | COM1-B108 (PL3) (XY/19) | 07 | @json.c |
1/Mon, 1600-1800 | COM1-B111 (PL4) (XY/19) | 08 | @ahzong |
5/Fri, (night, TBC) | Zoom Recurring Link TBA (free and easy) | - | TBA |
6/Sat, (morning, TBC) | Zoom Recurring Link TBA (free and easy) | - | TBA |
List of TAs (ordered using Lab Group Number):
This is what you will learn if you take CS2040/C/S taught by Prof Halim, compare it with the subset IT5003 version:
If you have any important questions regarding this course, email dcssh at nus edu sg. Relevant answers will be posted here to reach wider audiences.
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.
Date | News |
---|
The 4 units CS2040/C/S syllabus will be delivered over 13 weeks.
This course is a superset of the content of a similar IT5003 course, approximately 39/24 ~= 63% more content than IT5003.
The weekly lesson plan of Week X is typically as follows (2+(1+1)+(2+1)+3 = 10 hours/week):
Then, repeat this throughout the semester :).
The S1 AY 2024/25 timetable below is still tentative, especially those that are highlighted with pink color. The Wed morning of CS2040S will be as close as possible with Wed evening of IT5003.
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, 29 Jul-02 Aug |
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 Java specific instructions @ Kattis, pick up basic Java 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) Dr Chong Ket Fah will run CS2040 placement test for AY24/25 incoming IOI medallists on Fri, 02 August 2024, 9-11am |
PS0: Easy Coding Challenges (01-14 Aug) Already graded to speed up registration admins Solve any 3 out of 10 trivial tasks for 1% |
00, 05-09 Aug |
Has Not Started |
Has Not Started Continue attempting PS0 (hints in class Discord) Singapore National Day on Fri, 09 August 2024 |
PS0, continued Remember, solve any 3 for 1% |
01, 12-16 Aug |
Has Not Started |
01a. Course Admin, (Re-)Introduction to Java Setting the tone for a flipped classroom course VisuAlgo + this Private Canvas + Kattis (NUS) + Kattis (open) Basic Java 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 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 simple algorithms on unsorted array (Slide 1 to 6-1) before the next lecture 01b. Algorithms on Unsorted Array Kattis problem(s) discussed today: rankproblem (a List ADT task; Java ArrayList operations: add (2 versions), indexOf, remove; and using Java class) 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, 14 Aug 24, 11.29am PS1: Basic Programming Out: Wed, 14 Aug 24, 11.30am Mentioned at the end of the first lecture CS2040S students do problem B+C |
02, 19-23 Aug |
Has Not Started But (e-)Consultation starts from Fri, 23 Aug Review demo code so far, focusing on Java API (ArrayList, String, Collections) |
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) 02b. Algorithms on Sorted Array Kattis problem(s) discussed today: classfieldtrip (merge of mergesort; or any other solution that works) Last flipped classroom reminder: Read all sorting e-Lecture slides before next lecture |
PS1 (2%) Due: Sat, 24 Aug 24, 07.59am PS2: Sorting-related Problems Out: Sat, 24 Aug 24, 08.00am |
03, 26-30 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) 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 Java Collections.sort, Arrays.sort (object), Arrays.sort (primitives) Sorting Online Quiz (medium) Kattis problem(s) discussed today: sortofsorting (custom comparator, stable sorting library) 03b. Sorting Extras (until end) A preview of Ω(N log N) lower-bound of comparison-based sorting algorithms Special-purpose O(N) sorting algorithm: Counting Sort (Only) Other topics of sorting, e.g., counting inversions, counting minimum swaps Prof Halim will depart to Alexandria, Egypt |
PS2, continued |
04, 02-06 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 in Alexandria, Egypt, for IOI 2024 (01-08 Sep 2024) 04a lecture will be covered by [someone, TBC]. 04b lecture will be covered by [someone, TBC]. 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 Java ArrayList implementation versus Java LinkedList and Stack classes Introducing Queue ADT and MyQueue implementation (another extension of SLLDemo) DLL and Deque ADT Fixed-size array, circular array version, versus Java Queue and Deque interfaces Linked List Online Quiz (medium) A few other LL technicalities 04b. List Review [Live] Review of the recording Kattis problem(s) discussed today: circuitmath (classic postfix evalution; use a stack/LIFO) delimitersoup (classic bracket matching variant; use a stack/LIFO) |
PS2 (2%) Due: Sat, 07 Sep 24, 07.59am PS3: List+PQ Problems Out: Sat, 07 Sep 24, 08.00am |
05, 09-13 Sep |
T03+L03: tut03.pdf Linked List, mini experiment, Applications: Reversing/Sorting a List, Application: Stack-related, PS2 Debrief (short), Java LinkedList/Stack/Queue/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) Introducing PQ ADT Introducing basic Binary Heap structure and its Insert+ExtractMax operations Discussing CreateHeap (two versions) and HeapSort operations BinaryHeapDemo.cpp | py | java Java PriorityQueue class; see priority_queue.cpp | py | java at GitHub repo of CPbook website Last 15m of 05a: VisuAlgo Online Quiz 1 (7%) Bring your own laptop that can run at least 15 minutes on battery power. (we do not provide any spare laptop). Material: /array (3 Qs), /sorting (3 Qs), /list (3 Qs), and 3 'new' questions. 05b. PQ Extras (until end) Clearing a few more details about Binary Heap O(N) CreateHeap analysis and O(N+K log N) PartialSort Max-to-Min heap conversions (numbers only) Discussing UpdateKey(i, newv) and Delete(i) operations Binary Heap Online Quiz (medium) Prof Halim will depart to Astana, Kazakhstan |
PS3, continued |
06, 16-20 Sep |
T04+L04: tut04.pdf Binary Heap, Max-Min conversion, Additional ADT PQ Operations, Java PriorityQueue, VA OQ demo (heap), Hands-on, a simple problem involving PQ, PS3 last Discussion (algorithmic) |
Prof Halim will be in Astana, Kazakhstan, for ICPC World Finals 2024 (15-20 Sep 2024) 06a+06b lectures will be covered by [someone, TBC]. 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) 06b. Hash Table Extras (until end) HashTableDemo.cpp | py | java (all use SC) Java HashSet/HashMap/Hashtable classes See unordered_map_unordered_set.cpp | py | java at GitHub repo of CPbook website Kattis problem(s) discussed today: proofs (a simple table ADT task) |
PS3 (2%) Due: Sat, 21 Sep 24, 07.59am PS4: Hash Table Problems Out: Sat, 21 Sep 24, 08.00am |
Recess Week, 21-29 Sep 2024 You can take a break this week :) |
|||
07, 30 Sep-04 Oct |
T05+L05: tut05.pdf [Special] Past midterm paper(s) discussions |
First 18m of 07a: Hash Table recording review Then 7m break Next 70m of 07a: Midterm Quiz (11%) Time window: [10.25am-11.35am] (70 minutes). Open book A few short questions (close-ended) and one (hard) essay question No more giveaway questions (the questions are either tricky or hard) There will be 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): AY 2022/23: S1-midterm.pdf, [I didn't teach CS2040C in S2], AY 2023/24: S1-midterm.pdf, [I don't teach CS2040S in S2], AY 2024/25: S1-midterm.pdf (will be our paper), [I don't teach CS2040S in S2]. 07b. Union-Find Disjoint Sets (all slides) Quick Recap with VisuAlgo See unionfind_ds.cpp | py | java at GitHub repo of CPbook website Kattis problem(s) discussed today: tildes (basic UFDS task) PS: UFDS will be reused in Connected Component (CC) and MST topics |
PS4, continued |
08, 07-11 Oct |
T06+L06: tut06.pdf Table ADT 1 - unordered, Basic hashing concepts, Hash Table issues, Java HashSet/HashMap, PS3 Debrief (short), Only for CS2040S: UFDS review, VA OQ demo (hashtable,ufds), Skipped for CS2040S: PS4 Discussion (algorithmic) |
08a. 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 Last 15m of 08a: VisuAlgo Online Quiz 2 (7%) Material: /heap (3 Qs), /ufds (3 Qs), /hashtable (3 Qs), and 3 'new' questions. 08b. Balanced BST and Applications (until end) QnA about AVL Tree concepts BST+AVL Online Quiz (hard; need to clear pre-req) AVLDemo.cpp | (no py yet) | java Java TreeSet/TreeMap classes See map_set.cpp | (no built-in py) | java at GitHub repo of CPbook website Kattis problem(s) discussed today: kattissquest (combo DS, e.g., TreeMap int to PQ of ints, etc) Prof Halim will depart to Shenzhen, China |
PS4 (2%) Due: Sat, 12 Oct 24, 07.59am PS5: Combo DS Problems Out: Sat, 12 Oct 24, 08.00am |
09, 14-18 Oct |
T07+L07: tut07.pdf Table ADT 2 - ordered, (balanced) BST advanced stuffs: Select and Rank, PQ ADT alternative implementation, Comparison with Table ADT 1: unordered vs ordered, Java TreeSet/TreeMap, PS4 Debrief (short), VA OQ demo (bst or avl (need to clear pre-req)) Hands-on, a combo DS task, PS5 Discussion (algorithmic) |
Prof Halim will be in Shenzhen, China, for ICPC Challenge Championship powered by Huawei 09a+b lectures will be covered by [someone, TBC]. 09a. 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 + one application (count #CC) See dfs_cc.cpp | py | java Kattis problem(s) discussed today: reachableroads (AL; count #CC; DFS introduction) 09b. Graph Traversal Applications (Slide 7-3 to 7-8) Finding Connected Components on Grid Graph Detecting cycle in a Directed Graph Kattis problem(s) discussed today: amoebas (finding CCs on implicit (grid) graph) runningmom (AL of strings; DFS; back edge detection) |
PS5, continued |
10, 21-25 Oct |
T08+L08: tut08.pdf Graph DS Review, Some Graph Properties Discussion, Graph DS Conversion Exercise, DFS Review, Only for CS2040S: UFDS revisited, Custom graph DS implementation review, VA OQ demo (graphds,dfsbfs), Hands-on, a simple Graph DS task, PS5 Discussion (algorithmic) |
10a. 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: builddeps (AL of Strings + postorder DFS toposort demo) 10b. Practical Exam (11%) Thu, 24 Oct 2024, 8.55-9.55am (60m) (LT19 is empty before 9am and between 10-11am) Just one task with a bit more of subtasks (instead of two tasks in two hours) All other details TBA. NUS Online Teaching Feedback opens this Fri But this timing is too early for our course... You can wait until you have done VA OQ 3 |
PS5 (2%) Due: Sat, 26 Oct 24, 07.59am PS6: Graph Problems Out: Sat, 26 Oct 24, 08.00am |
Make-up time window Those who miss VisuAlgo Online Quiz 1 on Week 05, Midterm Quiz on Week 07 or VisuAlgo Online Quiz 2 on Week 08 due to VALID reasons (valid Medical Certificate; representing NUS for an official event; bereavement of immediate family member) will do make up on Week 10 (details only for those eligible). Note that there is no more make up of make up :O... |
|||
11, 28 Oct-01 Nov |
T09+L09: tut09.pdf BFS Review DFS/BFS advanced stuffs: Cycle Detection, Toposort++, Floodfill/CC, Modeling exercise, PS5 Debrief (short), VA OQ demo (dfsbfs), CS2040S Only: short PE debrief by TA, Hands-on, a Graph Traversal task, PS6 Discussion (algorithmic) |
11a. SSSP Problem (Slide 1 to 7-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 (modified Dijkstra's first) See dijkstra.cpp | py | java at GitHub repo of CPbook website Kattis problem(s) discussed today: modulosolitaire (SSSP; unweighted graph; BFS; implicit graph) shortestpath1 (basic Dijkstra's) Thu, 31 Oct 2024 is Deepavali PH CS2040S 11b lecture is cancelled Additionally, Fri, 01 Nov 2024 is chosen as NUS well-being day S1 AY 2024/25 Enjoy our short break here |
PS6, continued |
12, 04-08 Nov |
T10+L10: tut10.pdf BFS/Dijkstra's review Modeling exercises (continued), VA OQ demo (sssp), Hands-on, an SSSP task, PS6 Discussion (algorithmic) |
12a. MST Problem (Slide 1 to end) Review of basic MST problem QnA on Kruskal's and Prim's algorithms Mix and Match of various data structures/algorithms covered so far Kattis problem(s) discussed today: cats (MST application) Onsite class photo as momento Last 15m: VisuAlgo Online Quiz 3 (7%) Material: /bst (3 Qs), /graphds (3 Qs), /dfsbfs (3 Qs), /sssp (3 Qs). 12b. SSSP+MST Wrap-Up QnA on Bellman-Ford algorithm (the general algorithm) QnA on other special cases of SSSP problem Other MST Variants |
PS6 (2%) Due: Sat, 09 Nov 24, 07.59am |
13, 11-15 Nov |
T11+L11: tut11.pdf VA OQ demo (mst), Class Photo (for momento) Tut+Lab participation marks given (3%) |
13a. Make-up (or Remedial) Practical Exam slot Wed, 13 Nov 2024 (09.35-11.35am, 120m) Venue: LT15 (TBC) --- need to ensure there is no class at 9-10am Details only given to those who are invited. Make-up VisuAlgo Online Quiz 3 Venue and Timing TBC 13b. The Last Lecture Course wrap-up et al: Undoing all the illegal Java coding techniques, Semester summary, Review of what can be done better for future iterations, Advertisement of future (algorithm) courses: CS3233 (S2) or CS3230 (S1) Advertisement for part-time TA jobs (A-/A/A+ only), Ending: a few Final Assessment Tips. |
No more :) Or attempt the optional Final Preparation Tracker |
Study Week, 16-22 Nov 2024 Final Assessment Consultations (per request) Final Assessment Past Papers (recent 3 AYs only, note the transition from CS2040C/C++ to CS2040S/Java): AY 2022/23: S1-final.pdf, [Prof Halim didn't teach CS2040C in S2], AY 2023/24: S1-final.pdf, [Prof Halim didn't teach CS2040S in S2], Final Preparation Tracker AY 2024/25: S1-final.pdf (will be our paper; maybe also try IT5003 S1-final, link TBA), [Prof Halim didn't teach CS2040S in S2]. NUS Online Teaching Feedback System closes on Friday of Study Week |
|||
Final Assessment (40%) Date and Time: Wed, 27 Nov 2024, 5.00-7.00pm Venue: TBA Open book 40% MCQs (extremely tricky) (the MCQs are there to speed up grading as Prof Halim has two other final assessments on 13 Nov (14 pax) and 29 Nov (392 pax)) 2 questions with shorter answers, the easier ones (20%) 3 application questions, the harder ones (40%) |