CS61B Course Notes (Hug 2024 edition)
Authored by Josh Hug, with contributions from Paul Hilfinger and the CS61B staff. Mapped to CS61B assignment problems by our tutors.
UC BERKELEY
Project walkthroughs from HW0 through Gitlet, BYOW, and the lab autograder with explicit JUnit @Timeout annotations matching the staff rubric. The number-one grading deduction on Project 2 Gitlet is a checkout-branch implementation that mutates the working directory before persisting the HEAD pointer, causing the file system to desync from the commit graph after a power-loss simulation, the exact failure mode our tutors annotate inline. Verified CS graduates with prior CS61B TA or lab assistant experience, starting at $20 per project, 12-hour average turnaround.
Course Overview
CS61B teaches data structures and Java software engineering across 14 weeks under Josh Hug (since 2017) and Justin Yokota (recent semesters). Lectures cover lists, sets, maps, trees, balanced search trees (LLRB, B-trees, B+ trees), hashing, heaps, graphs, BFS, DFS, Dijkstra, A-star, MSTs, sorting, comparison-based and radix sort, and software engineering topics including version control, testing, and asymptotic analysis. Weekly cadence: 2 lectures, 1 lab, 1 discussion, and either a homework set or a project milestone.
The course assesses through 11 lab autograded assignments (one per topic week), 3 homework sets (HW0 Java basics, HW2 conceptual asymptotic analysis, HW3 algorithm design), 4 projects (Project 0 NBody n-body gravity simulation, Project 1 Deque with linked-list and array-deque variants, Project 2 Gitlet a 4,000-line clone of git, Project 3 BYOW a procedurally-generated 2D tile world), a midterm at week 7, and a 3-hour final at the end of week 14. Project autograders use JUnit 4 with @Timeout annotations enforcing per-test budgets: Project 2 Gitlet must complete all 35 acceptance tests in under 60 seconds wall-clock; Project 3 BYOW world generation must seed-stably reproduce a world from a 9-digit seed in under 5 seconds. Grading splits 30 percent labs and homework, 50 percent projects (10-10-15-15), 10 percent midterm, 10 percent final.
Course Reading
Authored by Josh Hug, with contributions from Paul Hilfinger and the CS61B staff. Mapped to CS61B assignment problems by our tutors.
Authored by Robert Sedgewick and Kevin Wayne. Mapped to CS61B assignment problems by our tutors.
Authored by Joshua Bloch. Mapped to CS61B assignment problems by our tutors.
Assignments
Verifies the Java 17 toolchain (JDK, javac, java, junit-4.13.2.jar on the classpath), IntelliJ IDEA Community Edition project import, and git workflow with the staff skeleton repo. Includes a `Sort.java` that sorts an int array (any algorithm, autograded for correctness only) and `Pig.java` a Pig Latin translator. Sets the baseline development environment for the semester.
A 2D n-body gravitational simulation reading planet data from a `.txt` file (e.g. `data/planets.txt` with 5 planets and 200 timesteps), computing pairwise force vectors, updating positions and velocities by Euler integration, and rendering each timestep via the staff-provided StdDraw library. Tests the float math, file I/O via In.java, and the `Planet` class API (constructor with position-velocity-mass-image-fields, calcForceExertedBy, calcNetForceExertedByAll, update).
A doubly-linked-list deque with a circular sentinel node, supporting addFirst, addLast, removeFirst, removeLast, get, size, isEmpty, and an iterator. The acceptance test calls 5,000 randomized operations and checks O(1) for addFirst, addLast, removeFirst, removeLast, and O(n) for get(i). The sentinel pattern (one always-present node where sentinel.next is the first real node and sentinel.prev is the last) avoids 8 special cases for empty-deque insertion and deletion.
A circular-buffer deque with resizing (grow by 2x on overflow, shrink by 0.5x when usage drops below 25 percent and capacity exceeds 16). Maintains nextFirst and nextLast indices that wrap via modulo arithmetic. The hardest part: resize must preserve element order across the wraparound, which requires copying from nextFirst+1 through nextLast-1 with modulo indexing into the new array. Grading tests include a 1,000,000-element push-pop sequence verifying O(1) amortized cost and correct shrink behavior.
A 4,000-line Java implementation of git with the commands init, add, commit, rm, log, global-log, find, status, checkout, branch, rm-branch, reset, and merge. Persists commit objects, blob objects, and the staging area as SHA-1-keyed files under `.gitlet/`. The acceptance test (35 integration tests via the ec module) must complete in under 60 seconds wall-clock; the merge command alone has 14 tests including criss-cross merges and conflict markers matching git's `<<<<<<< HEAD` syntax exactly. Project 2 is the largest single CS61B deliverable and the most autograder-sensitive.
A procedurally-generated 2D tile world rendered with the staff TileEngine and StdDraw. A 9-digit seed produces a deterministic dungeon (rooms of 3-by-3 to 8-by-8 connected by hallways of width 1 to 3), and the player controls an avatar with WASD navigation, save and load via colon-S, and a HUD showing the tile under the cursor. The autograder validates seed-stable world reproduction (same seed produces identical world across runs and across machines) and headless-mode behavior (TERenderer disabled, world state inspectable via getTiles).
Labs run from Lab 1 (HelloNumbers Java I/O) through Lab 13 (Graph algorithms with Dijkstra and A-star on a Bay Area map). Each lab autogrades with JUnit 4 tests via the lab repo skeleton, runs in under 30 seconds per submission on the staff grading cluster, and accepts up to 5 submissions before locking. Specific labs: Lab 4 Asymptotic analysis (writes worst-case complexity proofs), Lab 6 Maps and Sets (implement BSTMap and HashMap), Lab 8 Heaps (ArrayHeapMinPQ for Dijkstra), Lab 11 Graphs (BFS and DFS with adjacency-list representation).
Every autograded test in the cs61b grader uses `@Test(timeout = N)` annotations to enforce per-test runtime budgets. Project 2 Gitlet has tests with 5,000 ms budgets for single commands and a 60,000 ms wall-clock for the full integration sequence. Project 1B ArrayDeque has a 100 ms budget for million-element addFirst loops to enforce O(1) amortization. Submissions that pass correctness but TLE on the timeout still fail the test.
Common Pitfalls
StdDraw uses double-precision coordinates, but Planet.java starter code stores xxPos, yyPos, xxVel, yyVel as double. Students who declare these as float lose precision over 200 timesteps and the planets drift visibly off their orbital paths in the autograder image-diff test. The fix: use double for all position, velocity, mass, and force calculations; cast to float only when calling StdDraw rendering methods.
When the array is full and the elements wrap around (e.g. nextFirst is at index 14 of a 16-slot array with the data spanning indices 0 through 7 and 14 through 15), the naive resize that copies items[0..size] into the new array reorders the elements. The fix: copy from nextFirst+1 to the end of the old array first, then from index 0 to nextLast-1, then set nextFirst = newCapacity - 1 and nextLast = size. Hug's lecture notes have a 5-frame diagram for this exact case.
The checkout-branch command must: (1) verify the branch exists, (2) verify the working directory has no untracked files that would be overwritten, (3) move HEAD to the new branch, (4) restore the working directory to the new HEAD commit, (5) clear the staging area. Students who restore the working directory before moving HEAD leave the repo inconsistent if a crash interrupts step 4: HEAD still points to the old branch but files match the new branch. The autograder simulates power-loss via the `crash` test in ec/CrashTest.java.
Merge conflicts must produce conflict markers matching git's exact format: `<<<<<<< HEAD\n[current contents]=======\n[other branch contents]>>>>>>>\n` with `\n` after each marker, the current contents, the separator, the other branch contents, and the closing marker. Students who use Unix-style `<<<` or omit a trailing newline fail 7 of the 35 acceptance tests. The fix: read the staff test cases in the ec module and assert byte-equality of the conflict file via Utils.readContentsAsString.
BYOW world generation uses java.util.Random seeded by the 9-digit input. Students who use Math.random() (which has its own hidden global seed) or who call Random.nextInt() in a different order than the staff spec produce worlds that vary across machines. The autograder fails the seed-stability test by comparing tile-by-tile against a reference world generated on the staff machine. The fix: instantiate one Random instance from the seed, and call nextInt in a documented order (room count, then per-room x, y, width, height, then hallway endpoints).
A test with `@Test(timeout = 5000)` that runs at 4,999 ms passes, and at 5,001 ms fails with TestTimedOutException. Students who pass locally on a fast development machine (M1 Mac, M2 Pro) and submit to the grading cluster (older AWS instances) sometimes see tests that passed at 3 seconds locally fail at 7 seconds remotely. The fix: profile with java -agentlib:hprof or VisualVM, then redesign the hot loop to drop a level of nested iteration or replace a LinkedList with an ArrayDeque.
Lab 4 introduces JUnit 4 testing. Students who clone the skeleton repo without setting `library-cs61b-software.jar` as a project library see JUnit imports underline red in IntelliJ. The fix: Project Structure (cmd-semicolon on Mac), Libraries, add `library-su24/javalib/*.jar` as a new library, apply to all modules. The staff IntelliJ guide at cs61bl.org has screenshots for this exact step.
Project submission uses `git push skel su24-s123:proj2` against the skeleton remote. Students who push the wrong branch (e.g. `main:proj2` instead of `proj2:proj2`) overwrite a working submission with an in-progress feature branch. The fix: name the local proj2 branch `proj2` from the start, work in feature branches that merge into `proj2`, and verify the push target with `git remote -v` before each submission.
Sample Work
Every CS61B deliverable ships with annotated code, an autograder transcript, and a line-by-line walkthrough. Browse anonymized samples to see what a delivered pset looks like before you submit.
Sample-work archive includes code, comments, autograder output, and the design-decision notes our tutors leave for each pset.
Browse sample workRelated Coverage
JUnit-passing solutions for OOP, multithreading, and Spring Boot assignments, with Big-O annotations on every method. The number-one cause of failed autograder submissions in undergraduate Data Structures II courses (Berkeley CS61B, U of T CSC263, U of Sydney INFO1113, NUS CS2030S, IIT Bombay CS213) is iterator invalidation after a mid-traversal HashMap put, the exact failure mode our tutors annotate inline. Verified CS graduates from Georgia Tech, U of Toronto, Manchester, NUS, EPFL Lausanne, and IIT, starting at $20 per task, 12-hour average turnaround.
Implementation, Big-O analysis, and JUnit edge-case tests for every structure from arrays through graphs. The number-one cause of failed Gradescope submissions in CS61B is iterator invalidation after a mid-traversal mutation, the exact failure mode our tutors annotate inline. Verified CS graduates from BITS Pilani, EPFL Lausanne, and Georgia Tech, starting at $20 per task, 12-hour average turnaround.
Sorting, dynamic programming, greedy, divide-and-conquer, and graph algorithms with formal complexity analysis. The hardest CS161 grading deduction is failing to prove the greedy-choice property for a problem that looks greedy but is not, the gap our tutors close with a worked exchange argument. Verified CS graduates from Georgia Tech, Purdue, and BITS Pilani, starting at $20 per task, 12-hour average turnaround.
FAQ
Reviewed By
Submit your CS61B assignment and get a verified CS tutor on it within 12 hours. Every delivery passes the autograder, ships with line-by-line comments, and includes a design-decision walkthrough so you can defend the work in office hours.
Submit CS61B Assignment