Data Structures Assignments in C


Linked Lists

  1. Write a C program to create and display a singly linked list.
    • Expected Output:
    Linked List: 1 -> 2 -> 3 -> NULL
  2. Write a C program to insert an element at the beginning of a singly linked list.
    • Input: Insert 5
    • Expected Output:
    Linked List after inserting 5: 5 -> 1 -> 2 -> 3 -> NULL
  3. Write a C program to insert an element at the end of a singly linked list.
    • Input: Insert 4
    • Expected Output:
    Linked List after inserting 4: 1 -> 2 -> 3 -> 4 -> NULL
  4. Write a C program to delete an element from a singly linked list by key.
    • Input: Delete 2
    • Expected Output:
    Linked List after deleting 2: 1 -> 3 -> 4 -> NULL
  5. Write a C program to find the length of a singly linked list.
    • Expected Output:
    Length of Linked List: 4
  6. Write a C program to reverse a singly linked list.
    • Expected Output:
    Reversed Linked List: 3 -> 2 -> 1 -> NULL
  7. Write a C program to concatenate two singly linked lists.
    • Input: List1: 1 -> 2 -> 3, List2: 4 -> 5 -> 6
    • Expected Output:
    Concatenated List: 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> NULL
  8. Write a C program to detect a loop in a singly linked list (if any).
    • Expected Output:
    Loop detected: Yes / No
  9. Write a C program to find the middle node of a singly linked list.
    • Expected Output:
    Middle Node: 2
  10. Write a C program to remove duplicates from a sorted singly linked list.
    • Input: List: 1 -> 1 -> 2 -> 3 -> 3 -> 3
    • Expected Output:
      List after removing duplicates: 1 -> 2 -> 3 -> NULL

Stacks

  1. Write a C program to implement a stack using an array. Include operations for push, pop, and display.
    • Input: Push 5, 10, 15
    • Expected Output:
    Stack: [5, 10, 15]
  2. Write a C program to implement a stack using linked list. Include operations for push, pop, and display.
    • Input: Push 5, 10, 15
    • Expected Output:
    Stack: 15 -> 10 -> 5
  3. Write a C program to evaluate a postfix expression using a stack.
    • Input: Postfix expression: 6 5 2 3 + 8 * + 3 + *
    • Expected Output:
    Result: 288
  4. Write a C program to reverse a stack using recursion.
    • Input: Stack: [1, 2, 3, 4, 5]
    • Expected Output:
    Reversed Stack: [5, 4, 3, 2, 1]
  5. Write a C program to check if parentheses in a string are balanced using a stack.
    • Input: String: ((()))
    • Expected Output:
      Balanced parentheses: Yes

Queues

  1. Write a C program to implement a queue using an array. Include operations for enqueue, dequeue, and display.
    • Input: Enqueue 5, 10, 15
    • Expected Output:
    Queue: [5, 10, 15]
  2. Write a C program to implement a queue using linked list. Include operations for enqueue, dequeue, and display.
    • Input: Enqueue 5, 10, 15
    • Expected Output:
    Queue: 5 -> 10 -> 15
  3. Write a C program to implement a circular queue using an array. Include operations for enqueue, dequeue, and display.
    • Input: Enqueue 5, 10, 15
    • Expected Output:
    Circular Queue: [5, 10, 15]
  4. Write a C program to reverse the first K elements of a queue.
    • Input: Queue 1, 2, 3, 4, 5 and K 3
    • Expected Output:
      Queue after reversing first 3 elements: 3 -> 2 -> 1 -> 4 -> 5

Trees

  1. Write a C program to implement a binary search tree (BST). Include operations for insertion, deletion, and traversal (inorder, preorder, and postorder).
    • Input: Insert 5, 3, 7, 2, 4, 6
    • Expected Output: (Inorder traversal)
    BST: 2 -> 3 -> 4 -> 5 -> 6 -> 7
  2. Write a C program to find the height of a binary tree.
    • Input: BST 5, 3, 7, 2, 4, 6
    • Expected Output:
    Height of BST: 3
  3. Write a C program to count leaf nodes in a binary tree.
    • Input: BST 5, 3, 7, 2, 4, 6
    • Expected Output:
    Leaf nodes in BST: 3
  4. Write a C program to find the lowest common ancestor (LCA) of two nodes in a binary search tree.
    • Input: BST 5, 3, 7, 2, 4, 6 and Nodes 2, 4
    • Expected Output:
    LCA of 2 and 4: 3
  5. Write a C program to check if a binary tree is symmetric.
    • Input: Binary Tree 1, 2, 2, 3, 4, 4, 3
    • Expected Output:
    Binary Tree is symmetric: Yes
  6. Write a C program to perform level order traversal of a binary tree.
    • Input: Binary Tree 1, 2, 3, 4, 5, 6, 7
    • Expected Output:
      Level Order Traversal: 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7

Mahesh Wabale

Leave a Comment