SystemTutor
About
Sign in
Loading course documentation…
SystemTutor

COURSES

  • Data Structures & Algorithms
  • CSS MasterclassNew course
  • System DesignNew course

PRACTICE

  • Algorithm practice
  • CSS practice

LEGAL

  • Privacy Policy
  • Terms of Service
  • About

© 2026 SystemTutor. All rights reserved.

Built with 🫶 by Shatlyk

Course Overview

Course Overview

Learn to choose a data structure or algorithm, trace its behavior on a small input, and explain its time and space costs.

A package scanner records the IDs [42, 17, 42, 31] in arrival order. Someone asks, “When did package 42 first appear?” A scan from the left answers the question at index 0. If thousands of people will ask about the same log, it may be worth recording the first index of each ID ahead of time. The input stayed the same. The cost of answering the next question changed.

Package 42 appears at indices 0 and 2. Its first arrival is highlighted at index 0.

This course starts with decisions like that one. You’ll need to be comfortable reading variables, conditions, loops, and functions in JavaScript or Python. You can work through the course in either language.

Course roadmap

ChapterQuestion you’ll learn to answer
Big O notationIf the input doubles, what happens to the work and the extra memory?
Built-in data structuresDoes this problem need a position, a count, or a membership test?
Algorithm patternsWhich fact can you keep as you move through an array or string?
Linked lists, stacks, and queuesWhich item must be reachable next, and which links or endpoints make that possible?
RecursionWhat smaller input can solve part of the problem, and when can a call return immediately?
SortingWhich order do you need, and what does it cost to establish that order?
SearchingWhat property lets a search rule out a whole range of candidates?

Working through a lesson

Trace one small input before running the code. At each step, write down only the state that the algorithm carries forward. In Two Sum, for example, that means the current value and the earlier values you can look up. In a practice lesson, try the editor before reading the solution. Then test an input that would expose a mistake, such as a pair made from two equal values at different indices.

Check your reasoning

Return to the scanner log after the searching chapter. The log is fixed, and you can spend extra memory if it helps. What would you do for one first-position query? What would you prepare for many queries? If someone handed you only a sorted copy of the IDs, could you still recover the first arrival position?

Compare your reasoning

For one query, scan from the left and stop at the first match. This takes up to O(n) time and O(1) extra space. For many queries, scan once and store each ID’s index the first time you see it. The map for this log stores 42 → 0, 17 → 1, and 31 → 3. Overwriting the entry for the second 42 would give you its last position.

With ordinary hash-map assumptions, building the map takes O(n) expected time and answering a query takes O(1) expected time. Space grows with the number of distinct IDs. A sorted copy of the IDs alone loses the arrival positions. To use a sorted index for this question, you would also need to keep the original positions.

How is this lesson?

Next lessonAlgorithm Performance
Edit on GitHubReport on GitHub
On this page
%

On this page

Course roadmapWorking through a lessonCheck your reasoning