Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Computer Science Introduction to Data Structures Building a Linked List Inserting a Node

Jordan Kittle
.a{fill-rule:evenodd;}techdegree seal-36
Jordan Kittle
Full Stack JavaScript Techdegree Graduate 20,138 Points

Confusing visualization at 3:41 with the position variable and list head

At 3:41, the video animation starts highlighting the tail of the list and going backwards, but previously in the video we learn that we are reducing the position variable every time we called current.next_node, starting with current at the head. This animation is super confusing. Why is it highlighting the tail of the list? Counting down to zero stops at 3 and counting down to 1 stops at 2. When visualizing this from the tail going backward these numbers make no sense either. It only makes sense if, like stated earlier in the video, each time current.next_node is called the position is counting down. Then stopping at 0 would reach 3 and stopping at 1 would reach 2. It seems like we should be highlighting the head and going forward and not the tail going backward.

1 Answer

Chris Freeman
Chris Freeman
Treehouse Moderator 67,651 Points

Hey Jordan Kittle, you are correct! The example you mention at 341 should be counting down position starting at the head (leftmost) node and proceeding to the right. Instead it is incorrectly highlighting the tail and working toward the head. As a proof of this error, the video discusses that one cannot access the previous node in a singly-linked list. So how then would one traverse from the tail toward the head!?!

The position variable seems to be misnamed. Since index passed in is defined as the offset from the head node, and position is decremented at each stop down the list, "position" is really "number of steps yet to move", so "steps" or "offset" seems a better choice.

Flagging post as feedback!