1. Gyanastra
  2. Data Structures
  3. Singly Linked Lists
  4. Self-Referential Structures and the Singly Linked List Node
Free lesson, no account needed 4 min read 8 practice questions after it
Asked in past papers6 times
  • GATE CSE202620171987
  • UGC NET202320092006

Data Structures · Singly Linked Lists

Self-Referential Structures and the Singly Linked List Node

Overview

A singly linked list is a chain of nodes, each node being a structure that contains a pointer to a structure of its own type.
This self-referential structure is the foundation of dynamic list building: nodes are created at run time and joined by their links into a one-directional chain.

Key concepts

  • Singly linked list: a collection of nodes, where each node is a self-referential structure.
  • Self-referential structure: a structure that contains, inside it, a pointer that points to a structure of the same type.
  • Node structure: the structure with tag node, holding a data part and one link pointer:
struct node
{
    char data;
    struct node *link;
};
  • struct node — the structure with tag node.
  • char data — the data part, stored as a character.
  • struct node *link — a pointer that points to a structure of the same type (struct node).
  • The list is called single linked because every structure has only one link (one link, single link, single link, ...).
  • Movement is possible in only one direction: forward from a node to its next node; you cannot come back to the previous node.

How it works

  1. Declare the self-referential node structure (data plus one pointer to the same structure type).
  2. Dynamically create many such structures (nodes).
  3. Link them one after another using the link pointer of each node, so that from one node you can reach the next node.
  4. The resulting chain of nodes is the singly linked list.

Example arrangement: 6 structures are created and linked in a chain — from the first node you can reach the second, from the second the third, and so on. Reaching a node gives access to the next node through its link.

Revision summary

  • The structure must be self-referential: it contains a pointer to its own structure type (struct node *link).
  • Each node in a singly linked list has exactly one link — that is why it is called a single linked list.
  • Traversal is one-directional only (forward); backward movement is not possible.
  • Nodes are created dynamically and joined by their link pointers to form the list.

Previous-year exam insights

  • In C, a structure cannot contain a member of its own type (that would be infinitely sized); it may contain only a pointer to its own type, which is why the self-reference must be through a pointer.
    Asked inGATE 2017GATE 2026
  • A NULL-terminated list is detected by testing the link pointer against NULL (e.g., node->next == NULL identifies the last node);
    dereferencing a NULL pointer is undefined behaviour and must be guarded.
    Asked inGATE 2017GATE 2026
  • Recursive list operations (e.g., counting nodes) need a base case for the empty/NULL list and a recursive case that advances to next; the size of a non-empty list is 1 + size of the rest.
    Asked inGATE 2026
  • Appending one list to another requires traversing to the last node of the destination list, so it takes O(n)O(n) time; if the destination list is empty the head pointer itself must be updated.
    Asked inGATE 2017
  • A doubly linked list can be implemented with a single pointer per node by storing the XOR of the previous and next node addresses (XOR-linked list), but traversal then requires an extra pointer to the previous or next node.
    Asked inUGC NET 2023
  • Insertion at the front of a singly linked list is O(1)O(1), while insertion/deletion at a given position or at the end requires O(n)O(n) traversal; searching is O(n)O(n) since only forward traversal is possible.

Singly Linked List Node Chain

Shows six dynamically created nodes joined by their single link pointers into a one-directional chain ending at NULL.

Pages 1–2 of 2