Practice 50 Go Lang Data Structures Coding Questions, TechnoVlogs

Practice 50 Go Lang Data Structures Coding Questions


Q1. Write a Go program to implement a stack using a slice.  
  Input:    
  Push: 10, 20, 30
  Pop
  Expected Output:  
  Popped: 30
  Stack: [10, 20]

Q2. Write a Go program to implement a queue using a slice.  
  Input:    
  Enqueue: 5, 10, 15
  Dequeue
  Expected Output:  
  Dequeued: 5
  Queue: [10, 15]

Q3. Write a Go program to reverse a stack using recursion.  
  Input:    
  Stack: [1, 2, 3]
  Expected Output:  
  Reversed Stack: [3, 2, 1]

Q4. Write a Go program to implement a linked list with insert, delete, and display operations.  
  Input:    
  Insert: 10, 20, 30
  Delete: 20
  Expected Output:  
  List: [10, 30]

Q5. Write a Go program to implement a doubly linked list with insert and delete operations.  
  Input:    
  Insert: 5, 10, 15
  Delete: 10
  Expected Output:  
  List: [5, 15]

Q6. Write a Go program to find the middle element of a linked list.  
  Input:    
  List: [1, 2, 3, 4, 5]
  Expected Output:  
  Middle element: 3

Q7. Write a Go program to implement a stack using a linked list.  
  Input:    
  Push: 10, 20, 30
  Pop
  Expected Output:  
  Popped: 30
  Stack: [10, 20]

Q8. Write a Go program to implement a queue using a linked list.  
  Input:    
  Enqueue: 5, 10, 15
  Dequeue
  Expected Output:  
  Dequeued: 5
  Queue: [10, 15]

Q9. Write a Go program to check if a linked list is a palindrome.  
  Input:    
  List: [1, 2, 3, 2, 1]
  Expected Output:  
  The list is a palindrome.

Q10. Write a Go program to implement a binary search tree with insert and search operations.  
   Input:     
   Insert: 50, 30, 20, 40, 70, 60, 80
   Search: 40
   Expected Output:  
   Node 40 found.

Q11. Write a Go program to find the height of a binary search tree.  
   Input:     
   Tree: [50, 30, 20, 40, 70, 60, 80]
   Expected Output:  
   Height: 3

Q12. Write a Go program to find the lowest common ancestor in a binary search tree.  
   Input:     
   Tree: [50, 30, 20, 40, 70, 60, 80]
   Find LCA of 20 and 40
   Expected Output:  
   LCA: 30

Q13. Write a Go program to implement a binary tree with in-order traversal.  
   Input:     
   Tree: [50, 30, 20, 40, 70, 60, 80]
   Expected Output:  
   In-order traversal: 20 30 40 50 60 70 80

Q14. Write a Go program to implement a graph using adjacency list representation.  
   Input:     
   Add Edge: (1, 2), (1, 3), (2, 4)
   Display Graph
   Expected Output:  
   1: [2, 3]
   2: [4]
   3: []
   4: []

Q15. Write a Go program to implement breadth-first search (BFS) for a graph.  
   Input:     
   Graph: 1->2, 1->3, 2->4, 3->5
   Start BFS from node 1
   Expected Output:  
   BFS Order: 1, 2, 3, 4, 5

Q16. Write a Go program to implement depth-first search (DFS) for a graph.  
   Input:     
   Graph: 1->2, 1->3, 2->4, 3->5
   Start DFS from node 1
   Expected Output:  
   DFS Order: 1, 2, 4, 3, 5

Q17. Write a Go program to implement a priority queue using a heap.  
   Input:     
   Insert: 10, 20, 15, 30, 5
   Extract Max
   Expected Output:  
   Max Element: 30
   Queue: [20, 10, 15, 5]

Q18. Write a Go program to implement a circular queue using a slice.  
   Input:     
   Enqueue: 10, 20, 30, 40, 50
   Dequeue
   Expected Output:  
   Dequeued: 10
   Queue: [20, 30, 40, 50]

Q19. Write a Go program to implement a heap sort algorithm.  
   Input:     
   Array: [4, 10, 3, 5, 1]
   Expected Output:  
   Sorted Array: [1, 3, 4, 5, 10]

Q20. Write a Go program to implement a simple hash table with insert, search, and delete operations.  
   Input:     
   Insert: (1, "apple"), (2, "banana")
   Search: 1
   Delete: 2
   Expected Output:  
   Search Result: apple
   Hash Table: {1: "apple"}

Q21. Write a Go program to implement an LRU cache using a linked list.  
   Input:     
   Cache Size: 3
   Add: (1, "apple"), (2, "banana"), (3, "cherry")
   Access: 1
   Add: (4, "date")
   Expected Output:  
   Cache: {1: "apple", 3: "cherry", 4: "date"}

Q22. Write a Go program to implement a binary heap.  
   Input:     
   Insert: 5, 3, 8, 1, 6
   Extract Min
   Expected Output:  
   Min Element: 1
   Heap: [3, 5, 8, 6]

Q23. Write a Go program to implement a linked list with reverse operation.  
   Input:     
   List: [1, 2, 3, 4]
   Reverse List
   Expected Output:  
   Reversed List: [4, 3, 2, 1]

Q24. Write a Go program to implement an AVL tree (self-balancing binary search tree).  
   Input:     
   Insert: 30, 20, 40, 10, 25, 35, 50
   Expected Output:  
   AVL Tree: [30, 20, 10, 25, 40, 35, 50]

Q25. Write a Go program to implement a trie (prefix tree) for storing strings.  
   Input:     
   Insert: "apple", "app", "banana"
   Search: "app"
   Expected Output:  
   "app" found in trie.

Q26. Write a Go program to implement a singly linked list with a function to find the length of the list.  
  Input:    
  List: [10, 20, 30, 40]
  Expected Output:  
  Length of List: 4

Q27. Write a Go program to implement a stack with peek operation (view the top element without popping).  
  Input:    
  Stack: [10, 20, 30]
  Peek
  Expected Output:  
  Peeked: 30

Q28. Write a Go program to implement a stack with a minimum element tracker.  
  Input:    
  Push: 10, 20, 5, 30
  Get Min
  Expected Output:  
  Min Element: 5

Q29. Write a Go program to implement a queue using two stacks.  
  Input:    
  Push: 1, 2, 3
  Pop
  Expected Output:  
  Popped: 1
  Queue: [2, 3]

Q30. Write a Go program to implement a circular doubly linked list with insert and delete operations.  
  Input:    
  Insert: 5, 10, 15
  Delete: 10
  Expected Output:  
  List: [5, 15]

Q31. Write a Go program to merge two sorted linked lists into one sorted linked list.  
  Input:    
  List1: [1, 3, 5]
  List2: [2, 4, 6]
  Expected Output:  
  Merged List: [1, 2, 3, 4, 5, 6]

Q32. Write a Go program to implement a hash map with collision handling using separate chaining.  
  Input:    
  Insert: (1, "apple"), (2, "banana"), (1, "cherry")
  Search: 1
  Expected Output:  
  Search Result: "cherry"

Q33. Write a Go program to implement a hash set.  
  Input:    
  Add: 5, 10, 15, 5
  Expected Output:  
  Set: {5, 10, 15}

Q34. Write a Go program to implement a linked list that supports reversing a range of elements.  
  Input:    
  List: [1, 2, 3, 4, 5]
  Reverse range from 2 to 4
  Expected Output:  
  List after reverse: [1, 4, 3, 2, 5]

Q35. Write a Go program to implement an unordered map.  
  Input:    
  Insert: (1, "apple"), (2, "banana")
  Search: 2
  Expected Output:  
  Search Result: "banana"

Q36. Write a Go program to implement an ordered map (tree map).  
  Input:    
  Insert: (1, "apple"), (2, "banana"), (3, "cherry")
  Display Map
  Expected Output:  
  Map: {1: "apple", 2: "banana", 3: "cherry"}

Q37. Write a Go program to implement a trie with a delete function.  
  Input:    
  Insert: "apple", "app"
  Delete: "apple"
  Search: "apple"
  Expected Output:  
  "apple" not found in trie.

Q38. Write a Go program to implement a max heap.  
  Input:    
  Insert: 10, 20, 30, 40, 50
  Extract Max
  Expected Output:  
  Max Element: 50
  Heap: [40, 30, 20, 10]

Q39. Write a Go program to implement a min heap.  
  Input:    
  Insert: 10, 20, 5, 30, 25
  Extract Min
  Expected Output:  
  Min Element: 5
  Heap: [10, 20, 25, 30]

Q40. Write a Go program to implement a doubly linked list with a reverse method.  
  Input:    
  List: [1, 2, 3, 4]
  Reverse List
  Expected Output:  
  Reversed List: [4, 3, 2, 1]

Q41. Write a Go program to implement a linked list with sorting functionality.  
  Input:    
  List: [30, 10, 20, 40]
  Sort List
  Expected Output:  
  Sorted List: [10, 20, 30, 40]

Q42. Write a Go program to implement an AVL tree with insertion.  
  Input:    
  Insert: 30, 20, 40, 10, 25, 35, 50
  Expected Output:  
  AVL Tree: [30, 20, 10, 25, 40, 35, 50]

Q43. Write a Go program to implement a radix sort algorithm.  
  Input:    
  Array: [170, 45, 75, 90, 802, 24, 2, 66]
  Expected Output:  
  Sorted Array: [2, 24, 45, 66, 75, 90, 170, 802]

Q44. Write a Go program to implement a doubly linked list with insert at head and tail operations.  
  Input:    
  Insert at head: 10, 20
  Insert at tail: 30, 40
  Expected Output:  
  List: [10, 20, 30, 40]

Q45. Write a Go program to implement a queue using two stacks.  
  Input:    
  Push: 5, 10, 15
  Pop
  Expected Output:  
  Popped: 5
  Queue: [10, 15]

Q46. Write a Go program to implement a stack with a "get minimum" function.  
  Input:    
  Push: 10, 20, 5, 15
  Get Min
  Expected Output:  
  Min Element: 5

Q47. Write a Go program to implement a graph using adjacency matrix representation.  
  Input:    
  Add Edge: (0, 1), (1, 2), (2, 0)
  Display Graph
  Expected Output:  
  Adjacency Matrix: 
  [[0, 1, 0], 
   [0, 0, 1], 
   [1, 0, 0]]

Q48. Write a Go program to implement a set with union and intersection operations.  
  Input:    
  Set1: {1, 2, 3}, Set2: {3, 4, 5}
  Union
  Intersection
  Expected Output:  
  Union: {1, 2, 3, 4, 5}
  Intersection: {3}

Q49. Write a Go program to implement a singly linked list with a function to detect a cycle.  
  Input:    
  List: [1, 2, 3, 4]
  Add Cycle: 2
  Expected Output:  
  The list contains a cycle.

Q50. Write a Go program to implement a stack with multi-stack support using a single array.  
  Input:    
  Push Stack1: 10, 20
  Push Stack2: 30, 40
  Expected Output:  
  Stack1: [10, 20]
  Stack2: [30, 40]

Share on Social Media