Skip to content

Computer Science (both courses): Improve space complexity content#30463

Open
JoshDevHub wants to merge 10 commits intoTheOdinProject:mainfrom
JoshDevHub:improve_space_complexity_content
Open

Computer Science (both courses): Improve space complexity content#30463
JoshDevHub wants to merge 10 commits intoTheOdinProject:mainfrom
JoshDevHub:improve_space_complexity_content

Conversation

@JoshDevHub
Copy link
Copy Markdown
Contributor

Because

There are a few things that went into this.

The lesson previously included this blog post in the assignment: https://dev.to/mwong068/big-o-space-complexity-lcm

A lot of the explanation of auxiliary space was off-loaded to this post, but it has a couple of inaccuracies:

  1. It includes some Ruby code that is syntactically incorrect. A few of the shown examples can't be run.
  2. It includes some statements about space and memory use that are incorrect. A loop, for example, doesn't use O(N) extra space where its memory footprint is proportional to the size of the structure its iterating. At a low level, loops are just a set of instructions with a branch at the end that will either (1) Jump to a previous line so the preceding instructions can be repeated, or (2) Continue execution of the program, meaning the loop has ended. There may be some artifacts created (like an index) but they definitely don't have a linear relationship to the input.

This blog post has caused repeatedly caused confusion for learners (see the linked issue for one example).

There was a previous section in the lesson that included references to the different approaches one can take when counting space. I decided to merge this into the new auxiliary space section. It covered similar ground, but I also thought the way it was previously worded was a bit unfair to auxiliary space analysis. At least in my experience, it's fairly common to use it, especially when comparing two algorithms that take the same input. This can even be seen when the lesson links to the BigO cheatsheet and multiple sorting algorithms are described as taking up constant space, meaning they're definitely using an auxiliary space lens.

This PR

(All changes are made in both the Ruby and JS versions of the lesson)

  • Add section for auxiliary space analysis.
  • Add knowledge check link and lesson overview item related to the new section.
  • Remove previous #### Other considerations section and merge it with the new auxiliary space section.
  • Remove aforementioned blog post from the assignment.
  • Add stackexchange post to the Assignment
    • This was in the previous "Other considerations" section, but didn't really fit with my rearrangement of things. I think it's good to include though because it gets learners to think about how counting space is quite subjective and situation dependent.

Issue

Closes #29254

Additional Information

Pull Request Requirements

  • I have thoroughly read and understand The Odin Project curriculum contributing guide
  • The title of this PR follows the location of change: brief description of change format, e.g. Intro to HTML and CSS lesson: Fix link text
  • The Because section summarizes the reason for this PR
  • The This PR section has a bullet point list describing the changes in this PR
  • If this PR addresses an open issue, it is linked in the Issue section
  • If any lesson files are included in this PR, they have been previewed with the Markdown preview tool to ensure it is formatted correctly
  • If any lesson files are included in this PR, they follow the Layout Style Guide

@github-actions github-actions bot added Content: JavaScript Involves the JavaScript course Content: Ruby Involves the Ruby course labels Nov 26, 2025
@JoshDevHub JoshDevHub requested review from a team and CouchofTomato and removed request for a team November 26, 2025 18:55
Copy link
Copy Markdown
Contributor

@mao-sz mao-sz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave more of the content review to Austin but got a couple of nits and word flow suggestions below.
I've only attached the comments to the JS lesson diff but all of the non-code comments apply the same to the Ruby lesson of course.

JoshDevHub and others added 6 commits November 28, 2025 10:58
Co-authored-by: mao-sz <122839503+mao-sz@users.noreply.github.com>
Co-authored-by: mao-sz <122839503+mao-sz@users.noreply.github.com>
Co-authored-by: mao-sz <122839503+mao-sz@users.noreply.github.com>
Co-authored-by: mao-sz <122839503+mao-sz@users.noreply.github.com>
Co-authored-by: mao-sz <122839503+mao-sz@users.noreply.github.com>
Co-authored-by: mao-sz <122839503+mao-sz@users.noreply.github.com>
@mao-sz
Copy link
Copy Markdown
Contributor

mao-sz commented Dec 2, 2025

@JoshDevHub in case you missed it in the review main comment, I have the same suggestions for the Ruby version of the lesson. I was just lazy with repeating the comments and suggestions on both files so I only stuck them on the JS one 😅

@JoshDevHub
Copy link
Copy Markdown
Contributor Author

@mao-sz Oh I know. I've just been equally lazy about going to fix them myself manually 😅

@JoshDevHub
Copy link
Copy Markdown
Contributor Author

Okay I finally put Mao's changes over in the Ruby lesson as well. Now this just needs signoff from someone on the DSA team 🚀

@CouchofTomato
Copy link
Copy Markdown
Member

Apologies. I'll try to review in the next couple of days

Copy link
Copy Markdown
Contributor

@mao-sz mao-sz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry this took a while, Josh. Had a more proper read through of the new content and I think I'm happy with what it covers. Just some small tweaks/thoughts below.

Comment on lines 171 to +172
- [What are the main considerations we should consider before optimizing code?](#other-considerations)
- [What is a situation where auxiliary space analysis is useful?](#auxiliary-space-analysis)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you intended for this to be a replacement KC question instead of additional? Since the JS once has it replace the optimizing question, and the Other considerations heading has gone too

Suggested change
- [What are the main considerations we should consider before optimizing code?](#other-considerations)
- [What is a situation where auxiliary space analysis is useful?](#auxiliary-space-analysis)
- [What is a situation where auxiliary space analysis is useful?](#auxiliary-space-analysis)


```javascript
function squareNumsInPlace(arr) {
for (let i = 0; i < arr; i++) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (let i = 0; i < arr; i++) {
for (let i = 0; i < arr.length; i++) {

Comment on lines +126 to +133
function squareNumsNewArr(arr) {
const squaredNums = [];
arr.forEach((number) => {
squaredNums.push(number * number);
});

return squaredNums;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the use of an empty array and forEach+push to be extra extra explicit about the use of an additional array? Or would using .map suffice? Since at this point, .map should both be more idiomatic and probably sufficiently clear that an extra array is involved if the following paragraph is tweaked accordingly.

Not sure if it's as idiomatic in the Ruby version.
Ultimately, not married to this if the idea is to be extra extra explicit about an additional array being involved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content: JavaScript Involves the JavaScript course Content: Ruby Involves the Ruby course

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Javascript: Change the articles linked in the assignment of the space complexity lesson

3 participants