{"id":31794885,"url":"https://github.com/marvincolgin/data-structures-and-algorithms","last_synced_at":"2025-10-10T19:56:36.125Z","repository":{"id":35111679,"uuid":"195886645","full_name":"marvincolgin/data-structures-and-algorithms","owner":"marvincolgin","description":"Polyglot Data Structures/Algorithms. Collection of classic computer science data-structures: LinkList, Queue/Stack, Binary Tree, Hashmap, Graph and the sorts: bubble, insertion, merge, quicksort. Whiteboarded and originally written in Python, then ported to Java, Node and Golang.","archived":false,"fork":false,"pushed_at":"2022-12-30T18:43:46.000Z","size":38670,"stargazers_count":4,"open_issues_count":15,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-03-02T23:21:51.757Z","etag":null,"topics":["algorithms","binary-search-tree","computer-science","data-structrues","data-structures-algorithms","data-structures-and-algorithms","go","golang","graph-algorithms","graphs","hashtable","java","junit5","linked-list","node","node-js","nodejs","polyglot","python","whiteboards"],"latest_commit_sha":null,"homepage":"http://marvincolgin.com","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marvincolgin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-08T21:11:11.000Z","updated_at":"2022-02-07T15:41:58.000Z","dependencies_parsed_at":"2023-01-15T14:15:19.918Z","dependency_job_id":null,"html_url":"https://github.com/marvincolgin/data-structures-and-algorithms","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"purl":"pkg:github/marvincolgin/data-structures-and-algorithms","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marvincolgin%2Fdata-structures-and-algorithms","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marvincolgin%2Fdata-structures-and-algorithms/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marvincolgin%2Fdata-structures-and-algorithms/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marvincolgin%2Fdata-structures-and-algorithms/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marvincolgin","download_url":"https://codeload.github.com/marvincolgin/data-structures-and-algorithms/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marvincolgin%2Fdata-structures-and-algorithms/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279005036,"owners_count":26083827,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithms","binary-search-tree","computer-science","data-structrues","data-structures-algorithms","data-structures-and-algorithms","go","golang","graph-algorithms","graphs","hashtable","java","junit5","linked-list","node","node-js","nodejs","polyglot","python","whiteboards"],"created_at":"2025-10-10T19:56:35.013Z","updated_at":"2025-10-10T19:56:36.120Z","avatar_url":"https://github.com/marvincolgin.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"**Algorithms and Data Structures**\n\n*Written in Python, Golang, Node and Java*\n\nVin Colgin (Summer/Fall 2019)\n\nhttps://github.com/marvincolgin\n\nhttps://linkedin.com/in/mcolgin\n\n\n\n**Table of Contents:**\n\u003c!--ts--\u003e\n   * [Algorithms](#algorithms)\n      * [Bubble Sort](#bubble-sort)\n      * [Insertion Sort](#insertion-sort)\n      * [Merge Sort](#merge-sort)\n      * [Quick Sort](#quick-sort)\n   * [Data Structures](#data-structures)\n      * [Arrays](#arrays)\n         * [Reverse Elements](#reverse-elements)\n         * [Insert and Shift Array Elements](#insert-and-shift-array-elements)\n         * [Binary Search](#binary-search)\n      * [Singly Linked Lists](#singly-linked-lists)\n      * [Stack (LIFO)](#stack-lifo)\n         * [Balanced Brackets](#balanced-brackets)\n      * [Queue (FIFO)](#queue-fifo)\n         * [Queue: Animal Shelter](#queue-animal-shelter)\n      * [Binary Tree (BT)](#binary-tree-bt)\n         * [Breadth-first Traversal](#breadth-first-traversal)\n         * [Find the Maximum Value](#find-the-maximum-value)\n         * [FizzBuzzTree](#fizzbuzztree)\n         * [Tree Intersection](#tree-intersection)\n      * [Binary Search Tree (BST)](#binary-search-tree-bst)\n      * [Hash Table](#hash-table)\n         * [Repeated Words](#repeated-words)\n         * [Left Join](#left-join)\n      * [Graphs](#graphs)\n         * [Get Graph Edges](#get-graph-edges)\n         * [Depth-First Traversal](#depth-first-traversal)\n\n\u003c!-- Added by: mmc, at: Thu Sep 19 21:35:00 PDT 2019 --\u003e\n\n\u003c!--te--\u003e\n\n# CI/CD\n\nCircleCi for Tests:\n\n[![CircleCI](https://circleci.com/gh/marvincolgin/data-structures-and-algorithms.svg?style=svg)](https://circleci.com/gh/marvincolgin/data-structures-and-algorithms)\n\n\n# Algorithms\n\n\n## Bubble Sort\n\n*Source Code:*\n\n\u003cdetails\u003e\u003csummary\u003ePython\u003c/summary\u003e\n\nSource: [Github](https://github.com/marvincolgin/data-structures-and-algorithms/tree/master/python/algorithms/bubble_sort)\n\n```python\ndef bubble_sort(arr):\n    # BigO == n^2\n```\n\u003c/details\u003e\n\n---\n\n## Insertion Sort\n\n*Source Code:*\n\n\u003cdetails\u003e\u003csummary\u003ePython\u003c/summary\u003e\n\nSource: [Github](https://github.com/marvincolgin/data-structures-and-algorithms/tree/master/python/algorithms/insertion_sort)\n\n```python\ndef insertion_sort(arr):\n    # BigO = O(2n)\n```\n\u003c/details\u003e\n\n---\n\n## Merge Sort\n\n*Source Code:*\n\n\u003cdetails\u003e\u003csummary\u003ePython\u003c/summary\u003e\n\nSource: [Github](https://github.com/marvincolgin/data-structures-and-algorithms/tree/master/python/algorithms/merge_sort)\n\n```python\ndef merge_sort(arr):\n    # BigO (n log n)\n    # :: log n, as this is a divide algo\n    # :: n, as we need to merge the halfs back\n\ndef merge_split(arr):\n    # actual merge_sort function, without error handling\n    # :: recursivily called\n\ndef merge_array(arr, left, right):\n    # combine left and right sides\n```\n\u003c/details\u003e\n\n---\n\n## Quick Sort\n\n*Source Code:*\n\n\u003cdetails\u003e\u003csummary\u003ePython\u003c/summary\u003e\n\nSource: [Github](https://github.com/marvincolgin/data-structures-and-algorithms/tree/master/python/algorithms/quick_sort)\n\n```python\ndef quick_sort(arr):\n    # BigO (n log n)\n    # :: log n, as this is a divide algo\n    # :: n, as we need to merge the halfs back\n```\n\u003c/details\u003e\n\n# Data Structures\n\n## Arrays\nIn Python, arrays are dynamic lists of pointers to memory addresses, Big O Time == 0(1)\n\n### Reverse Elements\nCreate a function, which reverses an array/linked-list, as passed via a parameter and pass the new array back as the `return()` for the function.\n\n*Approach \u0026 Efficiency*\nMy initial approach was to utilize the `list.insert()` and `list.pop()` to rebuild the list in reverse order. However, my white boarding partner showed me a more pythonic method utilizing slices with a -1 stride.\n\n*Solution*\nTwo solutions were used, one that utilizes a while() loop and is destructive on the inbound array. The second is \"pythonic\" and utilizes an index slice and a -1 stride.\n\n\u003cdetails\u003e\u003csummary\u003eWhiteboard\u003c/summary\u003e\n\n![alt_text](https://raw.githubusercontent.com/marvincolgin/data-structures-and-algorithms/master/whiteboards/array-reverse.jpg)\n\u003c/details\u003e\n\n*Source Code:*\n\n\u003cdetails\u003e\u003csummary\u003ePython\u003c/summary\u003e\n\nSource: [Github](https://github.com/marvincolgin/data-structures-and-algorithms/blob/master/python/challenges/array_reverse/array_reverse.py)\n\n```python\ndef reverse_array(orig):\ndef reverse_array2(orig):\n```\n\u003c/details\u003e\n\n---\n\n### Insert and Shift Array Elements\nWrite a function which takes in an array and the value to be added. Without utilizing any of the built-in methods available to your language, return an array with the new value added at the middle index.\n\n*Solution*\nCreate an index into the array where the value will be inserted, utilize slice and .append/.extend to construct a return array\n\n\u003cdetails\u003e\u003csummary\u003eWhiteboard\u003c/summary\u003e\n\n![alt_text](https://raw.githubusercontent.com/marvincolgin/data-structures-and-algorithms/master/whiteboards/array-shift.jpg)\n\u003c/details\u003e\n\n*Source Code:*\n\n\u003cdetails\u003e\u003csummary\u003ePython\u003c/summary\u003e\n\nSource: [Github](https://github.com/marvincolgin/data-structures-and-algorithms/blob/master/python/challenges/array_shift/array_shift.py)\n\n```python\ndef insert_shift_array_sorted(arr, val):\ndef insert_shift_array(arr, val):\n```\n\u003c/details\u003e\n\n---\n\n### Binary Search\nWrite a function which takes in an array and the value to be searched. Return -1 if the value is not found, otherwise return the index (0 based). Incoming array is sorted.\n\n*Solution*\nDivide and Conquer! Look at the middle element, is it the middle element? Return. If not, create a new middle from either the smaller side or larger side. Repeat.\n\n\u003cdetails\u003e\u003csummary\u003eWhiteboard\u003c/summary\u003e\n\n![alt_text](https://raw.githubusercontent.com/marvincolgin/data-structures-and-algorithms/master/whiteboards/array-binary-search.jpg)\n\u003c/details\u003e\n\n*Source Code:*\n\n\u003cdetails\u003e\u003csummary\u003ePython\u003c/summary\u003e\n\nSource: [Github](https://github.com/marvincolgin/data-structures-and-algorithms/blob/master/python/challenges/array_binary_search/array_binary_search.py)\n\n```python\ndef array_binary_search(arr, val):\n```\n\u003c/details\u003e\n\n---\n\n## Singly Linked Lists\nLinked-Lists (singly) are dynamic data-structures which resembles a length of chain, where the entire length of chain is the list and the individual links of the chain are nodes. A singlarly linked list is only traversable in one direction, but utilizing a head element that points to the first node in the list, the second node in the list points to the next link in the chain, and finally the last element in the list points to \"none\"\n\n\u003cdetails\u003e\u003csummary\u003eWhiteboard\u003c/summary\u003e\n\n_*Insert()*_\n![alt_text](https://raw.githubusercontent.com/marvincolgin/data-structures-and-algorithms/master/whiteboards/linked_lists-insertions-whiteboard.jpg)\n\n_*KthFromEnd(): Iterative Approach*_\n![alt_text](https://raw.githubusercontent.com/marvincolgin/data-structures-and-algorithms/master/whiteboards/linked_lists-kth_from_end-whiteboard.jpg)\n\n_*KthFromEnd(): Recursive Approach*_\n![alt_text](https://raw.githubusercontent.com/marvincolgin/data-structures-and-algorithms/master/whiteboards/linked_lists-kth_from_end-whiteboard-recursive.jpg)\n\n_*MergeList()*_\n![alt_text](https://raw.githubusercontent.com/marvincolgin/data-structures-and-algorithms/master/whiteboards/linked_list-merge-whiteboard.jpg)\n\u003c/details\u003e\n\n*Source Code:*\n\n\u003cdetails\u003e\u003csummary\u003ePython\u003c/summary\u003e\n\nSource: [Github](https://github.com/marvincolgin/data-structures-and-algorithms/tree/master/python/datastructs/linked_list)\n\n```python\nclass LinkList()\n\n    def __init__(self):\n        # constructor\n\n    def toJSON(self):\n        # dump object to JSON and return as String\n\n    def insert(self, value):\n        # insert value at the head of the list\n\n    def includes(self, value):\n        # traverse list and determine if a value exists\n        # return bool\n\n    def count(self):\n        # count the number of nodes and return count\n\n    def append(value):\n        # adds a new node with the given value to the end of the list\n        # BigO == O(n)\n\n    def insertBefore(value, newVal):\n        # add a new node with the given newValue immediately before the first value node\n        # BigO == O(n)\n\n    def insertAfter(value, newVal):\n        # add a new node with the given newValue immediately after the first value node\n        # BigO == O(n)\n\nclass ListNode()\n    def __init__(self, value, next=None, prev=None):\n         # constructor\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eGolang\u003c/summary\u003e\n\nSource: [Github](https://github.com/marvincolgin/data-structures-and-algorithms/tree/master/golang/src/linklist)\n\n```golang\ntype LinkNode struct {\n    value interface{}\n\tnext  *LinkNode\n\tprev  *LinkNode\n}\nfunc (node *LinkNode) Init(value interface{}) {\n    head *LinkNode\n\t// @TODO: comparison_func func\n}\n\ntype LinkList struct {\n\thead *LinkNode\n\t// @TODO: comparison_func func\n}\nfunc (list *LinkList) Init() {}\nfunc (list *LinkList) toJSON() string {}\nfunc (list *LinkList) toStr() string {}\nfunc (list *LinkList) Insert(value interface{}) bool {}\nfunc (list *LinkList) Includes(value interface{}) bool {}\nfunc (list *LinkList) Get(value interface{}) interface{} {}\nfunc (list *LinkList) Count() int {}\nfunc (list *LinkList) Append(value interface{}) bool {}\nfunc (list *LinkList) Remove(value interface{}) bool {}\nfunc (list *LinkList) Peek() (bool, interface{}) {}\nfunc (list *LinkList) InsertBefore(targetVal, newVal interface{}, afterInstead bool) bool {}\nfunc (list *LinkList) InsertAfter(targetVal, newVal interface{}) bool {}\nfunc (list *LinkList) KthFromEnd(k int) (bool, interface{}) {}\nfunc (list *LinkList) MergeList(listA, listB LinkList) LinkList {}\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eNode\u003c/summary\u003e\n\nSource: [Github](https://github.com/marvincolgin/data-structures-and-algorithms/tree/master/node/src/linklist)\n\n```javascript\n// LinkNode this is the internal object for individual link-nodes\nclass LinkNode {\n\tconstructor(value) {\n}\n\n// LinkList is the internal data-structure\nclass LinkList {\n\tconstructor() {}\n\n   toStr() {}\n   count() {}\n   peek() {}\n   append(value) {}\n   insert(value) {}\n   includes(value) {}\n   remove(value) {}\n   insertBefore(targetVal, newVal, afterInstead=false)  {}\n   insertAfter(targetVal, newVal) {}\n   kthFromEnd(k) {}\n   mergeList(listA, listB) { }\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eJava\u003c/summary\u003e\n\nSource: [Github](https://github.com/marvincolgin/data-structures-and-algorithms/tree/master/java/src/main/java/datastructs/LinkList.java)\n\n```java\npublic class LinkList {\n\n   public class RetObj {}\n\n   public Node head;\n\n   private BiFunction\u003cString, String, Boolean\u003e comparisonFunc;\n   public void setComparisonFunc(BiFunction f) {}\n\n   public LinkList(BiFunction cf) {}\n\n   class Node {}\n\n   public void insert(String value) {}\n   public int count() {}\n   public Boolean includes(String value) {}\n   public RetObj peek() {}\n   public String toStr() {}\n   public Boolean append(String value) {}\n   public Boolean remove(String value) {}\n   public String get(String value) {}\n   private Boolean insertBeforeOrAfter(String targetVal, String newVal, Boolean afterInstead) {}\n   public Boolean insertBefore(String targetVal, String newVal) {}\n   public Boolean insertAfter(String targetVal, String newVal) {}\n   public void traverse(Consumer actionFunc) {}\n   public String kthFromEnd(int k) {}\n   public LinkList mergeList(LinkList listA, LinkList listB) {}\n}\n```\n\u003c/details\u003e\n\n---\n\n## Stack (LIFO)\n\n*Source Code:*\n\n\u003cdetails\u003e\u003csummary\u003ePython\u003c/summary\u003e\n\nSource: [Github](https://github.com/marvincolgin/data-structures-and-algorithms/tree/master/python/datastructs/stacks_and_queues)\n```python\nclass Stack():\n    def push(val) -\u003e bool:\n    def pop() -\u003e str:\n    def peek() -\u003e str:\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eGolang\u003c/summary\u003e\n\nSource: [Github](https://github.com/marvincolgin/data-structures-and-algorithms/tree/master/golang/src/linklist)\n```golang\ntype Stack struct {\n\t_data linklist.LinkList\n}\nfunc (stack *Stack) Init() {}\nfunc (stack *Stack) Count() int {}\nfunc (stack *Stack) Pop() (bool, interface{}) {}\nfunc (stack *Stack) Push(val interface{}) bool {}\nfunc (stack *Stack) Peek() (bool, interface{}) {}\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eNode\u003c/summary\u003e\n\nSource: [Github](https://github.com/marvincolgin/data-structures-and-algorithms/tree/master/node/src/stack)\n```javascript\n// Stack implementation of LIFO\nclass Stack {\n   constructor() {}\n   count() {}\n   pop() {}\n   push(val) {}\n   peek() {)\n}\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eJava\u003c/summary\u003e\n\nSource: [Github](https://github.com/marvincolgin/data-structures-and-algorithms/tree/master/java/src/main/java/datastructs/Stack.java)\n```java\npublic class Stack {\n   private LinkList _data = null;\n\n   public Stack() {}\n   public int count() {}\n   public Boolean push(String val) {}\n   public String pop() {}\n   public LinkList.RetObj peek() {}\n   public String toStr() {}\n}\n```\n\u003c/details\u003e\n\n---\n\n### Balanced Brackets\nCreate a function, which takes in a string and tests it to make sure that any open brackets ('{','(','[') are balanced with their corresponding closing-brackets ('}',')',']').\n\n\u003cdetails\u003e\u003csummary\u003eWhiteboard\u003c/summary\u003e\n\n![alt_text](https://github.com/marvincolgin/data-structures-and-algorithms/raw/multi_bracket_validation/challenges/multi_bracket_validation/assets/whiteboard.jpg)\n\u003c/details\u003e\n\n*Source Code:*\n\n\u003cdetails\u003e\u003csummary\u003ePython\u003c/summary\u003e\n\nSource: [Github](https://github.com/marvincolgin/data-structures-and-algorithms/tree/master/python/challenges/multi_bracket_validation)\n```python\ndef multi_bracket_validation(input : str) -\u003e boolean:\n```\n\u003c/details\u003e\n\n---\n\n## Queue (FIFO)\n\n\u003cdetails\u003e\u003csummary\u003eWhiteboard\u003c/summary\u003e\n\n![alt_text](https://raw.githubusercontent.com/marvincolgin/data-structures-and-algorithms/1805a3f00421d5f5f4bc5578e9cfc4522d47e9ba/challenges/queue_with_stacks/assets/whiteboard.jpg)\n\u003c/details\u003e\n\n*Source Code:*\n\n\u003cdetails\u003e\u003csummary\u003ePython (queue)\u003c/summary\u003e\n\nSource: [Github](https://github.com/marvincolgin/data-structures-and-algorithms/tree/master/python/datastructs/stacks_and_queues)\n```python\nclass Queue():\n\n    def enqueue(val) -\u003e bool:\n        # Add a value to the queue\n\n    def dequeue(val) -\u003e bool:\n        # Remove entry from queue with a given value\n\n    def peek() -\u003e str:\n        # Get value from the head of the queue (without removing it)\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003ePython (stack)\u003c/summary\u003e\n\nSource: [Github](https://github.com/marvincolgin/data-structures-and-algorithms/tree/master/python/datastructs/stacks_and_queues)\n```python\nclass PseudoQueue(object):\n\n    def __init__(self):\n        # create Stack for internal data-struct\n\n    def count(self):\n        # pass through method to underlying data struct\n        # BigO == O(n)\n\n    def enqueue(self, val: str) -\u003e bool:\n        # enqeue a value at the end queue\n        # BigO == O(1)\n\n    def dequeue(self) -\u003e (str, bool):\n        # dequeue from head of queue\n        # BigO == O(n)\n        # Algo: use a second stack, as we need the bottom element on the first stack\n        # so we are going to unload the first stack, into a temp stack, in order to\n        # get at the bottom element of the first, then rebuild it from temp to first-stack\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eNode\u003c/summary\u003e\n\nSource: [Github](https://github.com/marvincolgin/data-structures-and-algorithms/tree/master/node/src/queue)\n```javascript\nclass Queue {\n   constructor() {}\n   count() {}\n   toStr() {}\n   enqueue(val) {}\n   dequeue(val) {}\n   peek() {}\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eGolang\u003c/summary\u003e\n\nSource: [Github](https://github.com/marvincolgin/data-structures-and-algorithms/tree/master/golang/src/queue)\n```golang\n// Queue implementation of LIFO\ntype Queue struct {\n\t_data linklist.LinkList\n}\n\n// Init inistantiate the stuct\nfunc (queue *Queue) Init() {}\n\n// Count the number of items in linklist\nfunc (queue *Queue) Count() int {}\n\n// ToStr return the Queue as a String\nfunc (queue *Queue) ToStr() string {}\n\n// Enqueue to add a value to the queue\nfunc (queue *Queue) Enqueue(val interface{}) bool {}\n\n// Dequeue to remove a specific value from the Qeueue\nfunc (queue *Queue) Dequeue(val interface{}) bool {}\n\n// Peek at the front value in the Queue\nfunc (queue *Queue) Peek() (bool, interface{}) {}\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eJava\u003c/summary\u003e\n\nSource: [Github](https://github.com/marvincolgin/data-structures-and-algorithms/tree/master/java/src/main/java/datastructs/Queue.java)\n```java\npublic class Queue {\n   private LinkList _data = null;\n\n   public Queue() {}\n   public int count() {}\n   public Boolean enqueue(String val) {}\n   public Boolean dequeue(String val) {}\n   public LinkList.RetObj peek() {}\n   public String toStr() {}\n}\n```\n\u003c/details\u003e\n\n---\n\n### Queue: Animal Shelter\ncreate a class called AnimalShelter which holds only dogs/cats. The shelter operates as first-in / first-out\n\n\u003cdetails\u003e\u003csummary\u003eWhiteboard\u003c/summary\u003e\n\n![alt_text](https://raw.githubusercontent.com/marvincolgin/data-structures-and-algorithms/master/whiteboards/queue-animal_shelter.jpg)\n\u003c/details\u003e\n\n*Source Code:*\n\n\u003cdetails\u003e\u003csummary\u003ePython\u003c/summary\u003e\n\nSource: [Github](https://github.com/marvincolgin/data-structures-and-algorithms/tree/master/python/challenges/fifo_animal_shelter)\n```python\nclass AnimalType(IntEnum):\n\nclass Animal(object):\n\n    def __init__(self, animaltype : AnimalType):\n        # create internal data structs\n\n    def serialize(self):\n        # return json for obj\n\n    def Factory(jsonstr : str): # -\u003e Animal\n        # create Animal class Dog|Cat for Json\n\nclass Cat(Animal):\n    def __init__(self):\n        # create internal data structs\n\nclass Dog(Animal):\n    def __init__(self):\n        # create internal data structs\n\nclass AnimalShelter():\n    def __init__(self):\n        # create internal data structs\n\n    def enqueue(self, animal : Animal):\n        # add animal to shelter\n\n    def dequeue(self, pref : AnimalType=None) -\u003e Animal:\n        # grab animal that has been in queue the longest, optionally provide parameter\n```\n\u003c/details\u003e\n\n---\n\n## Binary Tree (BT)\n\n*Source Code:*\n\n\u003cdetails\u003e\u003csummary\u003ePython\u003c/summary\u003e\n\nSource: [Github](https://github.com/marvincolgin/data-structures-and-algorithms/tree/master/python/datastructs/tree)\n```python\nclass TraverseMethod(IntEnum):\n    # enum class for traversal and processing order\n\nclass Node:\n    # class for nodes within Tree\n\n    def __init__(self, value):\n        # constructor for creating Node\n\nclass BinaryTree:\n\n    def __init__(self):\n        # constructor for creating BinaryTree\n\n    def traverse(self, method : TraverseMethod, action_func):\n        # visit each node in atree, using a specified method and call action_func() for each node\n\n        def _visit(node):\n            # recusive function for visiting each node\n\n    def returnAsArr(self, method : TraverseMethod):\n        # return the enter tree as an array using a specified method\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eNode\u003c/summary\u003e\n\nSource: [Github](https://github.com/marvincolgin/data-structures-and-algorithms/tree/master/node/src/tree)\n```javascript\n// enum class for traversal and processing order\nvar TraverseMethod = {\n   PRE_ORDER: 1,\n   IN_ORDER: 2,\n   POST_ORDER: 3\n}\n\n// enum class for comparisons, gt, lt and equal\nvar ComparisonSign = {\n    LESS: 1,\n    GREATER: 2,\n    EQUAL: 3\n}\n\n// class for nodes within Tree\nclass Node {\n   constructor(value) {\n      this.value = value\n      this.left = null\n      this.right = null\n   }\n}\n\n// BinaryTree Implementation\nclass BinaryTree {\n   constructor() {}\n   traverse(method, action_func) { }\n   returnAsArr(method) {}\n}\n\nclass BinarySearchTree extends BinaryTree {\n   constructor(comparison_func=null) { }\n   comparison_func_default(val1, val2, CS) {}\n   add(new_value) {}\n   contains(target_value) {}\n}\n```\n\u003c/details\u003e\n\n---\n\n### Breadth-first Traversal\nBreadth first traversal method which takes a Binary Tree as its unique input.\n\n\u003cdetails\u003e\u003csummary\u003eWhiteboard\u003c/summary\u003e\n\n![alt_text](https://raw.githubusercontent.com/marvincolgin/data-structures-and-algorithms/master/whiteboards/binary_tree-breadth_first.jpg)\n\u003c/details\u003e\n\n*Source Code:*\n\n\u003cdetails\u003e\u003csummary\u003ePython\u003c/summary\u003e\n\nSource: [Github](https://github.com/marvincolgin/data-structures-and-algorithms/tree/master/python/datastructs/tree)\n```python\ndef breadth_first(tree, action_func):\n```\n\u003c/details\u003e\n\n---\n\n### Find the Maximum Value\nFunction called find_maximum_value which takes binary tree as its only input\n\n\u003cdetails\u003e\u003csummary\u003eWhiteboard\u003c/summary\u003e\n\n![alt_text](https://raw.githubusercontent.com/marvincolgin/data-structures-and-algorithms/master/whiteboards/binary_tree-find_max_value.jpg)\n\u003c/details\u003e\n\n*Source Code:*\n\n\u003cdetails\u003e\u003csummary\u003ePython\u003c/summary\u003e\n\nSource: [Github](https://github.com/marvincolgin/data-structures-and-algorithms/tree/master/python/challenges/find_maximum_binary_tree)\n```python\ndef find_max(tree : BinaryTree) -\u003e (bool,int):\n```\n\u003c/details\u003e\n\n---\n\n### FizzBuzzTree\nWrite a function called FizzBuzzTree which takes a tree as an argument.\nDetermine weather or not the value of each node is divisible by 3, 5 or both, and change the value of each of the nodes:\n- [x] value is divisible by 3, replace the value with \"Fizz\"\n- [x] value is divisible by 5, replace the value with \"Buzz\"\n- [x] value is divisible by 3 and 5, replace the value with \"FizzBuzz\"\n- [x] Return the tree with its new values.\n\n\u003cdetails\u003e\u003csummary\u003eWhiteboard\u003c/summary\u003e\n\n![alt_text](https://raw.githubusercontent.com/marvincolgin/data-structures-and-algorithms/master/whiteboards/binary_tree-fizzbuzz.jpg)\n\u003c/details\u003e\n\n*Source Code:*\n\n\u003cdetails\u003e\u003csummary\u003ePython\u003c/summary\u003e\n\nSource: [Github](https://github.com/marvincolgin/data-structures-and-algorithms/tree/master/python/challenges/fizz_buzz_tree)\n```python\ndef fizzBuzzTree(tree: BinaryTree) -\u003e BinaryTree:\n    # traverse tree, value = value%3==0 ? 'Fizz, value = value%5==0 ? 'Buzz' (set value to 'FizzBuzz' if both conditions met)\n```\n\u003c/details\u003e\n\n---\n\n### Tree Intersection\ntree_intersection(): given two binary-trees, return an array containing shared values\n\n\u003cdetails\u003e\u003csummary\u003eWhiteboard\u003c/summary\u003e\n\n![alt_text](https://raw.githubusercontent.com/marvincolgin/data-structures-and-algorithms/master/whiteboards/binary_tree-find_insection_with_two_trees.jpg)\n\u003c/details\u003e\n\n*Source Code:*\n\n\u003cdetails\u003e\u003csummary\u003ePython\u003c/summary\u003e\n\nSource: [Github](https://github.com/marvincolgin/data-structures-and-algorithms/tree/master/python/challenges/tree_intersection)\n```python\ndef tree_intersection(tree1, tree2: BinaryTree) -\u003e list:\n    # return an array with all the values in both tree1 and tree2\n    # BigO Time==O(2n)  Space==0(1.3n) 30% for hashtable\n    # assumption: No Duplicates within Trees\n```\n\u003c/details\u003e\n\n---\n\n## Binary Search Tree (BST)\n\n*Source Code:*\n\n\u003cdetails\u003e\u003csummary\u003ePython\u003c/summary\u003e\n\nSource: [Github](https://github.com/marvincolgin/data-structures-and-algorithms/tree/master/python/datastructs/tree)\n```python\nclass BinarySearchTree(BinaryTree):\n    # class for binary-search-tree\n\n    def add(self, new_value):\n        # adds new value to the tree\n\n        def _find_and_insert(node):\n            # recursive method for evaluating a node and calling itself depending on the value\n\n    def contains(self, target_value) -\u003e bool:\n        # accepts a value, and returns a boolean indicating whether or not the value is in the tree at least once.\n\n        def _visit(node):\n            # recursive function for isiting each node\n```\n\u003c/details\u003e\n\n---\n\n##  Hash Table\n\n*Source Code:*\n\n\u003cdetails\u003e\u003csummary\u003ePython\u003c/summary\u003e\n\nSource: [Github](https://github.com/marvincolgin/data-structures-and-algorithms/tree/master/python/datastructs/hashtable)\n```python\nclass HashTable():\n\n    def __init__(self, hashtableSize = 1024):\n        # create with hashTableSize\n\n    def _makePayload(self, name, value):\n        # return dict of name/value pair\n\n    def _makeHash(self, name) -\u003e int:\n        # create a hash based on the name to be added to hashtable\n        # this is a silly hash, as it's just for experiment and\n        # gives us the ability to easily create collisions. Live\n        # code should use something more sophisticated\n\n    def _getHashIndex(self, hash: int) -\u003e int:\n        # get the index into the hash-table for a given hash value\n\n    def _hashtable_compare_func(self, payload1, payload2) -\u003e bool:\n        # func passed to LinkList compare\n\n    def add(self, name, value):\n        # accepts name/value pair and adds them to the hashtable\n        # if there are collisions, then they will be handled\n        # by using a linked-list\n\n    def get(self, name):\n        # returns value in hashtable for a given name\n        # if the value is not found, and exception will be raised\n\n    def contains(self, name) -\u003e bool:\n        # returns true|false if the name is in the hashtable\n```\n\u003c/details\u003e\n\n---\n\n### Repeated Words\nrepeated_words(): search the longstr for complete words, return the first word that has more than one occurrence\n\n\u003cdetails\u003e\u003csummary\u003eWhiteboard\u003c/summary\u003e\n\n![alt_text](https://raw.githubusercontent.com/marvincolgin/data-structures-and-algorithms/master/whiteboards/hashtable-repeated_word.jpg)\n\u003c/details\u003e\n\n*Source Code:*\n\n\u003cdetails\u003e\u003csummary\u003ePython\u003c/summary\u003e\n\nSource: [Github](https://github.com/marvincolgin/data-structures-and-algorithms/tree/master/python/challenges/repeated_word)\n```python\ndef repeated_word(longstr: str) -\u003e str:\n    # search the longstr for complete words\n    # return the first word that has more than\n    # one occurrence\n    # BigO Time==O(n) Space==O(n*1.3)\n```\n\u003c/details\u003e\n\n---\n\n### Left Join\nleft_join(): given two hash-tables, return a list of all items from the first h1 and the value that exists in h2, if no value exists return None\n- [x] LEFT JOINs two hashmaps into a single data structure.\n- [x] 1st param is hashmap with words and synonyms\n- [x] 2nd param is hashmap with words and antonyms\n- [x] Combine the key and corresponding values (if they exist) into a new data structure according to LEFT JOIN logic.\n- [X] Code Styling: PEP8\n\n\u003cdetails\u003e\u003csummary\u003eWhiteboard\u003c/summary\u003e\n\n![alt_text](https://raw.githubusercontent.com/marvincolgin/data-structures-and-algorithms/master/whiteboards/hashtable-left_join.jpg)\n\u003c/details\u003e\n\n*Source Code:*\n\n\u003cdetails\u003e\u003csummary\u003ePython\u003c/summary\u003e\n\nSource: [Github](https://github.com/marvincolgin/data-structures-and-algorithms/tree/master/python/challenges/left_join)\n```python\ndef left_join(h1, h2: HashTable) -\u003e list:\n    # perform a left-join on h1 against h2\n    # - returns a list of dict:{word,syntonym,antonym)\n    # - BigO time==O(n) space==0(n)\n    # -      worst: time==O(3n)\n```\n\u003c/details\u003e\n\n---\n\n## Graphs\n\n*Source Code:*\n\n\u003cdetails\u003e\u003csummary\u003ePython\u003c/summary\u003e\n\nSource: [Github](https://github.com/marvincolgin/data-structures-and-algorithms/tree/master/python/datastructs/graph)\n```python\nclass Vertex:\n    def __init__(self, value: Any):\n\nclass Edge:\n    def __init__(self, vertex: Vertex, weight=0):\n\nclass Graph:\n    def __init__(self):\n    def __len__(self) -\u003e int:\n    def add_vertex(self, value) -\u003e Vertex:\n    def add_edge(self, vert1: Vertex, vert2: Vertex, weight=0.0):\n    def get_neighbors(self, vertex: Vertex) -\u003e List[Edge]:\n    def get_vertexes(self) -\u003e Optional[List[Vertex]]:\n    def breadth_first(self, root, action_func):\n```\n\u003c/details\u003e\n\n---\n\n### Get Graph Edges\nOverall: Identify if a given path exists through the Graph where path is a given list of values\nUse Case: Given a complete Graph data-structure, containing a variety of Vertexes/Edges containing city-names and costs, (Flight Routes) and a list of cities (Flight Plan), return True|False if the flight-plan can be performed and the cost.\n\n\u003cdetails\u003e\u003csummary\u003eWhiteboard\u003c/summary\u003e\n\n![alt_text](https://raw.githubusercontent.com/marvincolgin/data-structures-and-algorithms/master/whiteboards/graph-get_edges.jpg)\n\u003c/details\u003e\n\n*Source Code:*\n\n\u003cdetails\u003e\u003csummary\u003ePython\u003c/summary\u003e\n\nSource: [Github](https://github.com/marvincolgin/data-structures-and-algorithms/tree/master/python/challenges/get_edges)\n```python\ndef get_edges(graph: Graph, path_ro: List) -\u003e Tuple[bool, float]:\n    # identify if a given path exists through the Graph\n    # where path is a given list of values\n    # @path_ro will be treated as read-only\n    # BigO time==O(V+P*E) .. where p is len(path_ro)\n    # BigO space==O(1)\n```\n\u003c/details\u003e\n\n---\n\n### Depth-First Traversal\n- [x] breadth first traversal method which takes a Binary Tree as its unique input.\n- [x] print every node encountered\n\n\u003cdetails\u003e\u003csummary\u003eWhiteboard\u003c/summary\u003e\n\n![alt_text](https://raw.githubusercontent.com/marvincolgin/data-structures-and-algorithms/master/whiteboards/graph-breadthfirst.jpg)\n\u003c/details\u003e\n\n*Source Code:*\n\n\u003cdetails\u003e\u003csummary\u003ePython\u003c/summary\u003e\n\nSource: [Github](https://github.com/marvincolgin/data-structures-and-algorithms/blob/master/python/datastructs/graph/graph.py#L93)\n```python\ndef depth_first_recursive(self, root: Vertex, action_func: Any) -\u003e None:\ndef depth_first(self, root: Vertex, action_func: Any) -\u003e None:\n```\n\u003c/details\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarvincolgin%2Fdata-structures-and-algorithms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarvincolgin%2Fdata-structures-and-algorithms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarvincolgin%2Fdata-structures-and-algorithms/lists"}