/DS-A

A place for my Codefellows code challenges

Primary LanguageJavaMIT LicenseMIT

Data Structures & Algorithms

By: Pablo Rosales

This repository contains challenges relating to Data-Structures & Algorithms. The challenges were written primarily by Code Fellows and this README will serve as a table of contents to the individual challenges and their appropriate README's as well.

Table of Contents

Format:

  • Link to code - Link to docs
  1. reverseArray - Challenge Documentation
  2. arrayShift - Challenge Documentation
  3. arrayBinarySearch - Challenge Documentation
  4. Linked Lists - Challenge Documentation
  5. llInsertions - Challenge Documentation
  6. llKthFromEnd - Challenge Documentation
  7. ll_merge - Challenge Documentation
  8. Stacks & Queues - Challenge Documentation
  9. queueWithStacks - Challenge Documentation
  10. fifo animalShelter - Challenge Documentation
  11. multiBracketValidation - Challenge Documentation
  12. Trees - Challenge Documentation
  13. FizzBuzz - Challenge Documentation
  14. breadthFirstTraversal - Challenge Documentation
  15. getMax (Binary tree) - Challenge Documentation
  16. Graph - Challenge Documentation
  17. Breadth First Graph - Challenge Documentation
  18. Get Edge - Challenge Documentation
  19. Depth First Preorder Traversal - Challenge Documentation
  20. Hashtable - Challenge Documentation
  21. Insertion Sort - Challenge Documentation

401 Code Challenge Documentation

Challenge 1: reverseArray

Approach and Efficiency

Solution


Challenge 2: ArrayShift

Approach and Efficiency

Solution


Challenge 3: arrayBinarySearch

Approach and Efficiency

Solution

---

Challenge 4: Linked Lists

Approach and Efficiency

Solution

image placeholder


Challenge 5: LLInsertions

Approach and Efficiency

Solution

image placeholder


Challenge 6: LLKthFromEnd

Approach and Efficiency

Solution


Challenge 7: LL_merge

Approach and Efficiency

Solution


Challenge 8: Stacks & Queues

Approach and Efficiency

Solution

image placeholder


Challenge 9: queueWithStacks

Approach and Efficiency

Solution

image placeholder


Challenge 10: fifo animalShelter

Approach and Efficiency

Solution


Challenge 11: multiBracketValidation

Approach and Efficiency

Solution

image placeholder


Challenge 12: Trees

Approach and Efficiency

Solution

image placeholder


Challenge 13: FizzBuzz

Approach and Efficiency

Solution

image placeholder


Challenge 14: breadthFirstTraversal

Approach and Efficiency

Solution


Challenge 15: getMax

Approach and Efficiency

Solution

image placeholder


Challenge 16: Graph

Implement your own Graph. The graph should be represented as an adjacency list, and should include the following methods:

  1. AddNode()
    • Adds a new node to the graph
    • Takes in the value of that node
    • Returns the added node
  2. AddEdge()
    • Adds a new edge between two nodes in the graph
    • Include the ability to have a “weight”
    • Takes in the two nodes to be connected by the edge
    • Both nodes should already be in the Graph
  3. GetNodes()
    • Returns all of the nodes in the graph as a collection (set, list, or similar)
  4. GetNeighbors()
    • Returns a collection of nodes connected to the given node
    • Takes in a given node
    • Include the weight of the connection in the returned collection
  5. Size()
    • Returns the total number of nodes in the graph

Approach & Efficiency

Solution

image placeholder


Challenge 17: Breadth First Graph

Extend your graph object with a breadth-first traversal method that accepts a starting node. Without utilizing any of the built-in methods available to your language, return a collection of nodes in the order they were visited. Display the collection.

Approach and Efficiency

Solution

image placeholder


Challenge 18: get edge

Approach and Efficiency

Solution


Challenge 19: Depth first preoder traversal

Approach and Efficiency

Solution


Challenge 20: Hashtable

  • A method/function named add that takes in both the key and value. This method should hash the key and add the key and value pair to the table.
  • A method/function named Find that takes in the key and returns the value from key/value pair.
  • A method/function named contains that takes in the key and returns if the key exists in the table already.
  • A method/function named GetHash that takes in a key and returns the index in the array the key is stored.

Approach and Efficiency

Solution

Lab challenge (needs a whiteboard after class)


Challenge 21: Insertion sort

Sorts an array from left to right iteratively placing each new element into the appropriate index.

Approach and Efficiency

At it’s worst, the array is in the reverse order, giving a runtime of O(n^2), but on average it isn't going to be the worst possible runtime so it will still be O(n^2) with any data set. As for space, all this is doing is sorting the same array in place so it takes the same amount of space or O(1)


Challenge 22: mergeSort

Approach and Efficiency

Solution


Challenge 22: quickSort

Write a function that accepts an array of integers, and returns an array sorted by a recursive quickSort algorithm.

Approach and Efficiency

QuickSort has an efficiency of O(nLogn). This is because we always are dividing our problem until we reach a simple condition (the base case) then we meet that condition and that allows us to solve the next piece up the stack and that can potentially be a worst case scenario, but it most likely won't have t odo 100% of the work every time.

Solution