Pages

101 Linked List

 

Why Singly Linked Lists Matter

They test:

  • Understanding of pointers
  • Recursion
  • Iteration
  • Edge case handling (null nodes, head/tail issues)
  • Space and time complexity reasoning


Basic Operations on Singly Linked List

1. Insert at Head

Pseudocode:

function insertAtHead(head, value):
    newNode = Node(value)
    newNode.next = head
    return newNode  // new head

 Python Snippet:

class Node:
    def __init__(self, val):
        self.val = val
        self.next = None

def insertAtHead(head, value):
    newNode = Node(value)
    newNode.next = head
    return newNode

2. Insert at Tail

 Pseudocode:

function insertAtTail(head, value):
    newNode = Node(value)
    if head is null:
        return newNode
    temp = head
    while temp.next != null:
        temp = temp.next
    temp.next = newNode
    return head

 Python Snippet:

def insertAtTail(head, value):
    newNode = Node(value)
    if not head:
        return newNode
    temp = head
    while temp.next:
        temp = temp.next
    temp.next = newNode
    return head

3. Delete from Head

 Pseudocode:

function deleteFromHead(head):
    if head is null:
        return null
    return head.next

 Python Snippet:

def deleteFromHead(head):
    if not head:
        return None
    return head.next

4. Delete from Tail

 Pseudocode:

function deleteFromTail(head):
    if head is null or head.next is null:
        return null
    temp = head
    while temp.next.next != null:
        temp = temp.next
    temp.next = null
    return head

Python Snippet:

def deleteFromTail(head):
    if not head or not head.next:
        return None
    temp = head
    while temp.next.next:
        temp = temp.next
    temp.next = None
    return head

5. Search a Value

 Pseudocode:

function search(head, target):
    temp = head
    while temp != null:
        if temp.val == target:
            return true
        temp = temp.next
    return false

 Python Snippet:

def search(head, target):
    temp = head
    while temp:
        if temp.val == target:
            return True
        temp = temp.next
    return False

6. Reverse a Linked List

 Pseudocode:

function reverseList(head):
    prev = null
    curr = head
    while curr != null:
        next = curr.next
        curr.next = prev
        prev = curr
        curr = next
    return prev  // new head

Python Snippet:

def reverseList(head):
    prev = None
    curr = head
    while curr:
        nxt = curr.next
        curr.next = prev
        prev = curr
        curr = nxt
    return prev

7. Length of Linked List

 Pseudocode:

function getLength(head):
    count = 0
    temp = head
    while temp != null:
        count += 1
        temp = temp.next
    return count

Python Snippet:

def getLength(head):
    count = 0
    temp = head
    while temp:
        count += 1
        temp = temp.next
    return count

8. Print Linked List

 Pseudocode:

function printList(head):
    temp = head
    while temp != null:
        print temp.val
        temp = temp.next

 Python Snippet:

def printList(head):
    temp = head
    while temp:
        print(temp.val, end=" -> ")
        temp = temp.next
    print("None")



Beginner-Level Singly Linked List Questions (FAANG-Friendly)

#

Problem Name

Key Concepts

Difficulty

Platform

1

Reverse a Linked List

Iteration, Pointer manipulation

Easy

LeetCode

2

Merge Two Sorted Lists

Dummy node, Two pointers

Easy

LeetCode

3

Remove Duplicates from Sorted List

Edge-case handling

Easy

LeetCode

4

Delete Node in a Linked List

In-place manipulation

Easy

LeetCode

5

Middle of the Linked List

Fast & slow pointers

Easy

LeetCode

6

Linked List Cycle

Floyd’s Cycle Detection

Easy

LeetCode

7

Palindrome Linked List

Fast/slow pointer + reverse second half

Easy-Medium

LeetCode

8

Remove Nth Node From End of List

Two pointers, edge case

Medium

LeetCode

9

Convert Binary Number in a Linked List to Integer

Math, Iteration

Easy

LeetCode

10

Intersection of Two Linked Lists

Length comparison or hashset

Easy

LeetCode