Nord001 / data-structures-algorithms

Implementations of data structures and algorithms in GoLang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Data Structures and Algorithms

Data Structures and Algorithms (DSA) is one of the most important topic in computer science that every CS student must be proficient in and even non-CS students must have basic understanding of it. It is said that DSA is like bread and butter, necessity of CS. This repository is made for those students (like me 😎) who are eager to learn and want to implement data structures and algorithms.

Why Go/GoLang and not C, C++ or Java?

I wouldn't disagree that C, C++ or Java wouldn't be a great language to implement DSA as one has to take care of lot things while writing the code like memory allocations and proper deallocations and by doing so one learns a lot.

However the reason why go would also be a good language to implement DSA is that it lacks a lot of magic. There is no operator overloading, so no way to hide extra complexity. An index operation is O(1), a loop is O(n) - always. There are no generics, so a lot of extra abstractions and helpers don't exist, which is actually pretty great. There is no laziness or other compiler-driven magic that might alter the runtime of your algorithms significantly. And Go has pointer and low-level primitives for slices, meaning it is apparent when data is packed or when data has an extra indirection. In short: Go make the actual algorithmic execution obvious from the code, which is a good thing to learn algorithms.

Conclusion: Go would also be a good language to get started with implementing Data Structures and Algorithms. πŸ’»

Instructions

  1. To get started make sure that you have go programming language installed on your computer. Follow how to install instructions from golang download instructions.
  2. Once go is installed on your machine, just clone or download this repository.
  3. Now cd <folder-name> into the folder where the file you want to run is located.
  4. Now run go run ..

Example

Let's assume that you want to run files located in graphs/directed_unweighted directory then the syntax to run it would be:

cd graphs/directed_unweighted/

go run .

FOLDER NAMES

  1. algorithms -
    • 01knapsack_dp - 0-1 Knapsack Problem using Dynamic Programming
    • a_star -
      • 8_puzzle - 8 Puzzle problem using A* Algorithm
      • directed_graph - A*  Algorithm for directed graph
      • undirected_graph - A*  Algorithm for undirected graph
    • activity_selection_gp - Activity Selection using Greedy Programming
    • assembly_line_scheduling - Assembly Line Scheduling algorithm using Dynamic Programming
    • binary_reflected_gray_codes - Binary Reflected Gray Codes
    • closest_pair_problem -
      • cpp_brute_force - Closest Pair Problem using Brute Force Technique
      • cpp_divide_conquer - Closest Pair Problem using Divide and Conquer Techinque
    • combinations -
      • with_r - With repetition of elements
      • without_r - Without repetition of elements
    • convex_hull -
      • ch_brute_force - Convex Hull Algorithm using Brute Force Technique
      • ch_divide_conquer - Convex Hull Algorithm using Divide and Conquer Technique
    • expression_conversions -
      • infix_postfix - Infix to Postfix Conversion
      • infix_prefix - Infix to Prefix Conversion
      • postfix_infix - Postfix to Infix Conversion
      • postfix_prefix - Postfix to Prefix Conversion
      • prefix_infix - Prefix to Infix Conversion
      • prefix_postfix - Prefix to Postfix Conversion
    • gcd - Greatest Common Divisor (Euclid's Algorithm)
    • graphs -
      • articulation_point_detection - Detecting Articulation Points in an undirected graph
      • bellman_ford - Bellman Ford Algorithm
      • bridge_detection - Bridge Detection/Cut Edge Detection in an undirected graph
      • dijkstra - Dijkstra's Algorithm
      • floyd_warshall - Floyd Warshall Algorithm (All points shortest path)
      • kruskals - Kruskal's Algorithm (Finding Minimum Spanning Tree MST using Greedy Approach)
      • prims - Prim's Algorithm (Finding Minimum Spanning Tree MST using Greedy Approach)
      • topological_sort - Topological Sort
      • traversals -
        • cd_directed_graph_traversals - Cycle Detection in Directed Graphs using Traversals techniques
        • cd_undirected_graph_traversals - Cycle Detection in Undirected Graphs using Traversals techniques
      • tsp -
        • tsp_dynamic -
          1. directed_graph - TSP (Travelling Salesman Problem) using Dynamic approach for directed graph
          2. undirected_graph - TSP (Travelling Salesman Problem) using Dynamic approach for undirected graph
        • tsp_naive -
          1. directed_graph - TSP (Travelling Salesman Problem) using Naive approach for directed graph
          2. undirected_graph - TSP (Travelling Salesman Problem) using Naive approach for undirected graph
      • union_find - Union Find / Disjoint Sets (Detecting cycles in an undirected graph)
    • huffman_codes - Huffman Codes (Generating Huffman Codes)
    • job_scheduling_gp - Job Scheduling Algorithm using Greedy Programming
    • lcm - Least Common Multiple (using GCD Euclid's Algorithm)
    • lcs - Longest Common Subsequence
      • iterative_dp - Longest Common Subsequence using Dynamic Programming (Iterative Version)
    • lo_permutations - Lexicographic Ordering Permutations
    • longest_palindrome_substring -
      • brute_force - Longest Palindrome Substring using Brute Force Technique
      • manchers - Longest Palindrome Substring using Mancher's Algorithm
    • making_change_dp - Making Change Problem using Dynamic Programming
    • order_statistics - Finding Kth Smallest/Largest element (Order Statistics)
      • naive_approach - Naive Approach using Max Heap - O(k + (n-k)*log(k))
      • quick_select - Quick Select (Quick Sort) - O(n^2), Θ(nlogn)
      • worst_case_linear_time - Worst Case Linear Time Order Statistics - O(n)
    • power_set - Power Set (Set of Subsets)
    • searching -
      • binary_search - Binary Search - O(log n)
      • interpolation_search - Interpolation Search - O(n)
      • linear_search - Linear Search - O(n)
      • ternary_search - Ternary Search - O(log3n)
    • sieve_of_eratosthenes - Sieve of Eratosthenes (Consecutive primes not exceeding n)
    • sorting -
      • binary_insertion_sort - Binary Insertion Sort - O(n2)
      • bubble_sort - Bubble Sort - O(n2)
      • bucket_sort - Bucket Sort - O(n2)
      • counting_sort - Counting Sort - O(n + k)
      • heap_sort - Heap Sort - O(nlog(n)
      • insertion_sort - Insertion Sort - O(n2)
      • merge_sort - Merge Sort - O(nlog(n))
      • quick_sort - Quick Sort - Θ(nlog(n))
      • radix_sort - Radix Sort - O(n+k)
      • selection_sort - Selection Sort - (O(n2))
      • shell_sort - Shell Sort - О(n)
    • string_matching -
      • boyer_moore - Boyer Moore Algorithm
      • horspool - Boyer Moore Horspool Algorithm
      • knuth_morris_pratt - Knuth Morris Pratt
      • naive_pattern_matching - Naive Pattern Matching
      • rabin_karp - Rabin Karp
    • toh - Tower of Hanoi
  2. graphs -
    • directed_unweighted - Directed Unweighted graph
    • directed_weighted - Directed Weighted graph
    • undirected_unweighted - Undirected Unweighted graph
    • undirected_weighted - Undirected Weighted graph
  3. heaps -
    • max_binary_heap - Max Binary Heap
    • min_binary_heap - Min Binary Heap
  4. linked_lists -
    • circular_doubly_ll - Circular Doubly Linked List
    • circular_ll - Circular Linked List
    • doubly_ll - Doubly Linked List
    • pres_rev_single_ll - Preserve order during insertion on Single Linked List and Reversing Single Linked List
    • single_ll - Single Linked List
  5. queues -
    • cdqueue - Circular Double ended Queue
    • cqueue - Circular Queue
    • dqueue - Double ended Queue
    • priority_queue - Priority Queue with the use of Min Heap
    • simple_queue - Simple Queue
  6. stack - stack
  7. trees -
    • avl_tree_using_ll - AVL Tree using linked list with BFS and DFS (Pre, In, Post) order traversals.
    • bst_using_arr - Binary Search Tree using array with BFS and DFS (Pre, In, Post) order traversals.
    • bst_using_ll - Binary Search Tree using linked list with BFS and DFS (Pre, In, Post) order traversals.
    • simple_bt_using_arr - Simple Binary Tree using array with BFS and DFS (Pre, In, Post) order traversals.
    • simple_bt_using_ll - Simple Binary Tree using linked list with BFS and DFS (Pre, In, Post) order traversals.

Note: The pointer  " :point_left: "  indicates incomplete implementation and is in todo list.

Contribution

This repository is for learning how to implement data structures and algorithms, and since contributions of others won't really teach me how to implement it by myself, I won't be accepting any pull requests. However, feel free to fork this repo and modify the code to play around various data structures and algorithms. Moreover, while playing around the code, if you find anything unusual or wrong in the implemetation, I would highly appreciate if you create an issue on the same.

License

This repository is released under the MIT license. In short, this means you are free to use this software in any personal, open-source or commercial projects. Attribution is optional but appreciated.

HAPPY CODING πŸ’»
HAPPY LEARNING πŸ“š

About

Implementations of data structures and algorithms in GoLang

License:MIT License


Languages

Language:Go 100.0%