MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Singly Linked Lists: Node Architecture, Traversal & In-Place Reversal0%
Study Materials
Data Structures & AlgorithmsProgress 0%
1.1Introduction to DSA, Big-O, Big-Omega & Big-Theta Notations1.2Time Complexity Calculation Rules & Common Runtime Patterns1.3Space Complexity, Auxiliary Memory & Stack vs Heap Allocation
3.1Singly Linked Lists: Node Architecture, Traversal & In-Place Reversal3.2Doubly & Circular Linked Lists with Sentinel/Dummy Nodes3.3Fast & Slow Pointers: Floyd's Cycle Detection & Middle Node Finding
HomeTutorialsData Structures & AlgorithmsSingly Linked Lists: Node Architecture, Traversal & In-Place Reversal
Doubly & Circular Linked Lists with Sentinel/Dummy Nodes

Singly Linked Lists: Node Architecture, Traversal & In-Place Reversal

Beginner12 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

A Singly Linked List is a fundamental linear data structure where elements (called Nodes) are not stored in contiguous memory cells. Instead, each node contains a data payload and a reference pointer (next) to the subsequent node in memory.


1. Real-World Analogy: The Scavenger Hunt

Think of a treasure hunt where each clue contains:

  1. 1
    A small prize or message (Data).
  2. 2
    A handwritten note with GPS coordinates to the next clue (Next Pointer).
  • You cannot teleport directly to Clue #5; you must find Clue #1, follow its pointer to Clue #2, then #3, and so on.
  • The final clue has no coordinates (NULL Pointer), indicating the hunt is over.

2. Linked List Memory Architecture

Linked List Memory StructureClick to Zoom
Linked List Memory Structure

Comparison: Array vs Linked List

FeatureArraySingly Linked List
Memory AllocationContiguous chunk of RAMScattered nodes anywhere in Heap memory
Index Access (get(i))$O(1)$ (Direct pointer math)$O(n)$ (Must traverse from Head)
Insert/Delete at Beginning$O(n)$ (Shifting elements)$O(1)$ (Update Head pointer)
Memory OverheadLow (Only data stored)High (Each node stores data + 8-byte pointer)
Resizing Cost$O(n)$ reallocation & copy$O(1)$ dynamic heap allocation per node

3. The Core Algorithm: In-Place Linked List Reversal ($O(n)$ Time, $O(1)$ Space)

Reversing a linked list is the quintessential technical interview question. You must redirect every node's next pointer to face backwards without allocating new nodes:

1Initial: [1] -> [2] -> [3] -> NULL
2Pointers: prev = NULL, curr = [1]
3Step 1: Save next_node = [2]
4 Redirect curr.next = prev (points to NULL)
5 Advance prev = curr ([1])
6 Advance curr = next_node ([2])
7Final Result: NULL <- [1] <- [2] <- [3] (prev is new Head!)

4. Multi-Language Implementations: Node & Reversal

Python 3:

1class ListNode:
2 def __init__(self, val: int = 0, next: 'ListNode' = None):
3 self.val = val
4 self.next = next
5 
6def reverse_linked_list(head: ListNode) -> ListNode:
7 prev = None
8 curr = head
9
10 while curr is not None:
11 next_temp = curr.next # 1. Save reference to next node
12 curr.next = prev # 2. Reverse current node's pointer
13 prev = curr # 3. Advance prev pointer
14 curr = next_temp # 4. Advance curr pointer
15
16 return prev # prev is the new head of the reversed list!

Modern JavaScript / TypeScript:

1export class ListNode {
2 val: number;
3 next: ListNode | null;
4 
5 constructor(val: number = 0, next: ListNode | null = null) {
6 this.val = val;
7 this.next = next;
8 }
9}
10 
11export function reverseLinkedList(head: ListNode | null): ListNode | null {
12 let prev: ListNode | null = null;
13 let curr: ListNode | null = head;
14 
15 while (curr !== null) {
16 const nextTemp: ListNode | null = curr.next; // 1. Save next
17 curr.next = prev; // 2. Reverse pointer
18 prev = curr; // 3. Move prev
19 curr = nextTemp; // 4. Move curr
20 }
21 
22 return prev;
23}

5. Trace Table: Reversing List 1 -> 2 -> 3 -> NULL

Iterationcurr.valnextTemp.valNew curr.nextprev becomescurr becomes
Init1--NULL1
112NULL12
223123
33NULL23NULL (Loop ends)

Result: prev points to Node 3 -> 2 -> 1 -> NULL. Reversed in $O(n)$ time with $O(1)$ space!


Interactive Quiz• Knowledge Check

Multiple Choice Questions

Question 1
What does each node in a standard Singly Linked List contain?
Question 2
Why is random index access in a linked list (get(i)) $O(n)$ while in an array it is $O(1)$?
Question 3
What is the time complexity of inserting a new node at the very beginning (Head) of a Singly Linked List?
Question 4
What happens if you update curr.next = prev during an in-place list reversal before saving curr.next in a temporary variable?
Question 5
What value does the next pointer of the tail node store in a standard non-circular linked list?

Next Lesson

Doubly & Circular Linked Lists with Sentinel/Dummy Nodes

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Prefix Sums & Difference Arrays for Constant-Time Range QueriesDoubly & Circular Linked Lists with Sentinel/Dummy Nodes

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master Data Structures & Algorithms with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext