Bird
Raised Fist0
DSA C#programming~20 mins

Push Using Linked List Node in DSA C# - Practice Problems & Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Linked List Push Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output after pushing nodes onto the linked list?

Consider the following C# code that pushes nodes onto a singly linked list. What will be the printed linked list after all push operations?

DSA C#
public class Node {
    public int data;
    public Node next;
    public Node(int d) { data = d; next = null; }
}

public class LinkedList {
    public Node head;

    public void Push(int new_data) {
        Node new_node = new Node(new_data);
        new_node.next = head;
        head = new_node;
    }

    public void PrintList() {
        Node temp = head;
        while (temp != null) {
            System.Console.Write(temp.data + " -> ");
            temp = temp.next;
        }
        System.Console.WriteLine("null");
    }
}

LinkedList list = new LinkedList();
list.Push(10);
list.Push(20);
list.Push(30);
list.PrintList();
A10 -> 20 -> 30 -> null
Bnull -> 30 -> 20 -> 10
C30 -> 20 -> 10 -> null
D20 -> 30 -> 10 -> null
Attempts:
2 left
💡 Hint

Remember that pushing adds a new node at the beginning of the list.

❓ Predict Output
intermediate
2:00remaining
What is the output after pushing nodes with duplicate values?

Given the code below, what will be the printed linked list after pushing the values?

DSA C#
public class Node {
    public int data;
    public Node next;
    public Node(int d) { data = d; next = null; }
}

public class LinkedList {
    public Node head;

    public void Push(int new_data) {
        Node new_node = new Node(new_data);
        new_node.next = head;
        head = new_node;
    }

    public void PrintList() {
        Node temp = head;
        while (temp != null) {
            System.Console.Write(temp.data + " -> ");
            temp = temp.next;
        }
        System.Console.WriteLine("null");
    }
}

LinkedList list = new LinkedList();
list.Push(5);
list.Push(10);
list.Push(5);
list.Push(20);
list.PrintList();
A20 -> 5 -> 10 -> 5 -> null
B5 -> 10 -> 5 -> 20 -> null
C5 -> 5 -> 10 -> 20 -> null
D20 -> 10 -> 5 -> 5 -> null
Attempts:
2 left
💡 Hint

Push adds nodes at the front, so the last pushed value is first.

🔧 Debug
advanced
2:00remaining
Identify the error in this push method implementation

What error will occur when running the following push method in C#?

DSA C#
public void Push(int new_data) {
    Node new_node = new Node(new_data);
    new_node.next = head.next;
    head = new_node;
}
AStackOverflowException due to infinite recursion
BNullReferenceException at new_node.next = head.next;
CNo error, list is updated correctly
DCompilation error due to missing semicolon
Attempts:
2 left
💡 Hint

Consider what happens if head is null before push.

🧠 Conceptual
advanced
1:00remaining
What is the time complexity of the push operation in a singly linked list?

Consider the push operation that inserts a new node at the beginning of a singly linked list. What is its time complexity?

AO(n^2) - Quadratic time
BO(n) - Linear time
CO(log n) - Logarithmic time
DO(1) - Constant time
Attempts:
2 left
💡 Hint

Push only changes a few pointers at the head.

🚀 Application
expert
3:00remaining
After pushing nodes, what is the linked list state?

Given the following sequence of push operations on an empty linked list, what is the final state of the list?

DSA C#
LinkedList list = new LinkedList();
list.Push(1);
list.Push(2);
list.Push(3);
list.Push(4);
list.Push(5);
list.PrintList();
A5 -> 4 -> 3 -> 2 -> 1 -> null
B1 -> 2 -> 3 -> 4 -> 5 -> null
C1 -> 5 -> 2 -> 4 -> 3 -> null
Dnull
Attempts:
2 left
💡 Hint

Each push adds a new node at the front, so the last pushed is first.

Practice

(1/5)
1. What does the push operation do in a linked list when using nodes?
easy
A. Adds a new node at the beginning of the list
B. Removes the last node from the list
C. Searches for a node with a specific value
D. Deletes the first node from the list

Solution

  1. Step 1: Understand push operation in linked list

    The push operation inserts a new node at the start of the linked list.
  2. Step 2: Effect of push on list structure

    The new node becomes the head, and its next pointer points to the old head.
  3. Final Answer:

    Adds a new node at the beginning of the list -> Option A
  4. Quick Check:

    Push means insert at head [OK]
Hint: Push always adds node at the start of the list [OK]
Common Mistakes:
  • Confusing push with pop operation
  • Thinking push adds at the end
  • Assuming push deletes nodes
2. Which of the following is the correct syntax to create a new node and push it onto a linked list in C#?
easy
A. Node newNode = new Node(); head = newNode.next; newNode.data = data;
B. Node newNode = new Node(data); newNode.next = head; head = newNode;
C. head = new Node(data); head.next = null;
D. Node newNode = new Node(data); head = newNode.next; newNode = head;

Solution

  1. Step 1: Create new node with data

    Use new Node(data) to create a node with the given data.
  2. Step 2: Link new node to current head and update head

    Set newNode.next = head and then head = newNode to push at front.
  3. Final Answer:

    Node newNode = new Node(data); newNode.next = head; head = newNode; -> Option B
  4. Quick Check:

    New node points to old head, then head updated [OK]
Hint: New node next points to head, then head updated [OK]
Common Mistakes:
  • Assigning head before setting newNode.next
  • Not initializing new node with data
  • Swapping head and newNode incorrectly
3. What will be the output linked list after executing this code?
Node head = null;
head = new Node(10);
head.next = new Node(20);
Node newNode = new Node(5);
newNode.next = head;
head = newNode;

Print the list from head to end.
medium
A. 10 -> 20 -> 5 -> null
B. 5 -> 20 -> 10 -> null
C. 20 -> 10 -> 5 -> null
D. 5 -> 10 -> 20 -> null

Solution

  1. Step 1: Initial list creation

    Head points to node 10, which points to node 20, then null.
  2. Step 2: Push new node with value 5

    New node 5 points to old head (10), then head updated to new node 5.
  3. Final Answer:

    5 -> 10 -> 20 -> null -> Option D
  4. Quick Check:

    New node added at front [OK]
Hint: New node points to old head, becomes new head [OK]
Common Mistakes:
  • Appending new node at end instead of front
  • Not updating head to new node
  • Confusing node order after push
4. Identify the error in this push method for a singly linked list:
public void Push(int data) {
    Node newNode = new Node(data);
    newNode.next = null;
    head = newNode;
}
medium
A. newNode.next should point to current head before updating head
B. Node constructor is missing data parameter
C. head should be set to null before assigning newNode
D. No error, code is correct

Solution

  1. Step 1: Analyze newNode.next assignment

    Setting newNode.next = null disconnects new node from existing list.
  2. Step 2: Correct linking for push operation

    New node's next should point to current head to keep list intact before updating head.
  3. Final Answer:

    newNode.next should point to current head before updating head -> Option A
  4. Quick Check:

    Link new node to old head before head update [OK]
Hint: Link new node to old head before changing head [OK]
Common Mistakes:
  • Setting newNode.next to null breaks list
  • Not updating head after push
  • Confusing order of assignments
5. Given a linked list with nodes 30 -> 20 -> 10 -> null, you want to push nodes 40 and 50 in that order using the push method. What will be the final list?
hard
A. 30 -> 20 -> 10 -> 50 -> 40 -> null
B. 40 -> 50 -> 30 -> 20 -> 10 -> null
C. 50 -> 40 -> 30 -> 20 -> 10 -> null
D. 30 -> 20 -> 10 -> 40 -> 50 -> null

Solution

  1. Step 1: Initial list and first push

    Start with 30 -> 20 -> 10 -> null. Push 40: new head is 40, list is 40 -> 30 -> 20 -> 10 -> null.
  2. Step 2: Second push with 50

    Push 50: new head is 50, list becomes 50 -> 40 -> 30 -> 20 -> 10 -> null.
  3. Final Answer:

    50 -> 40 -> 30 -> 20 -> 10 -> null -> Option C
  4. Quick Check:

    Push adds nodes at front in reverse order [OK]
Hint: Last pushed node becomes new head [OK]
Common Mistakes:
  • Assuming push adds at end
  • Mixing order of pushed nodes
  • Not updating head after each push
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard