|
1 | 1 | # GO - Data Structures and Algorithms
|
2 | 2 |
|
3 |
| -Inspired by the **[Geeksforgeeks - Top 10 Algorithms in Interview Questions](https://www.geeksforgeeks.org/top-10-algorithms-in-interview-questions/amp/)** article, the intent of this repository is to solve these questions using the **Go Language**. GO is a great language choice for technical interviews and hopefully you can find these solutions to the common algorithms/problems easy to understand. |
| 3 | +Inspired by the **[Geeksforgeeks - Top 10 Algorithms in Interview Questions](https://www.geeksforgeeks.org/top-10-algorithms-in-interview-questions/amp/)** article, the intent of this repository is to solve these questions using the **Go Language**. GO is a great language choice for technical interviews and hopefully you can find these solutions to the common algorithms/problems easy to understand. |
4 | 4 |
|
5 |
| -Although this is an introductory material to algorithms and data structures, it assumes that you are familiar with GO programming language syntax and basic concepts. |
| 5 | +Although this is an introductory material to algorithms and data structures, it assumes that you are familiar with GO programming language syntax and basic concepts. |
6 | 6 |
|
7 | 7 | WIP, the descriptions of the below `unsolved yet` problems can be found in the [orginal article](https://www.geeksforgeeks.org/top-10-algorithms-in-interview-questions/amp/).
|
8 | 8 |
|
9 | 9 | > ***Contributions are welcomed - solve a problem and submit a PR***.
|
10 | 10 | > ***Contribution guidelines***
|
| 11 | +> |
11 | 12 | > * keep the consistency and document the code
|
12 | 13 | > * optimize for readability and simplicity (not over-engineered, best performance is not in scope)
|
13 | 14 |
|
14 | 15 | ## [Graph](https://github.com/danrusei/algorithms_with_Go/tree/main/graph)
|
15 | 16 |
|
16 |
| -- [x] [Breadth First Search (BFS)](https://github.com/danrusei/algorithms_with_Go/tree/main/graph/traverse_bfs) |
17 |
| -- [x] [Depth First Search (DFS)](https://github.com/danrusei/algorithms_with_Go/tree/main/graph/traverse_dfs) |
18 |
| -- [x] [Shortest Path from source to all vertices (Dijkstra)](https://github.com/danrusei/algorithms_with_Go/tree/main/graph/dijkstra) |
19 |
| -- [] Shortest Path from every vertex to every other vertex (Floyd Warshall) |
20 |
| -- [] To detect cycle in a Graph (Union Find) |
21 |
| -- [] Minimum Spanning tree (Prim) |
22 |
| -- [] Minimum Spanning tree (Kruskal) |
23 |
| -- [] Topological Sort |
24 |
| -- [x] [Boggle (Find all possible words in a board of characters)](https://github.com/danrusei/algorithms_with_Go/tree/main/graph/boggle) |
25 |
| -- [x] [Bridges in a Graph](https://github.com/danrusei/algorithms_with_Go/tree/main/graph/bridges) |
| 17 | +* [x] [Breadth First Search (BFS)](https://github.com/danrusei/algorithms_with_Go/tree/main/graph/traverse_bfs) |
| 18 | +* [x] [Depth First Search (DFS)](https://github.com/danrusei/algorithms_with_Go/tree/main/graph/traverse_dfs) |
| 19 | +* [x] [Shortest Path from source to all vertices (Dijkstra)](https://github.com/danrusei/algorithms_with_Go/tree/main/graph/dijkstra) |
| 20 | +* [] Shortest Path from every vertex to every other vertex (Floyd Warshall) |
| 21 | +* [] To detect cycle in a Graph (Union Find) |
| 22 | +* [] Minimum Spanning tree (Prim) |
| 23 | +* [] Minimum Spanning tree (Kruskal) |
| 24 | +* [] Topological Sort |
| 25 | +* [x] [Boggle (Find all possible words in a board of characters)](https://github.com/danrusei/algorithms_with_Go/tree/main/graph/boggle) |
| 26 | +* [x] [Bridges in a Graph](https://github.com/danrusei/algorithms_with_Go/tree/main/graph/bridges) |
26 | 27 |
|
27 | 28 | ## [Linked List](https://github.com/danrusei/algorithms_with_Go/tree/main/linkedlist)
|
28 | 29 |
|
29 |
| -- [x] [Insertion of a node in Linked List (On the basis of some constraints)](https://github.com/danrusei/algorithms_with_Go/tree/main/linkedlist/insert_node) |
30 |
| -- [] Delete a given node in Linked List (under given constraints) |
31 |
| -- [x] [Compare two strings represented as linked lists](https://github.com/danrusei/algorithms_with_Go/tree/main/linkedlist/compare_strings) |
32 |
| -- [] Add Two Numbers Represented By Linked Lists |
33 |
| -- [] Merge A Linked List Into Another Linked List At Alternate Positions |
34 |
| -- [x] [Reverse A List In Groups Of Given Size](https://github.com/danrusei/algorithms_with_Go/tree/main/linkedlist/reverse_by_groups) |
35 |
| -- [] Union And Intersection Of 2 Linked Lists |
36 |
| -- [x] [Detect And Remove Loop In A Linked List](https://github.com/danrusei/algorithms_with_Go/tree/main/linkedlist/remove_loop) |
37 |
| -- [] Merge Sort For Linked Lists |
38 |
| -- [x] [Select A Random Node from A Singly Linked List](https://github.com/danrusei/algorithms_with_Go/tree/main/linkedlist/random_node) |
| 30 | +* [x] [Insertion of a node in Linked List (On the basis of some constraints)](https://github.com/danrusei/algorithms_with_Go/tree/main/linkedlist/insert_node) |
| 31 | +* [] Delete a given node in Linked List (under given constraints) |
| 32 | +* [x] [Compare two strings represented as linked lists](https://github.com/danrusei/algorithms_with_Go/tree/main/linkedlist/compare_strings) |
| 33 | +* [] Add Two Numbers Represented By Linked Lists |
| 34 | +* [] Merge A Linked List Into Another Linked List At Alternate Positions |
| 35 | +* [x] [Reverse A List In Groups Of Given Size](https://github.com/danrusei/algorithms_with_Go/tree/main/linkedlist/reverse_by_groups) |
| 36 | +* [] Union And Intersection Of 2 Linked Lists |
| 37 | +* [x] [Detect And Remove Loop In A Linked List](https://github.com/danrusei/algorithms_with_Go/tree/main/linkedlist/remove_loop) |
| 38 | +* [] Merge Sort For Linked Lists |
| 39 | +* [x] [Select A Random Node from A Singly Linked List](https://github.com/danrusei/algorithms_with_Go/tree/main/linkedlist/random_node) |
39 | 40 |
|
40 | 41 | ## [Tree / Binary Search Tree](https://github.com/danrusei/algorithms_with_Go/tree/main/binary_tree)
|
41 | 42 |
|
42 |
| -- [x] [Find Minimum Depth of a Binary Tree](https://github.com/danrusei/algorithms_with_Go/tree/main/binary_tree/minimum_depth) |
43 |
| -- [] Maximum Path Sum in a Binary Tree |
44 |
| -- [x] [Check if a given array can represent Preorder Traversal of Binary Search Tree](https://github.com/danrusei/algorithms_with_Go/tree/main/binary_tree/preorder_traversal) |
45 |
| -- [] Check whether a binary tree is a full binary tree or not |
46 |
| -- [x] [Bottom View Binary Tree](https://github.com/danrusei/algorithms_with_Go/tree/main/binary_tree/bottom_view) |
47 |
| -- [] Print Nodes in Top View of Binary Tree |
48 |
| -- [x] [Remove nodes on root to leaf paths of length < K](https://github.com/danrusei/algorithms_with_Go/tree/main/binary_tree/remove_nodes) |
49 |
| -- [] Lowest Common Ancestor in a Binary Search Tree |
50 |
| -- [] Check if a binary tree is subtree of another binary tree |
51 |
| -- [x] [Reverse alternate levels of a perfect binary tree](https://github.com/danrusei/algorithms_with_Go/tree/main/binary_tree/reverse_alternate) |
| 43 | +* [x] [Find Minimum Depth of a Binary Tree](https://github.com/danrusei/algorithms_with_Go/tree/main/binary_tree/minimum_depth) |
| 44 | +* [] Maximum Path Sum in a Binary Tree |
| 45 | +* [x] [Check if a given array can represent Preorder Traversal of Binary Search Tree](https://github.com/danrusei/algorithms_with_Go/tree/main/binary_tree/preorder_traversal) |
| 46 | +* [] Check whether a binary tree is a full binary tree or not |
| 47 | +* [x] [Bottom View Binary Tree](https://github.com/danrusei/algorithms_with_Go/tree/main/binary_tree/bottom_view) |
| 48 | +* [] Print Nodes in Top View of Binary Tree |
| 49 | +* [x] [Remove nodes on root to leaf paths of length < K](https://github.com/danrusei/algorithms_with_Go/tree/main/binary_tree/remove_nodes) |
| 50 | +* [] Lowest Common Ancestor in a Binary Search Tree |
| 51 | +* [] Check if a binary tree is subtree of another binary tree |
| 52 | +* [x] [Reverse alternate levels of a perfect binary tree](https://github.com/danrusei/algorithms_with_Go/tree/main/binary_tree/reverse_alternate) |
52 | 53 |
|
53 | 54 | ## [Other Data Structures](https://github.com/danrusei/algorithms_with_Go/tree/main/other_ds)
|
54 | 55 |
|
55 |
| -- [x] [STACK](https://github.com/danrusei/algorithms_with_Go/tree/main/other_ds/stack) |
56 |
| -- [x] [QUEUE](https://github.com/danrusei/algorithms_with_Go/tree/main/other_ds/queue) |
57 |
| -- [] HASH-TABLE |
| 56 | +* [x] **[Stack](https://github.com/danrusei/algorithms_with_Go/tree/main/other_ds/stack)** |
| 57 | +* [x] **[Queue](https://github.com/danrusei/algorithms_with_Go/tree/main/other_ds/queue)** |
| 58 | +* [x] **[HashTable](https://github.com/danrusei/algorithms_with_Go/tree/main/other_ds/hashtable)** |
58 | 59 |
|
59 | 60 | ## [Sorting And Searching](https://github.com/danrusei/algorithms_with_Go/tree/main/sorting)
|
60 | 61 |
|
61 |
| -- [] Binary Search |
62 |
| -- [] Search an element in a sorted and rotated array |
63 |
| -- [x] [Bubble Sort](https://github.com/danrusei/algorithms_with_Go/tree/main/sorting/bubble_sort) |
64 |
| -- [x] [Insertion Sort](https://github.com/danrusei/algorithms_with_Go/tree/main/sorting/insertion_sort) |
65 |
| -- [x] [Merge Sort](https://github.com/danrusei/algorithms_with_Go/tree/main/sorting/merge_sort) |
66 |
| -- [x] [Heap Sort (Binary Heap)](https://github.com/danrusei/algorithms_with_Go/tree/main/sorting/heap_sort) |
67 |
| -- [x] [Quick Sort](https://github.com/danrusei/algorithms_with_Go/tree/main/sorting/quick_sort) |
68 |
| -- [] Interpolation Search |
69 |
| -- [] Find Kth Smallest/Largest Element In Unsorted Array |
70 |
| -- [] Given a sorted array and a number x, find the pair in array whose sum is closest to x |
| 62 | +* [] Binary Search |
| 63 | +* [] Search an element in a sorted and rotated array |
| 64 | +* [x] [Bubble Sort](https://github.com/danrusei/algorithms_with_Go/tree/main/sorting/bubble_sort) |
| 65 | +* [x] [Insertion Sort](https://github.com/danrusei/algorithms_with_Go/tree/main/sorting/insertion_sort) |
| 66 | +* [x] [Merge Sort](https://github.com/danrusei/algorithms_with_Go/tree/main/sorting/merge_sort) |
| 67 | +* [x] [Heap Sort (Binary Heap)](https://github.com/danrusei/algorithms_with_Go/tree/main/sorting/heap_sort) |
| 68 | +* [x] [Quick Sort](https://github.com/danrusei/algorithms_with_Go/tree/main/sorting/quick_sort) |
| 69 | +* [] Interpolation Search |
| 70 | +* [] Find Kth Smallest/Largest Element In Unsorted Array |
| 71 | +* [] Given a sorted array and a number x, find the pair in array whose sum is closest to x |
71 | 72 |
|
72 | 73 | ## [Dynamic Programming](https://github.com/danrusei/algorithms_with_Go/tree/main/dynamic)
|
73 | 74 |
|
74 |
| -- [x] [Longest Common Subsequence](https://github.com/danrusei/algorithms_with_Go/tree/main/dynamic/longest_common_subsequence) |
75 |
| -- [] Longest Increasing Subsequence |
76 |
| -- [] Edit Distance |
77 |
| -- [] Minimum Partition |
78 |
| -- [x] [Ways to Cover a Distance](https://github.com/danrusei/algorithms_with_Go/tree/main/dynamic/cover_distance) |
79 |
| -- [] Longest Path In Matrix |
80 |
| -- [x] [Subset Sum Problem](https://github.com/danrusei/algorithms_with_Go/tree/main/dynamic/subset_sum) |
81 |
| -- [] Optimal Strategy for a Game |
82 |
| -- [] 0-1 Knapsack Problem |
83 |
| -- [] Boolean Parenthesization Problem |
| 75 | +* [x] [Longest Common Subsequence](https://github.com/danrusei/algorithms_with_Go/tree/main/dynamic/longest_common_subsequence) |
| 76 | +* [] Longest Increasing Subsequence |
| 77 | +* [] Edit Distance |
| 78 | +* [] Minimum Partition |
| 79 | +* [x] [Ways to Cover a Distance](https://github.com/danrusei/algorithms_with_Go/tree/main/dynamic/cover_distance) |
| 80 | +* [] Longest Path In Matrix |
| 81 | +* [x] [Subset Sum Problem](https://github.com/danrusei/algorithms_with_Go/tree/main/dynamic/subset_sum) |
| 82 | +* [] Optimal Strategy for a Game |
| 83 | +* [] 0-1 Knapsack Problem |
| 84 | +* [] Boolean Parenthesization Problem |
84 | 85 |
|
85 | 86 | ## [BIT Manipulation](https://github.com/danrusei/algorithms_with_Go/tree/main/bitwise)
|
86 | 87 |
|
87 |
| -- [x] [Maximum Subarray XOR](https://github.com/danrusei/algorithms_with_Go/tree/main/bitwise/max_xor) |
88 |
| -- [] Magic Number |
89 |
| -- [] Sum of bit differences among all pairs |
90 |
| -- [x] [Swap All Odds And Even Bits](https://github.com/danrusei/algorithms_with_Go/tree/main/bitwise/swapp_odd_even) |
91 |
| -- [] Find the element that appears once |
92 |
| -- [x] [Binary representation of a given number](https://github.com/danrusei/algorithms_with_Go/tree/main/bitwise/decimal_to_binary) |
93 |
| -- [] Count total set bits in all numbers from 1 to n |
94 |
| -- [x] [Rotate bits of a number](https://github.com/danrusei/algorithms_with_Go/tree/main/bitwise/rotate_bits) |
95 |
| -- [] Count number of bits to be flipped to convert A to B |
96 |
| -- [x] [Find Next Sparse Number](https://github.com/danrusei/algorithms_with_Go/tree/main/bitwise/next_sparse) |
| 88 | +* [x] [Maximum Subarray XOR](https://github.com/danrusei/algorithms_with_Go/tree/main/bitwise/max_xor) |
| 89 | +* [] Magic Number |
| 90 | +* [] Sum of bit differences among all pairs |
| 91 | +* [x] [Swap All Odds And Even Bits](https://github.com/danrusei/algorithms_with_Go/tree/main/bitwise/swapp_odd_even) |
| 92 | +* [] Find the element that appears once |
| 93 | +* [x] [Binary representation of a given number](https://github.com/danrusei/algorithms_with_Go/tree/main/bitwise/decimal_to_binary) |
| 94 | +* [] Count total set bits in all numbers from 1 to n |
| 95 | +* [x] [Rotate bits of a number](https://github.com/danrusei/algorithms_with_Go/tree/main/bitwise/rotate_bits) |
| 96 | +* [] Count number of bits to be flipped to convert A to B |
| 97 | +* [x] [Find Next Sparse Number](https://github.com/danrusei/algorithms_with_Go/tree/main/bitwise/next_sparse) |
97 | 98 |
|
98 | 99 | ## [Number Theory](https://github.com/danrusei/algorithms_with_Go/tree/main/numbers)
|
99 | 100 |
|
100 |
| -- [] Modular Exponentiation |
101 |
| -- [x] [Modular multiplicative inverse](https://github.com/danrusei/algorithms_with_Go/tree/main/numbers/multiplicative) |
102 |
| -- [] Primality Test | Set 2 (Fermat Method) |
103 |
| -- [] Euler’s Totient Function |
104 |
| -- [x] [Sieve of Eratosthenes](https://github.com/danrusei/algorithms_with_Go/tree/main/numbers/eratosthenes) |
105 |
| -- [] Convex Hull |
106 |
| -- [] Basic and Extended Euclidean algorithms |
107 |
| -- [x] [Segmented Sieve](https://github.com/danrusei/algorithms_with_Go/tree/main/numbers/segmented) |
108 |
| -- [] Chinese remainder theorem |
109 |
| -- [] Lucas Theorem |
| 101 | +* [] Modular Exponentiation |
| 102 | +* [x] [Modular multiplicative inverse](https://github.com/danrusei/algorithms_with_Go/tree/main/numbers/multiplicative) |
| 103 | +* [] Primality Test | Set 2 (Fermat Method) |
| 104 | +* [] Euler’s Totient Function |
| 105 | +* [x] [Sieve of Eratosthenes](https://github.com/danrusei/algorithms_with_Go/tree/main/numbers/eratosthenes) |
| 106 | +* [] Convex Hull |
| 107 | +* [] Basic and Extended Euclidean algorithms |
| 108 | +* [x] [Segmented Sieve](https://github.com/danrusei/algorithms_with_Go/tree/main/numbers/segmented) |
| 109 | +* [] Chinese remainder theorem |
| 110 | +* [] Lucas Theorem |
110 | 111 |
|
111 | 112 | ## [String / Array](https://github.com/danrusei/algorithms_with_Go/tree/main/strings)
|
112 | 113 |
|
113 |
| -- [x] [Reverse an array without affecting special characters](https://github.com/danrusei/algorithms_with_Go/tree/main/strings/reverse_alpha) |
114 |
| -- [] All Possible Palindromic Partitions |
115 |
| -- [] Count triplets with sum smaller than a given value |
116 |
| -- [x] [Convert array into Zig-Zag fashion](https://github.com/danrusei/algorithms_with_Go/tree/main/strings/zig_zag) |
117 |
| -- [] Generate all possible sorted arrays from alternate elements of two given sorted arrays |
118 |
| -- [] Pythagorean Triplet in an array |
119 |
| -- [x] [Length of the largest subarray with contiguous elements](https://github.com/danrusei/algorithms_with_Go/tree/main/strings/largest_subarray) |
120 |
| -- [] Find the smallest positive integer value that cannot be represented as sum of any subset of a given array |
121 |
| -- [x] [Smallest subarray with sum greater than a given value](https://github.com/danrusei/algorithms_with_Go/tree/main/strings/smallest_subarray) |
122 |
| -- [] Stock Buy Sell to Maximize Profit |
123 |
| - |
| 114 | +* [x] [Reverse an array without affecting special characters](https://github.com/danrusei/algorithms_with_Go/tree/main/strings/reverse_alpha) |
| 115 | +* [] All Possible Palindromic Partitions |
| 116 | +* [] Count triplets with sum smaller than a given value |
| 117 | +* [x] [Convert array into Zig-Zag fashion](https://github.com/danrusei/algorithms_with_Go/tree/main/strings/zig_zag) |
| 118 | +* [] Generate all possible sorted arrays from alternate elements of two given sorted arrays |
| 119 | +* [] Pythagorean Triplet in an array |
| 120 | +* [x] [Length of the largest subarray with contiguous elements](https://github.com/danrusei/algorithms_with_Go/tree/main/strings/largest_subarray) |
| 121 | +* [] Find the smallest positive integer value that cannot be represented as sum of any subset of a given array |
| 122 | +* [x] [Smallest subarray with sum greater than a given value](https://github.com/danrusei/algorithms_with_Go/tree/main/strings/smallest_subarray) |
| 123 | +* [] Stock Buy Sell to Maximize Profit |
0 commit comments