Skip to content

Conversation

@damon314159
Copy link
Member

Because

The concept of graphs is introduced but rather swept under the rug in the current implementation of the knight travails project

This PR

  • Introduces a new project to go between BST and KT projects in the computer science section of both pathways.
  • Edits the existing KT project to make back-references to this project instead of introducing graphs haphazardly itself.

Issue

Closes #28487

Additional Information

Notes:

  • This is currently the first draft of this project. I have not yet translated it to Ruby, or edited the KT project as described in the "this PR" section. I want to get maintainer input on the substance of the project before proceeding with those two steps, since there are almost certainly changes that need to be made to this draft.
  • I've opted to keep the implementation as simple as possible. No specific mention of edge cases to be considered, no weighted or directed edges, and no dedicated Vertex wrapper class (though I do mention that this is a possibility later on in the project). I think what is here is plenty for the learner to understand the motivations and produce a basic implementation, without spending ages on niche aspects.
  • I included no methods regarding traversals or searching, since those concepts are introduced in the previous BST project, and are tied into the graphs with the subsequent KT project
  • I don't know how to either declare where the lesson should sit in the curriculum, nor how to add images to a lesson page 😅 . I might need some guidance on that once this gets through the drafting process.
  • I went ahead and produced a solution that's something like what I imagine learners would produce for this project. You can see it in this gist if you're curious what this might be like.

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 the Content: JavaScript Involves the JavaScript course label Nov 1, 2024
@damon314159 damon314159 marked this pull request as ready for review December 7, 2024 14:06
@wise-king-sullyman wise-king-sullyman requested review from a team and CouchofTomato and removed request for a team December 10, 2024 01:44
@JoshDevHub
Copy link
Contributor

@damon314159 Thanks for making this PR!

My initial impression of this is good. I did wonder why you ask for an adjacency matrix over an adjacency list? A list would be more convenient (or equivalently convenient) for nearly every operation, and I suspect learners who've been formally exposed to this will bring that up.

@damon314159
Copy link
Member Author

@damon314159 Thanks for making this PR!

My initial impression of this is good. I did wonder why you ask for an adjacency matrix over an adjacency list? A list would be more convenient (or equivalently convenient) for nearly every operation, and I suspect learners who've been formally exposed to this will bring that up.

It wasn't a decision I put a lot of weight on. I mostly went with a matrix so that it was easily displayable. I don't object to switching to a list approach, but it does increase the complexity of the visualisation

@JoshDevHub
Copy link
Contributor

Visualization is a good point, and I think some of the inconveniences with adding and removing vertices and edges make for good practice with keeping state held between multiple structures in-sync.

I could probably be onboard for a matrix, but I think it could be good to potentially talk a bit more about a list and maybe recommend using that in Knight Travails?

@damon314159
Copy link
Member Author

Sorry I left this hanging for so long! I completely forgot about it.
Implemented your feedback @JoshDevHub

@ManonLef ManonLef requested a review from JoshDevHub September 2, 2025 14:49
@JoshDevHub
Copy link
Contributor

Sorry for taking a bit to look back at this @damon314159 I'm still potentially interested in including this, but I want to discuss some things with the team first.

I'm a bit wary on the scope of the project gauntlet of Linked List > Hash Map > Binary Search Tree > Knight Travails, and this will be another project to add to that bit. But I also think expanding the quality of the graph instruction would be nice for helping with Knight Travails and giving learners a better foundation in that area.

I'll get back to you after I've discussed more.

@JoshDevHub
Copy link
Contributor

Okay gonna shift my above concerns to another issue and begin reviewing this in earnest this week because I think it's a good idea. Thank you for your patience 🙌

Copy link
Contributor

@JoshDevHub JoshDevHub left a comment

Choose a reason for hiding this comment

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

This is really good I think. One of the main things to figure out would be the image. Let me know if you have any questions about that.

I think the content all makes really good sense here. I might get another, less DSA-oriented maintainer to look this over and see if it's clear from that perspective.

I'll also try to put together a solution myself over the weekend and see how it feels.

Let me know if you have any other comments/concerns @damon314159

- In a road map, cities are vertices, and roads between them are edges
- In a computer network, devices are vertices, and connections between computers are edges

![Basic Graph Visualization](example-image.png)
Copy link
Contributor

Choose a reason for hiding this comment

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

Feel free to draw up a concrete example here. Should be able to just throw together something simple using excalidraw.

You can find out how to add images to the curriculum through the contributing guide.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will get something worked out this evening

Copy link
Member Author

Choose a reason for hiding this comment

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

graph-visualisation

How's this?

@scriabin-enjoyer
Copy link
Contributor

Hi, great work @damon314159 . Although I am not involved with this PR in any way, I was looking at it and just wanted to offer my perspective on some things I noticed.

In particular, neither the project description nor the G4G article explains why one might use an adjacency list vs an adjacency matrix, and in the case of the matrix, why it is even useful to represent a graph as a matrix in the first place. This latter point about matrices also has implications regarding getNeighbours and getCommonNeighbors functions, and this is especially important in the case of directed graphs.

And moreover, unless learners have had exposure to matrices before (via calculus/linear algebra course), you can't really appreciate all the nice things that matrices can tell you about the underlying data.

This is all to say that I think adjacency lists are a much more motivating representation, as one wouldn't need an intuition about matrices to actually reason about their usefulness and applicability.

@damon314159
Copy link
Member Author

@scriabin-enjoyer do you have an idea how we could do some kind of visualisation for that?

While not necessary I think it adds a layer of tangibility that many learners will appreciate if there is some kind of visual

@scriabin-enjoyer
Copy link
Contributor

@damon314159 Yeah there are several options. The G4G article linked does provide a graphical representation see here.

Typically (in my experience) people usually represent adjacency lists as associative arrays with the keys being the nodes of the graph and the values are arrays or linked lists containing nodes that are adjacent to the key. Such a textual representation would be imo a legitimate replacement for the printMatrix command, as in the attached screenshot, which shows a network example. Is something like this what you were looking for?

Screenshot from 2025-11-09 18-52-16

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Knights Travails: Handle the concept of a graph more explicitly with new project

3 participants