├── .gitignore ├── .gitmodules ├── .travis.yml ├── 99-recurrences.pdf ├── AlgorithmMuseum.html ├── AllPairsShortestPaths.html ├── AmortizedAnalysis.html ├── ApproximationAlgorithms.html ├── AugmentingDataStructures.html ├── BTrees.html ├── BinarySearchTrees.html ├── C++ ├── AllPairsShortestPaths │ └── README ├── AmortizedAnalysis │ └── README ├── ApproximationAlgorithms │ └── README ├── AugmentingDataStructures │ └── README ├── BTrees │ └── README ├── BinarySearchTrees │ └── README ├── ComputationalGeometry │ └── README ├── DataStructuresForDisjointSets │ └── README ├── DivideAndConquer │ ├── DivideAndConquer │ │ ├── find_maximum_subarray_test.cpp │ │ └── strassen_matrix_nultiplation_test.cpp │ ├── FindMaximumArray │ │ └── maximum_array.h │ └── StrassenMatrixMultiplication │ │ └── Matrix.h ├── DynamicProgramming │ ├── DynamicProgrammingTest │ │ ├── LCS_test.cpp │ │ ├── matrix_chain_test.cpp │ │ ├── optimal_binary_tree_test.cpp │ │ └── rob_cutting_test.cpp │ ├── LongestCommonSubsequence │ │ └── LCS.h │ ├── MatrixChainning │ │ └── Matrix_Chain.h │ ├── OptimalBinaryTree │ │ └── Optimal_BST.h │ └── RodCutting │ │ └── Rod_cutting.h ├── ElementaryDataStructures │ ├── README │ ├── clinkedlist.h │ ├── cqueue.h │ ├── cstack.h │ ├── linkedList.h │ ├── main.cpp │ ├── queue.h │ ├── queues.h │ └── stacks.h ├── FibonacciHeaps │ └── README ├── GettingStarted │ ├── bubble_sort.h │ ├── insertion_sort.h │ ├── merge_sort.h │ └── sort_test.cpp ├── Graph │ ├── Graph.cpp │ ├── Graph.hpp │ └── test.cpp ├── GraphAlgorithms │ └── README ├── GreedyAlgorithms │ └── README ├── GrowthOfFunctions │ └── README ├── Hanoi │ ├── Hanoi.cpp │ └── Hanoi.h ├── HashTables │ ├── README │ └── hash_tables.cpp ├── Heapsort │ ├── Heapsort.h │ ├── heapsort_main.cpp │ ├── priority_queue.h │ └── priorityqueue_main.cpp ├── LinearProgramming │ └── README ├── MatrixOperations │ └── README ├── MaximumFlow │ └── README ├── MediansAndOrderStatistics │ ├── README │ └── random_select.cpp ├── MinimumSpanningTrees │ └── README ├── MultithreadedAlgorithms │ ├── README │ ├── fibonacci.h │ ├── matrix.h │ └── test.cpp ├── NPCompleteness │ └── README ├── NumberTheoreticAlgorithms │ └── README ├── PolynomialsAndTheFFT │ └── README ├── Quicksort │ ├── Quicksort.h │ └── QuicksortTest.cpp ├── README.md ├── RandomizedAlgorithms │ ├── hiring_problem.h │ ├── randomized_algorithms.h │ └── test.cpp ├── RedBlackTrees │ └── README ├── SingleSourceShortestPaths │ └── README ├── SortingInLinearTime │ ├── bucket_sort.h │ ├── counting_sort.h │ ├── radix_sort.h │ └── test.cpp ├── StringMatching │ └── README ├── TheRoleOfAlgorithms │ └── README ├── suffixTree │ └── suffixTree.h ├── tests.sh └── vanEmdeBoasTrees │ └── README ├── Clojure ├── AllPairsShortestPaths │ └── README ├── AmortizedAnalysis │ └── README ├── ApproximationAlgorithms │ └── README ├── AugmentingDataStructures │ └── README ├── BTrees │ └── README ├── BinarySearchTrees │ └── README ├── ComputationalGeometry │ └── README ├── DataStructuresForDisjointSets │ └── README ├── DivideAndConquer │ └── README ├── DynamicProgramming │ ├── README │ ├── dynamic_programming.clj │ └── fibonacci.clj ├── ElementaryDataStructures │ └── README ├── FibonacciHeaps │ └── README ├── GettingStarted │ ├── README │ └── getting_started.clj ├── GraphAlgorithms │ └── README ├── GreedyAlgorithms │ └── README ├── GrowthOfFunctions │ └── README ├── HashTables │ └── README ├── Heapsort │ └── README ├── LinearProgramming │ └── README ├── MatrixOperations │ └── README ├── MaximumFlow │ └── README ├── MediansAndOrderStatistics │ └── README ├── MinimumSpanningTrees │ └── README ├── MultithreadedAlgorithms │ └── README ├── NPCompleteness │ └── README ├── NumberTheoreticAlgorithms │ └── README ├── PolynomialsAndTheFFT │ └── README ├── Quicksort │ └── README ├── RandomizedAlgorithms │ └── README ├── RedBlackTrees │ └── README ├── SingleSourceShortestPaths │ └── README ├── SortingInLinearTime │ └── README ├── StringMatching │ └── README ├── TheRoleOfAlgorithms │ └── README ├── tests.sh └── vanEmdeBoasTrees │ └── README ├── CodingStandards.html ├── ComputationalGeometry.html ├── DPVideo.html ├── DataStructuresForDisjointSets.html ├── DivideAndConquer.html ├── DynamicProgramming.html ├── ElementaryDataStructures.html ├── FibonacciHeaps.html ├── Gemfile ├── GettingStarted.html ├── Go ├── AllPairsShortestPaths │ └── README ├── AmortizedAnalysis │ └── README ├── ApproximationAlgorithms │ └── README ├── AugmentingDataStructures │ └── README ├── BTrees │ └── README ├── BinarySearchTrees │ └── README ├── ComputationalGeometry │ └── README ├── DataStructuresForDisjointSets │ └── README ├── DivideAndConquer │ └── README ├── DynamicProgramming │ └── README ├── ElementaryDataStructures │ └── README ├── FibonacciHeaps │ └── README ├── GettingStarted │ └── sort.go ├── GraphAlgorithms │ └── README ├── GreedyAlgorithms │ └── greedy.go ├── GrowthOfFunctions │ └── README ├── HashTables │ └── README ├── Heapsort │ └── README ├── LinearProgramming │ └── README ├── MatrixOperations │ └── README ├── MaximumFlow │ └── README ├── MediansAndOrderStatistics │ └── README ├── MinimumSpanningTrees │ └── README ├── MultithreadedAlgorithms │ └── README ├── NPCompleteness │ └── README ├── NumberTheoreticAlgorithms │ └── README ├── PolynomialsAndTheFFT │ └── README ├── Quicksort │ └── quicksort.go ├── READMe.md ├── RandomizedAlgorithms │ └── README ├── RedBlackTrees │ └── README ├── SingleSourceShortestPaths │ └── README ├── SortingInLinearTime │ └── README ├── StringMatching │ └── README ├── TheRoleOfAlgorithms │ └── README ├── makefile ├── tests.sh └── vanEmdeBoasTrees │ └── README ├── GraphAlgorithms.html ├── GreedyAlgorithms.html ├── GreedyVsDynamic ├── biblio.html └── index.html ├── GrowthOfFunctions.html ├── HashTables.html ├── Heapsort.html ├── Homework ├── Fall2016 │ ├── Homework2.html │ └── Homework3.html └── Fall2017 │ ├── AlgGraphs.pdf │ ├── AlgHW2F2017.txt │ ├── AlgHW3F2017.txt │ ├── Homework1.pdf │ ├── Homework2.pdf │ ├── Homework3.html │ ├── Homework4.pdf │ ├── images │ ├── image1.jpg │ └── image2.png │ └── index.html ├── Java ├── AllPairsShortestPaths │ └── README ├── AmortizedAnalysis │ └── README ├── ApproximationAlgorithms │ └── README ├── AugmentingDataStructures │ └── README ├── BTrees │ └── README ├── BinarySearchTrees │ ├── BinarySearchTree.java │ ├── Node.java │ ├── Tree.java │ └── TreePrinter.java ├── ComputationalGeometry │ └── README ├── DataStructuresForDisjointSets │ └── README ├── DivideAndConquer │ ├── FindMaximumSubarray.java │ ├── FindMaximumSubarrayTest.java │ ├── FindMaximumSubarrayTest.sh │ └── matrixMult.java ├── DynamicProgramming │ ├── LongestCommonSubsequence.java │ ├── MatrixChainMultiplication.java │ ├── OptimalBinarySearchTrees.java │ └── RodCutting.java ├── ElementaryDataStructures │ ├── LinkedList │ │ ├── LinkedList.java │ │ └── Node.java │ ├── Main.java │ ├── Queue.java │ ├── README │ └── Stack.java ├── FibonacciHeaps │ └── README ├── GettingStarted │ ├── InsertionSort.java │ └── MergeSort.java ├── GraphAlgorithms │ ├── AdjacencyList.java │ ├── BreadthFirstSearch.java │ ├── Color.java │ ├── DepthFirstSearch.java │ ├── Graph.java │ ├── TopologicalSort.java │ └── Vertex.java ├── GreedyAlgorithms │ └── ActivitySelection.java ├── GrowthOfFunctions │ └── README ├── HashTables │ ├── DirectAddressTable.java │ ├── HashMap.java │ ├── HashMapImplementation.java │ ├── Node.java │ └── OpenAddressing │ │ ├── DoubleHashing.java │ │ ├── LinearProbing.java │ │ ├── OpenAddressing.java │ │ ├── OpenAddressingMain.java │ │ └── QuadraticProbing.java ├── Heapsort │ ├── Heap.java │ ├── MaxHeap.java │ ├── MaxPriorityQueue.java │ ├── MinHeap.java │ ├── MinPriorityQueue.java │ └── test │ │ ├── MaxHeapTest.java │ │ ├── MinHeapTest.java │ │ └── Test.sh ├── LinearProgramming │ └── README ├── MatrixOperations │ └── README ├── MaximumFlow │ └── README ├── MediansAndOrderStatistics │ └── README ├── MinimumSpanningTrees │ └── README ├── MultithreadedAlgorithms │ ├── Fibonacci.java │ ├── MatrixMultiplication.java │ ├── MultithreadedAlgorithms.java │ ├── README │ ├── RaceCondition.java │ └── tests │ │ ├── FibonacciTest.java │ │ └── MatrixMultiplicationTest.java ├── NPCompleteness │ └── README ├── NumberTheoreticAlgorithms │ └── README ├── PolynomialsAndTheFFT │ └── README ├── Quicksort │ ├── Quicksort.java │ └── README ├── RandomizedAlgorithms │ └── HiringProblem.java ├── RedBlackTree.java ├── RedBlackTrees │ ├── README.md │ ├── RedBlackTree.java │ └── com │ │ └── tree │ │ └── Node.java ├── SingleSourceShortestPaths │ └── README ├── SortingInLinearTime │ ├── BucketSort.java │ ├── CountingSort.java │ ├── README │ └── RadixSort.java ├── StringMatching │ └── README ├── TheRoleOfAlgorithms │ └── README ├── test │ ├── hamcrest-core-1.3.jar │ └── junit-4.12.jar ├── tests.sh └── vanEmdeBoasTrees │ └── README ├── Javascript ├── AllPairsShortestPaths │ └── README ├── AmortizedAnalysis │ └── README ├── ApproximationAlgorithms │ └── README ├── AugmentingDataStructures │ └── README ├── BTrees │ └── README ├── BinarySearchTrees │ └── README ├── ComputationalGeometry │ └── README ├── DataStructuresForDisjointSets │ └── README ├── DivideAndConquer │ └── README ├── DynamicProgramming │ └── README ├── ElementaryDataStructures │ └── README ├── FibonacciHeaps │ └── README ├── GettingStarted │ └── README ├── GraphAlgorithms │ └── README ├── GreedyAlgorithms │ └── README ├── GrowthOfFunctions │ └── README ├── HashTables │ └── README ├── Heapsort │ └── README ├── LinearProgramming │ └── README ├── MatrixOperations │ └── README ├── MaximumFlow │ └── README ├── MediansAndOrderStatistics │ └── README ├── MinimumSpanningTrees │ └── README ├── MultithreadedAlgorithms │ └── README ├── NPCompleteness │ └── README ├── NumberTheoreticAlgorithms │ └── README ├── PolynomialsAndTheFFT │ └── README ├── Quicksort │ └── README ├── RandomizedAlgorithms │ └── README ├── RedBlackTrees │ └── README ├── SingleSourceShortestPaths │ └── README ├── SortingInLinearTime │ └── README ├── StringMatching │ └── README ├── TheRoleOfAlgorithms │ └── README ├── binary_tree.js ├── divideAndConquer.js ├── fibonacci.js ├── heap.js ├── sorting.js ├── tests.sh └── vanEmdeBoasTrees │ └── README ├── LinearProgramming.html ├── MatrixOperations.html ├── MaximumFlow.html ├── MediansAndOrderStatistics.html ├── MidTermLessons.html ├── MinimumSpanningTrees.html ├── MultithreadedAlgorithms.html ├── NPCompleteness.html ├── NumberTheoreticAlgorithms.html ├── Outline2017F.html ├── PolynomialsAndTheFFT.html ├── Probability.html ├── Python ├── AllPairsShortestPaths │ └── README ├── AmortizedAnalysis │ └── README ├── ApproximationAlgorithms │ ├── README │ ├── __init__.py │ ├── approximation_algorithms.py │ └── test_approximation_algorithms.py ├── AugmentingDataStructures │ └── README ├── BTrees │ └── README ├── BinarySearchTrees │ ├── README │ ├── __init__.py │ └── binary_search_trees.py ├── ComputationalGeometry │ └── README ├── DataStructuresForDisjointSets │ └── README ├── DivideAndConquer │ ├── FibonacciDemo.ipynb │ ├── README │ ├── __init__.py │ ├── divide_and_conquer.py │ └── fibonacci.py ├── DynamicProgramming │ ├── README │ ├── __init__.py │ └── dynamic_programming.py ├── ElementaryDataStructures │ └── README ├── FibonacciHeaps │ └── README ├── GettingStarted │ ├── README │ ├── __init__.py │ └── getting_started.py ├── GraphAlgorithms │ ├── README │ ├── __init__.py │ └── graph_algorithms.py ├── GreedyAlgorithms │ ├── README │ ├── __init__.py │ └── greedy_algorithms.py ├── GrowthOfFunctions │ └── README ├── HashTables │ ├── README │ ├── hash_comp.py │ └── hash_tables.py ├── Heapsort │ ├── README │ ├── __init__.py │ └── heapsort.py ├── LinearProgramming │ └── README ├── MatrixOperations │ └── README ├── MaximumFlow │ └── README ├── MediansAndOrderStatistics │ ├── README │ ├── __init__.py │ └── medians.py ├── MinimumSpanningTrees │ ├── README │ └── mst.py ├── MultithreadedAlgorithms │ └── README ├── NPCompleteness │ └── README ├── NumberTheoreticAlgorithms │ └── README ├── PolynomialsAndTheFFT │ └── README ├── Quicksort │ ├── README │ ├── __init__.py │ └── quicksort.py ├── RandomizedAlgorithms │ ├── README │ └── randomized_algorithms.py ├── RedBlackTrees │ └── README ├── SingleSourceShortestPaths │ └── README ├── SortingInLinearTime │ └── README ├── StringMatching │ └── README ├── TheRoleOfAlgorithms │ └── README ├── __init__.py ├── print_dups.py ├── test_binary_search_trees.py ├── test_fibonacci.py ├── test_getting_started.py ├── test_greedy_algorithms.py ├── test_heapsort.py ├── test_quicksort.py ├── test_template.py ├── tests.sh ├── utils │ ├── __init__.py │ ├── graph.py │ ├── misc.py │ └── test_utils.py └── vanEmdeBoasTrees │ └── README ├── Quicksort.html ├── README.md ├── Rakefile ├── RandomizedAlgorithms.html ├── RedBlackTrees.html ├── RegularityCondition.xlsx ├── Ruby ├── AllPairsShortestPaths │ └── README ├── AmortizedAnalysis │ └── README ├── ApproximationAlgorithms │ └── README ├── AugmentingDataStructures │ └── README ├── BTrees │ └── README ├── BinarySearchTrees │ ├── README │ ├── graphviz_methods.rb │ ├── insertion_deletion.rb │ ├── node.rb │ ├── ruby_graphviz_images │ │ ├── Order 0 - Inserted F.png │ │ ├── Order 1 - Inserted B.png │ │ ├── Order 2 - Inserted G.png │ │ ├── Order 3 - Inserted A.png │ │ ├── Order 4 - Inserted D.png │ │ ├── Order 5 - Inserted C.png │ │ ├── Order 6 - Inserted E.png │ │ ├── Order 7 - Inserted I.png │ │ └── Order 8 - Inserted H.png │ ├── search.rb │ ├── traversals.rb │ ├── tree.rb │ └── unit_tests │ │ ├── insertion_deletion_test.rb │ │ ├── search_test.rb │ │ └── seed_binary_search_tree.rb ├── ComputationalGeometry │ └── README ├── DataStructuresForDisjointSets │ └── README ├── DivideAndConquer │ ├── README │ ├── find_max_subarray.rb │ ├── matrix_multiplication.rb │ ├── towers_of_hanoi.rb │ └── unit_tests │ │ ├── find_max_subarray_test.rb │ │ └── matrix_multiplication_test.rb ├── DynamicProgramming │ ├── README │ ├── dynamic_programming_tests.sh │ ├── lcs.rb │ ├── matrix_chain_multiplication.rb │ ├── optimal_binary_search_tree.rb │ ├── rod_cutting.rb │ └── unit_tests │ │ ├── lcs_test.rb │ │ ├── matrix_chain_multiplication_test.rb │ │ ├── optimal_binary_search_tree_test.rb │ │ └── rod_cutting_test.rb ├── ElementaryDataStructures │ └── README ├── FibonacciHeaps │ └── README ├── GettingStarted │ ├── README │ ├── bubble_sort.rb │ ├── insertion_sort.rb │ ├── merge_sort.rb │ └── unit_tests │ │ ├── bubble_sort_test.rb │ │ ├── getting_started.sh │ │ ├── insertion_sort_test.rb │ │ └── merge_sort_test.rb ├── GraphAlgorithms │ ├── README │ ├── breadth_first_search.rb │ ├── depth_first_search.rb │ ├── directed_graph.rb │ ├── disjoint_set.rb │ ├── graph.rb │ ├── minimum_spanning_tree.rb │ ├── topological_sort.rb │ ├── undirected_graph.rb │ ├── unit_tests │ │ ├── breadth_first_search_test.rb │ │ ├── depth_first_search_test.rb │ │ ├── disjoint_set_test.rb │ │ ├── graph_test.rb │ │ ├── minimum_spanning_tree_test.rb │ │ ├── seed_graph.rb │ │ └── topological_sort_test.rb │ └── weighted_graph.rb ├── GreedyAlgorithms │ ├── README │ ├── activity_selection.rb │ ├── knapsack.rb │ └── unit_tests │ │ ├── activity_selection_test.rb │ │ └── knapsack_test.rb ├── GrowthOfFunctions │ └── README ├── HashTables │ ├── README │ ├── direct_addressing.rb │ ├── hash.rb │ ├── node.rb │ ├── open_addressing.rb │ ├── popular_hashes.rb │ └── unit_tests │ │ ├── direct_addressing_test.rb │ │ └── open_addressing_test.rb ├── Heapsort │ ├── README.md │ ├── heap_sort.rb │ ├── max_heap.rb │ ├── max_priority_queue.rb │ ├── min_heap.rb │ ├── min_priority_queue.rb │ ├── monkey_patch.rb │ └── unit_tests │ │ ├── heap_sort_test.rb │ │ ├── max_heap_test.rb │ │ ├── max_priority_queue_test.rb │ │ ├── min_heap_test.rb │ │ └── min_priority_queue_test.rb ├── LinearProgramming │ └── README ├── MatrixOperations │ └── README ├── MaximumFlow │ └── README ├── MediansAndOrderStatistics │ ├── README │ ├── min_max.rb │ ├── randomized_select.rb │ └── unit_tests │ │ ├── min_max_test.rb │ │ └── randomized_select_test.rb ├── MinimumSpanningTrees │ └── README ├── MultithreadedAlgorithms │ └── README ├── NPCompleteness │ └── README ├── NumberTheoreticAlgorithms │ └── README ├── PolynomialsAndTheFFT │ └── README ├── Quicksort │ ├── README.md │ ├── quick_sort.rb │ ├── randomized_quick_sort.rb │ ├── tail_recursive_quick_sort.rb │ └── unit_tests │ │ ├── quick_sort_test.rb │ │ ├── randomized_quick_sort_test.rb │ │ └── tail_recursive_quick_sort_test.rb ├── README.md ├── RandomizedAlgorithms │ ├── README │ ├── hire_assistant.rb │ ├── permuting_arrays.rb │ └── unit_tests │ │ ├── hire_assistant_test.rb │ │ └── permuting_arrays_test.rb ├── RedBlackTrees │ └── README ├── SingleSourceShortestPaths │ └── README ├── SortingInLinearTime │ ├── README │ ├── bucket_sort.rb │ ├── counting_sort.rb │ ├── radix_sort.rb │ └── unit_tests │ │ ├── bucket_sort_test.rb │ │ ├── counting_sort_test.rb │ │ └── radix_sort_test.rb ├── StringMatching │ └── README ├── TheRoleOfAlgorithms │ └── README ├── fibonacci │ ├── integer_methods.rb │ └── methods.rb ├── tests.sh ├── travis_test.rb ├── utils.rb └── vanEmdeBoasTrees │ └── README ├── SingleSourceShortestPaths.html ├── SortingInLinearTime.html ├── StringMatching.html ├── Syllabus2017F.docx ├── TAHours.html ├── TheRoleOfAlgorithms.html ├── Union-FindClassPresentation.pdf ├── about.html ├── checked.png ├── cross.png ├── feedback.html ├── final.css ├── gen_dirs.awk ├── gen_md.awk ├── graphics ├── 4TRec.gif ├── AdjList.png ├── AdjMatrix.png ├── Big-O-notation.png ├── BinTree1.png ├── BinTree2.png ├── Board.jpg ├── CommonSubsequence.png ├── EdgeList.png ├── EqCaseRec.gif ├── GraphForFinal.png ├── GraphForFinal2.png ├── GraphForFinal3.png ├── GraphForFinal4.png ├── GraphsEq1.gif ├── H3Eq1.gif ├── H3Eq2.gif ├── H3Eq3.gif ├── H3Eq4.gif ├── H3Eq5.gif ├── H3Eq6.gif ├── H3Eq7.gif ├── Huffman.png ├── Julia.png ├── Kruskal.png ├── Kruskal2.jpg ├── Lec3Eq1.gif ├── Lec3Eq2.gif ├── Lec3Eq3.gif ├── Lec3Eq4.gif ├── Lec3Eq5.gif ├── Lec3Eq6.gif ├── LinearityOfExp.gif ├── MatrixChainRun.png ├── MatroidGraph.png ├── MatroidMatching.png ├── MatroidVectors.png ├── MinSpanTree1.png ├── MinSpanTree2.png ├── NSquaredRec.gif ├── NSquaredTree1.png ├── NSquaredTree2.png ├── Notations.png ├── PolynomialLine.svg ├── PolynomialLine.xml ├── RandEq1.gif ├── RandEq10.gif ├── RandEq2.gif ├── RandEq3.gif ├── RandEq4.gif ├── RandEq5.gif ├── RandEq6.gif ├── RandEq7.gif ├── RandEq8.gif ├── RandEq9.gif ├── RecEq1.gif ├── RecEq2.gif ├── RecEq3.gif ├── RecEq4.gif ├── RecEq5.gif ├── RecEq6.gif ├── RecEq7.gif ├── RecEq8.gif ├── RecEq9.gif ├── RecRodCutEqn.gif ├── RedBlackBalance.png ├── RedBlackRightRotate.png ├── RedBlackUnbalanced.png ├── RegularityCond.png ├── ShortPath.png ├── ThreeTree.png └── TwoToTheN.png ├── index.html ├── makefile ├── ptml ├── AlgorithmMuseum.ptml ├── AllPairsShortestPaths.ptml ├── AmortizedAnalysis.ptml ├── ApproximationAlgorithms.ptml ├── AugmentingDataStructures.ptml ├── BTrees.ptml ├── BinarySearchTrees.ptml ├── ComputationalGeometry.ptml ├── DPVideo.ptml ├── DataStructuresForDisjointSets.ptml ├── DivideAndConquer.ptml ├── DynamicProgramming.ptml ├── ElementaryDataStructures.ptml ├── FibonacciHeaps.ptml ├── GettingStarted.ptml ├── GraphAlgorithms.ptml ├── GreedyAlgorithms.ptml ├── GrowthOfFunctions.ptml ├── HashTables.ptml ├── Heapsort.ptml ├── LinearProgramming.ptml ├── MatrixOperations.ptml ├── MaximumFlow.ptml ├── MediansAndOrderStatistics.ptml ├── MinimumSpanningTrees.ptml ├── MultithreadedAlgorithms.ptml ├── NPCompleteness.ptml ├── NumberTheoreticAlgorithms.ptml ├── Outline2017F.ptml ├── PolynomialsAndTheFFT.ptml ├── Probability.ptml ├── Quicksort.ptml ├── RandomizedAlgorithms.ptml ├── RedBlackTrees.ptml ├── SingleSourceShortestPaths.ptml ├── SortingInLinearTime.ptml ├── StringMatching.ptml ├── TAHours.ptml ├── TheRoleOfAlgorithms.ptml ├── about.ptml ├── feedback.ptml ├── index.ptml └── vanEmdeBoasTrees.ptml ├── qentry.sh ├── quizzes ├── makefile ├── quiz11.1.qhtm ├── quiz11.1.txt ├── quiz12.1.qhtm ├── quiz12.1.txt ├── quiz13.1.qhtm ├── quiz13.1.txt ├── quiz13.3.qhtm ├── quiz13.3.txt ├── quiz2.2.qhtm ├── quiz2.2.txt ├── quiz3.3.qhtm ├── quiz3.3.txt ├── quiz4.1.qhtm ├── quiz4.1.txt ├── quiz4.5.qhtm ├── quiz4.5.txt ├── quiz6.2.qhtm ├── quiz6.2.txt ├── quiz999.999.qhtm └── quiz999.999.txt ├── recurrence.pdf ├── rel.sh ├── run_ruby_and_python_tests.sh ├── sample.awk ├── style.css ├── templates ├── .gitignore ├── AllPairsShortestPaths_langs.txt ├── AmortizedAnalysis_langs.txt ├── ApproximationAlgorithms_langs.txt ├── AugmentingDataStructures_langs.txt ├── BTrees_langs.txt ├── BinarySearchTrees_langs.txt ├── ChapTemplate.txt ├── ComputationalGeometry_langs.txt ├── DataStructuresForDisjointSets_langs.txt ├── DivideAndConquer_langs.txt ├── DynamicProgramming_langs.txt ├── ElementaryDataStructures_langs.txt ├── FibonacciHeaps_langs.txt ├── GettingStarted_langs.txt ├── GraphAlgorithms_langs.txt ├── GreedyAlgorithms_langs.txt ├── GrowthOfFunctions_langs.txt ├── HashTables_langs.txt ├── Heapsort_langs.txt ├── LatexCode.txt ├── LinearProgramming_langs.txt ├── MatrixOperations_langs.txt ├── MaximumFlow_langs.txt ├── MediansAndOrderStatistics_langs.txt ├── MinimumSpanningTrees_langs.txt ├── MultithreadedAlgorithms_langs.txt ├── NPCompleteness_langs.txt ├── NumberTheoreticAlgorithms_langs.txt ├── PolynomialsAndTheFFT_langs.txt ├── Quicksort_langs.txt ├── RandomizedAlgorithms_langs.txt ├── RedBlackTrees_langs.txt ├── SingleSourceShortestPaths_langs.txt ├── SortingInLinearTime_langs.txt ├── StringMatching_langs.txt ├── TheRoleOfAlgorithms_langs.txt ├── ToDo.txt ├── chap_menu.txt ├── chapters.txt ├── gen_chap_files.awk ├── gen_chaps.awk ├── gen_lang_bin.awk ├── gen_lang_menu.awk ├── google_analytics.txt ├── lang_chapter_binary.txt ├── lang_menu.txt ├── langs.txt ├── makefile ├── menu.txt ├── python_anywhere.txt └── vanEmdeBoasTrees_langs.txt ├── test.html ├── test_runner.sh ├── tests ├── FinalFall2016.html ├── FinalFall2017.pdf ├── MidTermFall2016.html ├── MidTermFall2017.pdf └── index.html └── vanEmdeBoasTrees.html /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "Algocynfas"] 2 | path = Algocynfas 3 | url = https://github.com/gcallah/Algocynfas.git 4 | [submodule "utils"] 5 | path = utils 6 | url = https://github.com/gcallah/utils 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - '3.5' 4 | before_install: 5 | - rvm install 2.0.0-p648 6 | - bundle install 7 | - pip3 install pytest 8 | script: source test_runner.sh 9 | -------------------------------------------------------------------------------- /99-recurrences.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/99-recurrences.pdf -------------------------------------------------------------------------------- /C++/AllPairsShortestPaths/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/C++/AllPairsShortestPaths/README -------------------------------------------------------------------------------- /C++/AmortizedAnalysis/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/C++/AmortizedAnalysis/README -------------------------------------------------------------------------------- /C++/ApproximationAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/C++/ApproximationAlgorithms/README -------------------------------------------------------------------------------- /C++/AugmentingDataStructures/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/C++/AugmentingDataStructures/README -------------------------------------------------------------------------------- /C++/BTrees/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/C++/BTrees/README -------------------------------------------------------------------------------- /C++/BinarySearchTrees/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/C++/BinarySearchTrees/README -------------------------------------------------------------------------------- /C++/ComputationalGeometry/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/C++/ComputationalGeometry/README -------------------------------------------------------------------------------- /C++/DataStructuresForDisjointSets/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/C++/DataStructuresForDisjointSets/README -------------------------------------------------------------------------------- /C++/DivideAndConquer/DivideAndConquer/find_maximum_subarray_test.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // main.cpp 3 | // DivideAndConquer 4 | // 5 | // Created by Xiaohang Su on 2/3/17. 6 | // Copyright © 2017 Xiaohang Su. All rights reserved. 7 | // 8 | 9 | #include 10 | #include "maximum_array.h" 11 | using namespace std; 12 | int main(int argc, const char * argv[]) { 13 | int a[16] = {13, -3, -25, 20, -3, -16, -23, 18, 20, -7, 12, -5, -22, 15, -4, 7}; 14 | vector b(a, a + 16); 15 | triplet res = find_maximum_subarray(b, 0, b.size() - 1); 16 | cout << "(" < 4 | 5 | using namespace std; 6 | 7 | void inputMatrixValue(Matrix &x) { 8 | for (int i = 0; i < x.row; i++) { 9 | cout << "Input Matrix row " << i + 1 << ":" << endl; 10 | for (int j = 0; j < x.col; j++) { 11 | double val; 12 | x.matrix[i][j] = 1; 13 | } 14 | } 15 | cout << "End" << endl; 16 | cout << endl; 17 | } 18 | 19 | int main() { 20 | while (1) { 21 | int row, col; 22 | cout << "Input Matrix A Row and Col"; 23 | cin >> row >> col; 24 | Matrix A(row, col); 25 | inputMatrixValue(A); 26 | cout << "Input Matrix B Row and Col"; 27 | cin >> row >> col; 28 | Matrix B(row, col); 29 | inputMatrixValue(B); 30 | Matrix dotSum = A * (B); 31 | Matrix sDotSum = A % (B); 32 | } 33 | return 0; 34 | } -------------------------------------------------------------------------------- /C++/DynamicProgramming/DynamicProgrammingTest/LCS_test.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // main.cpp 3 | // dynamic_programming 4 | // 5 | // Created by Xiaohang Su on 12/3/16. 6 | // 7 | // 8 | 9 | #include 10 | #include "Rod_cutting.h" 11 | #include "Optimal_BST.h" 12 | #include "Matrix_Chain.h" 13 | #include "LCS.h" 14 | #include 15 | 16 | 17 | int main(int argc, const char * argv[]) { 18 | // insert code here... 19 | 20 | LCS b; 21 | b.LCS_Length("ABCBDAB", "BDCABA"); 22 | b.print_LCS(b.b, "ABCBDAB", 7, 6); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /C++/DynamicProgramming/DynamicProgrammingTest/matrix_chain_test.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/C++/DynamicProgramming/DynamicProgrammingTest/matrix_chain_test.cpp -------------------------------------------------------------------------------- /C++/DynamicProgramming/DynamicProgrammingTest/optimal_binary_tree_test.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // main.cpp 3 | // dynamic_programming 4 | // 5 | // Created by Xiaohang Su on 12/3/16. 6 | // 7 | // 8 | 9 | #include 10 | #include "Rod_cutting.h" 11 | #include "Optimal_BST.h" 12 | 13 | #include 14 | int main(int argc, const char * argv[]) { 15 | // insert code here... 16 | double p[6] = {-1.0, 0.15, 0.10, 0.05, 0.10, 0.20}; 17 | double q[6] = {0.05, 0.10, 0.05, 0.05, 0.05, 0.10}; 18 | 19 | Optimal_BST BST(vector(std::begin(p), std::end(p)), vector(std::begin(q), std::end(q))); 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /C++/DynamicProgramming/DynamicProgrammingTest/rob_cutting_test.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // main.cpp 3 | // dynamic_programming 4 | // 5 | // Created by Xiaohang Su on 12/3/16. 6 | // 7 | // 8 | 9 | #include 10 | #include "Rod_cutting.h" 11 | #include 12 | int main(int argc, const char * argv[]) { 13 | // insert code here... 14 | std::cout << "Hello, World!\n"; 15 | std::cout << "Input Rod Length: "; 16 | int length = 0; 17 | std::cin >> length; 18 | Rod_cutting rod(length); 19 | std::string op; 20 | std::cout << "Input 'r' For Recursive Cut Rod or 'm' For MemorizeD Cut Rod" << std::endl; 21 | std::cin >> op; 22 | if (op == "r") 23 | std::cout << "Maximum Price: " << rod.recursive_cut_rod(rod.price, rod.length) << std::endl; 24 | else if (op == "m") 25 | std::cout << "Maximum Price: " << rod.memorized_cut_rod(rod.price, rod.length) << std::endl; 26 | std::cout << "Maximum Price: " << rod.bottom_up_cut_rod(rod.price, rod.length) << std::endl; 27 | std::cout << "Print cut path: "; 28 | rod.print_cut_rod_solution(rod.price, rod.length); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /C++/DynamicProgramming/MatrixChainning/Matrix_Chain.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/C++/DynamicProgramming/MatrixChainning/Matrix_Chain.h -------------------------------------------------------------------------------- /C++/ElementaryDataStructures/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/C++/ElementaryDataStructures/README -------------------------------------------------------------------------------- /C++/ElementaryDataStructures/cqueue.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef CQUEUE 3 | #define CQUEUE 4 | 5 | #include 6 | 7 | const static int CQUEUE_SIZE = 10; 8 | 9 | struct cqueue { 10 | int head = 0, tail = 0; 11 | std::vector Q; 12 | cqueue() { 13 | head = 0; 14 | tail = 0; 15 | Q = std::vector(CQUEUE_SIZE, 0); 16 | } 17 | }; 18 | 19 | void enqueue(cqueue Q, int x) { 20 | Q.Q[Q.tail] = x; 21 | if (Q.tail == Q.Q.size()) { 22 | Q.tail = 1; 23 | } 24 | else { 25 | Q.tail = Q.tail + 1; 26 | } 27 | } 28 | 29 | int dequeue(cqueue Q) { 30 | int x; 31 | x = Q.Q[Q.head]; 32 | if (Q.head == Q.Q.size()) { 33 | Q.head = 1; 34 | } 35 | else { 36 | Q.head = Q.head + 1; 37 | } 38 | return x; 39 | } 40 | 41 | #endif // !CQUEUE 42 | -------------------------------------------------------------------------------- /C++/ElementaryDataStructures/cstack.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef CSTACK 3 | #define CSTACK 4 | 5 | // use vector serves as array 6 | #include 7 | #include 8 | struct cstack 9 | { 10 | int top; 11 | std::vector S; 12 | cstack() { 13 | top = 0; 14 | } 15 | }; 16 | 17 | bool stack_empty(cstack S) { 18 | if (S.top == 0) return true; 19 | else return false; 20 | } 21 | 22 | void push(cstack S, int x) { 23 | S.top = S.top + 1; 24 | S.S.push_back(x); 25 | } 26 | 27 | int pop(cstack S) { 28 | assert(!stack_empty(S)); 29 | S.top = S.top - 1; 30 | int top = S.S.back(); 31 | S.S.pop_back(); 32 | return top; 33 | } 34 | 35 | #endif // !CSTACK 36 | -------------------------------------------------------------------------------- /C++/ElementaryDataStructures/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | return 0; 7 | } -------------------------------------------------------------------------------- /C++/ElementaryDataStructures/queue.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | -------------------------------------------------------------------------------- /C++/ElementaryDataStructures/queues.h: -------------------------------------------------------------------------------- 1 | // 2 | // queues.h 3 | // elementaryDataStructure 4 | // 5 | // Created by Xiaohang Su on 24/03/2017. 6 | // Copyright © 2017 Xiaohang Su. All rights reserved. 7 | // 8 | 9 | #ifndef queues_h 10 | #define queues_h 11 | 12 | #include 13 | #include 14 | 15 | struct d_queue { 16 | int tail; 17 | int head; 18 | std::vector q; 19 | d_queue(const int t_size) { 20 | q = std::vector(t_size, 0); 21 | } 22 | }; 23 | 24 | void enqueue(d_queue &Q, int x) { 25 | Q.q[Q.tail] = x; 26 | if (Q.tail == Q.q.size()) { 27 | Q.tail = 0; 28 | } else { 29 | Q.tail = Q.tail + 1; 30 | } 31 | } 32 | 33 | int dequeue(d_queue &Q) { 34 | int x = Q.q[Q.head]; 35 | if (Q.head == Q.q.size()) { 36 | Q.head = 0; 37 | } else { 38 | Q.head = Q.head + 1; 39 | } 40 | return x; 41 | } 42 | 43 | #endif /* queues_h */ 44 | -------------------------------------------------------------------------------- /C++/ElementaryDataStructures/stacks.h: -------------------------------------------------------------------------------- 1 | // 2 | // stacks.h 3 | // elementaryDataStructure 4 | // 5 | // Created by Xiaohang Su on 24/03/2017. 6 | // Copyright © 2017 Xiaohang Su. All rights reserved. 7 | // 8 | 9 | #ifndef stacks_h 10 | #define stacks_h 11 | 12 | #include 13 | #include 14 | struct d_stack { 15 | std::vector S; 16 | int top; 17 | d_stack(int t_size) { 18 | S = std::vector(t_size, 0); 19 | top = -1; 20 | } 21 | }; 22 | 23 | bool stack_empty(const d_stack &S) { 24 | if (S.top == -1) { 25 | return true; 26 | } else { 27 | return false; 28 | } 29 | } 30 | 31 | void push(d_stack &S, int x) { 32 | S.top = S.top + 1; 33 | S.S[S.top] = x; 34 | } 35 | 36 | int pop(d_stack &S) { 37 | if (stack_empty(S)) { 38 | throw std::runtime_error("underflow"); 39 | } else { 40 | S.top = S.top - 1; 41 | return S.S[S.top + 1]; 42 | } 43 | } 44 | 45 | #endif /* stacks_h */ 46 | -------------------------------------------------------------------------------- /C++/FibonacciHeaps/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/C++/FibonacciHeaps/README -------------------------------------------------------------------------------- /C++/GettingStarted/bubble_sort.h: -------------------------------------------------------------------------------- 1 | // 2 | // bubble_sort.h 3 | // Getting Started 4 | // 5 | // Created by Xiaohang Su on 2/1/17. 6 | // Copyright © 2017 Xiaohang Su. All rights reserved. 7 | // 8 | 9 | #ifndef bubble_sort_h 10 | #define bubble_sort_h 11 | #include 12 | 13 | template 14 | void swap(T& a, T& b) { 15 | T c = b; 16 | b = a; 17 | a = c; 18 | } 19 | 20 | template 21 | void bubble_sort(std::vector & A) { 22 | for (int i = 0; i < A.size() - 1; i++) { 23 | for (int j = A.size() - 1; j >= i + 1; j--) { 24 | if (A[j] < A[j - 1]) { 25 | swap(A[j], A[j - 1]); 26 | } 27 | } 28 | } 29 | } 30 | 31 | 32 | #endif /* bubble_sort_h */ 33 | -------------------------------------------------------------------------------- /C++/GettingStarted/insertion_sort.h: -------------------------------------------------------------------------------- 1 | // 2 | // Insertion_sort.h 3 | // Getting Started 4 | // 5 | // Created by Xiaohang Su on 2/1/17. 6 | // Copyright © 2017 Xiaohang Su. All rights reserved. 7 | // 8 | 9 | #ifndef Insertion_sort_h 10 | #define Insertion_sort_h 11 | #include 12 | template 13 | void insertion_sort(std::vector &A) { 14 | for (int j = 1; j < A.size(); j++) { 15 | comparable key = A[j]; 16 | // Insert A[j] into the sorted sequence A[1 .. j - 1] 17 | int i = j - 1; 18 | while (i >= 0 && A[i] > key) { 19 | A[i + 1] = A[i]; 20 | i = i - 1; 21 | } 22 | A[i + 1] = key; 23 | } 24 | } 25 | #endif /* Insertion_sort_h */ 26 | -------------------------------------------------------------------------------- /C++/GettingStarted/sort_test.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // main.cpp 3 | // Getting Started 4 | // 5 | // Created by Xiaohang Su on 2/1/17. 6 | // Copyright © 2017 Xiaohang Su. All rights reserved. 7 | // 8 | 9 | #include 10 | #include "insertion_sort.h" 11 | #include "merge_sort.h" 12 | #include "bubble_sort.h" 13 | 14 | using namespace std; 15 | int main(int argc, const char * argv[]) { 16 | int a[10] = {1, 4, 2, 3, 6, 5, 9, 7, 8, 0}; 17 | vector b(a, a + 10); 18 | vector c = b; 19 | vector d = c; 20 | insertion_sort(b); 21 | merge_sort(c, 0, c.size() - 1); 22 | bubble_sort(d); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /C++/GraphAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/C++/GraphAlgorithms/README -------------------------------------------------------------------------------- /C++/GreedyAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/C++/GreedyAlgorithms/README -------------------------------------------------------------------------------- /C++/GrowthOfFunctions/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/C++/GrowthOfFunctions/README -------------------------------------------------------------------------------- /C++/Hanoi/Hanoi.cpp: -------------------------------------------------------------------------------- 1 | #include "Hanoi.h" 2 | #include 3 | int main() { 4 | int disks; 5 | std::cout << "Input Disks number:"; 6 | std::cin >> disks; 7 | Hanoi hanoi(disks); 8 | hanoi.start(); 9 | system("pause"); 10 | return 0; 11 | } -------------------------------------------------------------------------------- /C++/HashTables/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/C++/HashTables/README -------------------------------------------------------------------------------- /C++/Heapsort/heapsort_main.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // main.cpp 3 | // AlgorithmMuseum 4 | // 5 | // Created by Xiaohang Su on 1/29/17. 6 | // Copyright © 2017 Xiaohang Su. All rights reserved. 7 | // 8 | 9 | #include 10 | #include "heapsort.h" 11 | 12 | int main(int argc, const char * argv[]) { 13 | int a[10] = {2, 6, 5, 3, 9, 0, 8, 1, 4, 7}; 14 | std::vector b(a, a + sizeof(a) / sizeof(a[0])); 15 | heapsort heaps; 16 | heaps.heapsort(b); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /C++/Heapsort/priorityqueue_main.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // main.cpp 3 | // AlgorithmMuseum 4 | // 5 | // Created by Xiaohang Su on 1/29/17. 6 | // Copyright © 2017 Xiaohang Su. All rights reserved. 7 | // 8 | 9 | #include 10 | #include "priority_queue.h" 11 | #include "heapsort.h" 12 | #include 13 | 14 | int main(int argc, const char * argv[]) { 15 | int a[10] = {2, 6, 5, 3, 9, 0, 8, 1, 4, 7}; 16 | std::vector b(a, a + sizeof(a) / sizeof(a[0])); 17 | PriorityQueue pq; 18 | pq.build_max_heap(b); 19 | pq.heap_extract_max(b); 20 | pq.max_heap_insert(b, 10, INT_MIN); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /C++/LinearProgramming/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/C++/LinearProgramming/README -------------------------------------------------------------------------------- /C++/MatrixOperations/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/C++/MatrixOperations/README -------------------------------------------------------------------------------- /C++/MaximumFlow/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/C++/MaximumFlow/README -------------------------------------------------------------------------------- /C++/MediansAndOrderStatistics/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/C++/MediansAndOrderStatistics/README -------------------------------------------------------------------------------- /C++/MediansAndOrderStatistics/random_select.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | void minimum(vector A) { 6 | int minVal = A[0]; 7 | for (int i = 1; i < A.size(); i++) { 8 | if (minVal > A[i]) { 9 | minVal = A[i]; 10 | } 11 | } 12 | 13 | return minVal; 14 | } 15 | 16 | 17 | // from section 7.3 randomized_partition 18 | int randomized_partition(std::vector A, int p, int r) { 19 | int i = (rand() % (r - p)) + p; 20 | std::swap(A[r], A[i]); 21 | return partition(A, p, r); 22 | } 23 | 24 | int randomized_select(vector A, int p, int r, int i) { 25 | if (p == r) { 26 | return A[p]; 27 | } 28 | int q = randomized_partition(A, p, r); 29 | int k = p - q + 1; 30 | if (i == k) // the pivot value is the answer 31 | return A[q]; 32 | else if (i < k) { 33 | return randomized_select(A, p, q - 1, i); 34 | } else { 35 | return randomized_select(A, q + 1, r, i - k); 36 | } 37 | } -------------------------------------------------------------------------------- /C++/MinimumSpanningTrees/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/C++/MinimumSpanningTrees/README -------------------------------------------------------------------------------- /C++/MultithreadedAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/C++/MultithreadedAlgorithms/README -------------------------------------------------------------------------------- /C++/MultithreadedAlgorithms/fibonacci.h: -------------------------------------------------------------------------------- 1 | // 2 | // fibonacci.h 3 | // multithreadedAlgorithm 4 | // 5 | // Created by Xiaohang Su on 19/03/2017. 6 | // Copyright © 2017 Xiaohang Su. All rights reserved. 7 | // 8 | 9 | #ifndef fibonacci_h 10 | #define fibonacci_h 11 | #include 12 | #include 13 | 14 | int fib(int n) { 15 | if (n <= 1) { 16 | return n; 17 | } else { 18 | int x = fib(n - 1); 19 | int y = fib(n - 2); 20 | return x + y; 21 | } 22 | } 23 | 24 | // C++ 11 feature using future 25 | // Implementation varies different languages 26 | // computer is not ideal and max thread numbers are easily reach with larger n 27 | int p_fib(int n) { 28 | if (n <= 1) { 29 | return n; 30 | } else { 31 | std::future fut = std::async(p_fib, n - 1); 32 | int y = p_fib(n - 2); 33 | 34 | return fut.get() + y; 35 | } 36 | } 37 | 38 | #endif /* fibonacci_h */ 39 | -------------------------------------------------------------------------------- /C++/MultithreadedAlgorithms/test.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // main.cpp 3 | // multithreadedAlgorithm 4 | // 5 | // Created by Xiaohang Su on 19/03/2017. 6 | // Copyright © 2017 Xiaohang Su. All rights reserved. 7 | // 8 | 9 | #include 10 | #include "fibonacci.h" 11 | #include "matrix.h" 12 | 13 | 14 | using namespace std; 15 | int main(int argc, const char * argv[]) { 16 | int n = 10; 17 | cout << p_fib(n) << endl; // might threads explode 18 | 19 | cout << fib(n) << endl; 20 | cout << "Race Example: "; 21 | race_example(); 22 | 23 | 24 | cout << "Matrix Calculation" << endl; 25 | vector> A {{1,2,3}, 26 | {4,5,6}, 27 | {7,8,9}}; 28 | vector x {3, 6, 9}; 29 | vector y = mat_vec(A, x); 30 | vector wrongY = mat_vec_wrong(A, x); 31 | 32 | vector main_loop_y(3, 0); 33 | mat_vec_main_loop(A, x, main_loop_y, 3, 0, 2); 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /C++/NPCompleteness/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/C++/NPCompleteness/README -------------------------------------------------------------------------------- /C++/NumberTheoreticAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/C++/NumberTheoreticAlgorithms/README -------------------------------------------------------------------------------- /C++/PolynomialsAndTheFFT/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/C++/PolynomialsAndTheFFT/README -------------------------------------------------------------------------------- /C++/Quicksort/QuicksortTest.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // main.cpp 3 | // Quicksort 4 | // 5 | // Created by Xiaohang Su on 2/21/17. 6 | // Copyright © 2017 Xiaohang Su. All rights reserved. 7 | // 8 | 9 | #include 10 | #include 11 | #include "Quicksort.h" 12 | using namespace std; 13 | int main(int argc, const char * argv[]) { 14 | srand(time(0)); 15 | vector unsorted_array({2,3,6,1,4,9,5,0,8,7}); 16 | vector a = unsorted_array; 17 | vector b = unsorted_array; 18 | quicksort(a, 0, a.size() - 1); 19 | randomized_quicksort(b, 0, b.size() - 1); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /C++/RandomizedAlgorithms/test.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // main.cpp 3 | // ProbabilisticAnalysis_RandomizedAlgorithms 4 | // 5 | // Created by Xiaohang Su on 2/10/17. 6 | // Copyright © 2017 Xiaohang Su. All rights reserved. 7 | // 8 | 9 | #include 10 | #include "hiring_problem.h" 11 | #include "randomized_algorithms.h" 12 | using namespace std; 13 | int main(int argc, const char * argv[]) { 14 | srand(time(NULL)); // use for random number 15 | vector A ({1, 3, 5, 2, 4 ,3}); 16 | permute_by_sorting(A); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /C++/RedBlackTrees/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/C++/RedBlackTrees/README -------------------------------------------------------------------------------- /C++/SingleSourceShortestPaths/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/C++/SingleSourceShortestPaths/README -------------------------------------------------------------------------------- /C++/SortingInLinearTime/bucket_sort.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Xiaohang Su on 2/27/17. 3 | // Copyright © 2017 Xiaohang Su. All rights reserved. 4 | // 5 | 6 | #ifndef BUCKET_SORT_H 7 | #define BUCKET_SORT_H 8 | 9 | #include 10 | template 11 | void buck_sort(std::vector& A) { 12 | // n is important, it represents how many buckets, 13 | // but also need elements in this range(0 ~ n - 1) 14 | int n = A.size(); 15 | std::vector buckets(n, T()); 16 | for (int i = 0; i < A.size(); i++) { 17 | // insert bucket in bucket 18 | // hash is a common approach 19 | } 20 | // buckets element insides all sorted 21 | for (int i = 0; i < buckets.size(); i++) { 22 | // concatenate all buckets 23 | // define your own method 24 | } 25 | } 26 | 27 | // O(n) + n * O(2 - 1/n) = O(n) 28 | // O(n) time complexity 29 | 30 | #endif -------------------------------------------------------------------------------- /C++/SortingInLinearTime/counting_sort.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Xiaohang Su on 2/27/17. 3 | // Copyright © 2017 Xiaohang Su. All rights reserved. 4 | // 5 | #ifndef COUNTING_SORT_H 6 | #define COUNTING_SORT_H 7 | 8 | #include 9 | using namespace std; 10 | template 11 | void counting_sort(vector &A, vector& B, int k) { 12 | vector C(k + 1, 0); 13 | for (int j = 0; j < A.size(); j++) { 14 | C[A[j]] = C[A[j]] + 1; 15 | } 16 | // C[i] now contains the number of elements equal to i. 17 | for (int i = 1; i <= k; i++) { 18 | C[i] = C[i] + C[i - 1]; 19 | } 20 | // C[i] now contains the number of elements less than or equal to i. 21 | for (int j = A.size() - 1; j >= 0; j--) { 22 | B[C[A[j]]] = A[j]; 23 | C[A[j]] = C[A[j]] - 1; 24 | } 25 | } 26 | 27 | // stable sort 28 | // O(n) 29 | // limitation: n input elements is an integer in the range for 0 to k. 30 | #endif -------------------------------------------------------------------------------- /C++/SortingInLinearTime/radix_sort.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Xiaohang Su on 2/27/17. 3 | // Copyright © 2017 Xiaohang Su. All rights reserved. 4 | // 5 | 6 | #ifndef RADIX_SORT_H 7 | #define RADIX_SORT_H 8 | 9 | #include 10 | 11 | template 12 | void radix_sort(std::vector &A, int d) { // d represent radix number 13 | for (int i = 0; i < d; i++) { 14 | // use a stable sort to sort array A on digit/string_index i 15 | } 16 | } 17 | 18 | #endif -------------------------------------------------------------------------------- /C++/SortingInLinearTime/test.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Xiaohang Su on 2/27/17. 3 | // Copyright © 2017 Xiaohang Su. All rights reserved. 4 | // 5 | #include 6 | 7 | using namespace std; 8 | 9 | int main() { 10 | return 0; 11 | } -------------------------------------------------------------------------------- /C++/StringMatching/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/C++/StringMatching/README -------------------------------------------------------------------------------- /C++/TheRoleOfAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/C++/TheRoleOfAlgorithms/README -------------------------------------------------------------------------------- /C++/tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # put tests here! 4 | 5 | exit 0 6 | -------------------------------------------------------------------------------- /C++/vanEmdeBoasTrees/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/C++/vanEmdeBoasTrees/README -------------------------------------------------------------------------------- /Clojure/AllPairsShortestPaths/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Clojure/AllPairsShortestPaths/README -------------------------------------------------------------------------------- /Clojure/AmortizedAnalysis/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Clojure/AmortizedAnalysis/README -------------------------------------------------------------------------------- /Clojure/ApproximationAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Clojure/ApproximationAlgorithms/README -------------------------------------------------------------------------------- /Clojure/AugmentingDataStructures/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Clojure/AugmentingDataStructures/README -------------------------------------------------------------------------------- /Clojure/BTrees/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Clojure/BTrees/README -------------------------------------------------------------------------------- /Clojure/BinarySearchTrees/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Clojure/BinarySearchTrees/README -------------------------------------------------------------------------------- /Clojure/ComputationalGeometry/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Clojure/ComputationalGeometry/README -------------------------------------------------------------------------------- /Clojure/DataStructuresForDisjointSets/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Clojure/DataStructuresForDisjointSets/README -------------------------------------------------------------------------------- /Clojure/DivideAndConquer/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Clojure/DivideAndConquer/README -------------------------------------------------------------------------------- /Clojure/DynamicProgramming/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Clojure/DynamicProgramming/README -------------------------------------------------------------------------------- /Clojure/DynamicProgramming/fibonacci.clj: -------------------------------------------------------------------------------- 1 | ;;;; Clojure examples of algorithms from Getting Started chapter of CLRS 2 | ;;;; Introduction to Algorithms. 3 | ;;;; Since the intention is that students can run these in the interactive 4 | ;;;; Clojure interpreter, rather than build JVM Clojure programs with them, for 5 | ;;;; now we are not worried about Clojure's module structure. 6 | ;;;; We used: 7 | ;;;; http://danmidwood.com/content/2013/02/24/exploring-clojure-memoization.html 8 | ;;;; in preparing these functions 9 | 10 | (defn fib 11 | "A naive, recursive fibonacci function." 12 | [n] 13 | ;; print . to indicate number of calls 14 | (print ".") 15 | (if (>= 1 n) 16 | n 17 | (+ (fib (- n 1)) (fib (- n 2))) 18 | ) 19 | ) 20 | 21 | ;; memo-ized version of above 22 | (def memo-fib 23 | (memoize 24 | (fn [n] 25 | ;; print . to indicate number of calls 26 | (print ".") 27 | (if (>= 1 n) 28 | n 29 | (+ (memo-fib (- n 1)) (memo-fib (- n 2))) 30 | ) 31 | ) 32 | ) 33 | ) 34 | -------------------------------------------------------------------------------- /Clojure/ElementaryDataStructures/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Clojure/ElementaryDataStructures/README -------------------------------------------------------------------------------- /Clojure/FibonacciHeaps/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Clojure/FibonacciHeaps/README -------------------------------------------------------------------------------- /Clojure/GettingStarted/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Clojure/GettingStarted/README -------------------------------------------------------------------------------- /Clojure/GraphAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Clojure/GraphAlgorithms/README -------------------------------------------------------------------------------- /Clojure/GreedyAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Clojure/GreedyAlgorithms/README -------------------------------------------------------------------------------- /Clojure/GrowthOfFunctions/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Clojure/GrowthOfFunctions/README -------------------------------------------------------------------------------- /Clojure/HashTables/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Clojure/HashTables/README -------------------------------------------------------------------------------- /Clojure/Heapsort/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Clojure/Heapsort/README -------------------------------------------------------------------------------- /Clojure/LinearProgramming/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Clojure/LinearProgramming/README -------------------------------------------------------------------------------- /Clojure/MatrixOperations/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Clojure/MatrixOperations/README -------------------------------------------------------------------------------- /Clojure/MaximumFlow/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Clojure/MaximumFlow/README -------------------------------------------------------------------------------- /Clojure/MediansAndOrderStatistics/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Clojure/MediansAndOrderStatistics/README -------------------------------------------------------------------------------- /Clojure/MinimumSpanningTrees/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Clojure/MinimumSpanningTrees/README -------------------------------------------------------------------------------- /Clojure/MultithreadedAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Clojure/MultithreadedAlgorithms/README -------------------------------------------------------------------------------- /Clojure/NPCompleteness/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Clojure/NPCompleteness/README -------------------------------------------------------------------------------- /Clojure/NumberTheoreticAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Clojure/NumberTheoreticAlgorithms/README -------------------------------------------------------------------------------- /Clojure/PolynomialsAndTheFFT/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Clojure/PolynomialsAndTheFFT/README -------------------------------------------------------------------------------- /Clojure/Quicksort/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Clojure/Quicksort/README -------------------------------------------------------------------------------- /Clojure/RandomizedAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Clojure/RandomizedAlgorithms/README -------------------------------------------------------------------------------- /Clojure/RedBlackTrees/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Clojure/RedBlackTrees/README -------------------------------------------------------------------------------- /Clojure/SingleSourceShortestPaths/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Clojure/SingleSourceShortestPaths/README -------------------------------------------------------------------------------- /Clojure/SortingInLinearTime/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Clojure/SortingInLinearTime/README -------------------------------------------------------------------------------- /Clojure/StringMatching/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Clojure/StringMatching/README -------------------------------------------------------------------------------- /Clojure/TheRoleOfAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Clojure/TheRoleOfAlgorithms/README -------------------------------------------------------------------------------- /Clojure/tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # put tests here! 4 | 5 | exit 0 6 | -------------------------------------------------------------------------------- /Clojure/vanEmdeBoasTrees/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Clojure/vanEmdeBoasTrees/README -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'minitest', '5.8.4' 4 | -------------------------------------------------------------------------------- /Go/AllPairsShortestPaths/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Go/AllPairsShortestPaths/README -------------------------------------------------------------------------------- /Go/AmortizedAnalysis/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Go/AmortizedAnalysis/README -------------------------------------------------------------------------------- /Go/ApproximationAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Go/ApproximationAlgorithms/README -------------------------------------------------------------------------------- /Go/AugmentingDataStructures/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Go/AugmentingDataStructures/README -------------------------------------------------------------------------------- /Go/BTrees/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Go/BTrees/README -------------------------------------------------------------------------------- /Go/BinarySearchTrees/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Go/BinarySearchTrees/README -------------------------------------------------------------------------------- /Go/ComputationalGeometry/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Go/ComputationalGeometry/README -------------------------------------------------------------------------------- /Go/DataStructuresForDisjointSets/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Go/DataStructuresForDisjointSets/README -------------------------------------------------------------------------------- /Go/DivideAndConquer/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Go/DivideAndConquer/README -------------------------------------------------------------------------------- /Go/DynamicProgramming/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Go/DynamicProgramming/README -------------------------------------------------------------------------------- /Go/ElementaryDataStructures/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Go/ElementaryDataStructures/README -------------------------------------------------------------------------------- /Go/FibonacciHeaps/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Go/FibonacciHeaps/README -------------------------------------------------------------------------------- /Go/GraphAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Go/GraphAlgorithms/README -------------------------------------------------------------------------------- /Go/GrowthOfFunctions/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Go/GrowthOfFunctions/README -------------------------------------------------------------------------------- /Go/HashTables/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Go/HashTables/README -------------------------------------------------------------------------------- /Go/Heapsort/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Go/Heapsort/README -------------------------------------------------------------------------------- /Go/LinearProgramming/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Go/LinearProgramming/README -------------------------------------------------------------------------------- /Go/MatrixOperations/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Go/MatrixOperations/README -------------------------------------------------------------------------------- /Go/MaximumFlow/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Go/MaximumFlow/README -------------------------------------------------------------------------------- /Go/MediansAndOrderStatistics/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Go/MediansAndOrderStatistics/README -------------------------------------------------------------------------------- /Go/MinimumSpanningTrees/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Go/MinimumSpanningTrees/README -------------------------------------------------------------------------------- /Go/MultithreadedAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Go/MultithreadedAlgorithms/README -------------------------------------------------------------------------------- /Go/NPCompleteness/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Go/NPCompleteness/README -------------------------------------------------------------------------------- /Go/NumberTheoreticAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Go/NumberTheoreticAlgorithms/README -------------------------------------------------------------------------------- /Go/PolynomialsAndTheFFT/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Go/PolynomialsAndTheFFT/README -------------------------------------------------------------------------------- /Go/READMe.md: -------------------------------------------------------------------------------- 1 | # AlgorithmMuseum 2 | 3 | Code written in Go for Gene Callahan's Algorithm Museum 4 | 5 | https://gcallah.github.io/algorithms/AlgorithmMuseum.html 6 | 7 | -------------------------------------------------------------------------------- /Go/RandomizedAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Go/RandomizedAlgorithms/README -------------------------------------------------------------------------------- /Go/RedBlackTrees/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Go/RedBlackTrees/README -------------------------------------------------------------------------------- /Go/SingleSourceShortestPaths/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Go/SingleSourceShortestPaths/README -------------------------------------------------------------------------------- /Go/SortingInLinearTime/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Go/SortingInLinearTime/README -------------------------------------------------------------------------------- /Go/StringMatching/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Go/StringMatching/README -------------------------------------------------------------------------------- /Go/TheRoleOfAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Go/TheRoleOfAlgorithms/README -------------------------------------------------------------------------------- /Go/makefile: -------------------------------------------------------------------------------- 1 | 2 | DIRS = GettingStarted Quicksort GreedyAlgorithms 3 | 4 | 5 | all: 6 | -for d in $(DIRS); do (cd $$d; go build -v); done 7 | 8 | install: 9 | -for d in $(DIRS); do (cd $$d; go install -v); done 10 | 11 | clean: 12 | -for d in $(DIRS); do (cd $$d; go clean); done 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Go/tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # put tests here! 4 | 5 | exit 0 6 | -------------------------------------------------------------------------------- /Go/vanEmdeBoasTrees/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Go/vanEmdeBoasTrees/README -------------------------------------------------------------------------------- /Homework/Fall2017/AlgGraphs.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Homework/Fall2017/AlgGraphs.pdf -------------------------------------------------------------------------------- /Homework/Fall2017/AlgHW3F2017.txt: -------------------------------------------------------------------------------- 1 | Homework 3: Dynamic and Greedy Programming 2 | 3 | 4 | Note: ^ means “raise to the power”. 5 | [NOTE ANY OTHER UNUSUAL NOTATION UP HERE!] 6 | 7 | 8 | [HERE ARE EXAMPLES OF THE FORMATS: YOU MUST FOLLOW THE FORMAT EXACTLY! IT IS A DUMB-ASSED COMPUTER THAT HAS TO READ THESE.] 9 | 10 | 11 | 1. (2 points) Question? 12 | a. Wrong answer 13 | *b. Correct answer 14 | c. Wrong answer 15 | d. Wrong answer 16 | 17 | 18 | 2. (1 point) All Xs are Ys. 19 | *False 20 | 21 | 22 | 4. (4 points) Some longer problem. -------------------------------------------------------------------------------- /Homework/Fall2017/Homework1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Homework/Fall2017/Homework1.pdf -------------------------------------------------------------------------------- /Homework/Fall2017/Homework2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Homework/Fall2017/Homework2.pdf -------------------------------------------------------------------------------- /Homework/Fall2017/Homework4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Homework/Fall2017/Homework4.pdf -------------------------------------------------------------------------------- /Homework/Fall2017/images/image1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Homework/Fall2017/images/image1.jpg -------------------------------------------------------------------------------- /Homework/Fall2017/images/image2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Homework/Fall2017/images/image2.png -------------------------------------------------------------------------------- /Homework/Fall2017/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Homework Sets Fall 2017 8 | 9 | 10 | 11 | 12 |

13 | Homework Sets Fall 2017 14 |

15 | 16 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /Java/AllPairsShortestPaths/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Java/AllPairsShortestPaths/README -------------------------------------------------------------------------------- /Java/AmortizedAnalysis/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Java/AmortizedAnalysis/README -------------------------------------------------------------------------------- /Java/ApproximationAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Java/ApproximationAlgorithms/README -------------------------------------------------------------------------------- /Java/AugmentingDataStructures/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Java/AugmentingDataStructures/README -------------------------------------------------------------------------------- /Java/BTrees/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Java/BTrees/README -------------------------------------------------------------------------------- /Java/BinarySearchTrees/Node.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by Zebin Xu. 3 | * A tree node structure for binary trees. 4 | */ 5 | 6 | package binarysearchtrees; 7 | 8 | public class Node { 9 | 10 | int key; 11 | T data; 12 | 13 | Node left; 14 | Node right; 15 | Node p; 16 | 17 | public Node(int key) { 18 | this(key, null); 19 | } 20 | 21 | public Node(int key, T data) { 22 | this.key = key; 23 | this.data = data; 24 | } 25 | } -------------------------------------------------------------------------------- /Java/BinarySearchTrees/Tree.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by Zebin Xu. 3 | * A binary tree structure with a root. 4 | */ 5 | 6 | package binarysearchtrees; 7 | 8 | public class Tree { 9 | Node root; 10 | } -------------------------------------------------------------------------------- /Java/ComputationalGeometry/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Java/ComputationalGeometry/README -------------------------------------------------------------------------------- /Java/DataStructuresForDisjointSets/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Java/DataStructuresForDisjointSets/README -------------------------------------------------------------------------------- /Java/DivideAndConquer/FindMaximumSubarrayTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by Zebin Xu. 3 | * Test findMaximumSubarray algorithm in the DivideAndConquer chapter. 4 | */ 5 | 6 | import static org.junit.Assert.assertEquals; 7 | import org.junit.Test; 8 | 9 | public class FindMaximumSubarrayTest { 10 | 11 | @Test public void testFindMaximumSubarray() { 12 | FindMaximumSubarray fms = new FindMaximumSubarray(); 13 | int[] array = {13, -3, -25, 20, -3, -16, -23, 18, 20, -7, 12, -5, -22, 15, -4, 7}; 14 | 15 | FindMaximumSubarray.Tuple max = fms.findMaximumSubarray(array); 16 | assertEquals(max.low, 7); 17 | assertEquals(max.high, 10); 18 | assertEquals(max.sum, 43); 19 | } 20 | } -------------------------------------------------------------------------------- /Java/DivideAndConquer/FindMaximumSubarrayTest.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # compile and run the unit test 3 | 4 | javac -cp ../test/junit-4.12.jar FindMaximumSubarray.java FindMaximumSubarrayTest.java 5 | 6 | java -cp .:../test/junit-4.12.jar:../test/hamcrest-core-1.3.jar org.junit.runner.JUnitCore FindMaximumSubarrayTest -------------------------------------------------------------------------------- /Java/ElementaryDataStructures/LinkedList/Node.java: -------------------------------------------------------------------------------- 1 | package LinkedList; 2 | 3 | /** 4 | * Created by prashant on 5/21/2017. 5 | */ 6 | public class Node{ 7 | int data; 8 | Node next; 9 | 10 | Node(int data){ 11 | this.data=data; 12 | } 13 | 14 | Node(){} 15 | } 16 | -------------------------------------------------------------------------------- /Java/ElementaryDataStructures/Queue.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | 3 | /** 4 | * Created by Prashantkumar Patel on 3/30/2017. 5 | */ 6 | public class Queue { 7 | 8 | int q[]; 9 | int head; 10 | int tail; 11 | 12 | public Queue(int size){ 13 | q=new int[size]; 14 | head=0; 15 | tail=0; 16 | } 17 | 18 | public void enqueue(int x){ 19 | q[tail]=x; 20 | 21 | if(tail==q.length-1){ 22 | tail=0; 23 | }else { 24 | tail=tail+1; 25 | } 26 | } 27 | 28 | public int dequeue(){ 29 | int x=q[head]; 30 | 31 | if(head==q.length-1){ 32 | head=0; 33 | }else { 34 | head=head+1; 35 | } 36 | 37 | return x; 38 | } 39 | 40 | 41 | @Override 42 | public String toString() { 43 | return "Queue{" + 44 | "q=" + Arrays.toString(q) + 45 | ", head=" + head + 46 | ", tail=" + tail + 47 | '}'; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Java/ElementaryDataStructures/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Java/ElementaryDataStructures/README -------------------------------------------------------------------------------- /Java/ElementaryDataStructures/Stack.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | 3 | /** 4 | * Created by Prashantkumar Patel on 3/30/2017. 5 | */ 6 | public class Stack { 7 | 8 | 9 | int[] s; 10 | int top=-1; 11 | 12 | public Stack(int size){ 13 | s=new int[size]; 14 | top=-1; 15 | } 16 | 17 | public boolean stackEmpty(){ 18 | return (top==-1); 19 | } 20 | 21 | public void push(int x) throws Exception{ 22 | if(top==s.length-1){ 23 | throw new Exception("Stack Overflow"); 24 | } 25 | top=top+1; 26 | s[top]=x; 27 | } 28 | 29 | public int pop() throws Exception{ 30 | if(stackEmpty()){ 31 | throw new Exception("Stack Underflow"); 32 | }else { 33 | top=top-1; 34 | return s[top+1]; 35 | } 36 | } 37 | 38 | @Override 39 | public String toString() { 40 | return "Stack{" + 41 | "s=" + Arrays.toString(s) + 42 | ", top=" + top + 43 | '}'; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Java/FibonacciHeaps/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Java/FibonacciHeaps/README -------------------------------------------------------------------------------- /Java/GraphAlgorithms/Color.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The state of the Vertex. 3 | */ 4 | 5 | package graphalgorithms; 6 | 7 | public enum Color { 8 | WHITE, 9 | GRAY, 10 | BLACK 11 | } -------------------------------------------------------------------------------- /Java/GraphAlgorithms/TopologicalSort.java: -------------------------------------------------------------------------------- 1 | package graphalgorithms; 2 | 3 | import java.util.List; 4 | import java.util.LinkedList; 5 | 6 | public class TopologicalSort extends DepthFirstSearch { 7 | 8 | private LinkedList topologicalSortList; 9 | 10 | public TopologicalSort() { 11 | this.topologicalSortList = new LinkedList<>(); 12 | } 13 | 14 | public List topologicalSort(Graph g) { 15 | dfs(g); 16 | return topologicalSortList; 17 | } 18 | 19 | @Override protected void dfsVisit(Graph g, Vertex u) { 20 | super.dfsVisit(g, u); 21 | topologicalSortList.addFirst(u); 22 | } 23 | } -------------------------------------------------------------------------------- /Java/GrowthOfFunctions/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Java/GrowthOfFunctions/README -------------------------------------------------------------------------------- /Java/HashTables/HashMapImplementation.java: -------------------------------------------------------------------------------- 1 | package hashtables; 2 | 3 | /** 4 | * Created by Prashant 5 | * As you can see in this program we have resolved the collision using chaining for two values 6 | * "Prashant" and "Patrick" 7 | */ 8 | public class HashMapImplementation { 9 | 10 | public static void main(String[] args){ 11 | 12 | HashMap map=new HashMap(); 13 | map.put("Nanda",Double.parseDouble("3474797289")); 14 | map.put("Prashant",Double.parseDouble("2012682695")); 15 | map.put("Patrick",Double.parseDouble("3474798289")); 16 | double phone_no_prashant=map.get("Prashant"); 17 | double phone_no_patrick=map.get("Patrick"); 18 | System.out.println("We are haiving collision with following two values but It will be resolved and we will get the correct output"); 19 | System.out.println("Key= Prashant"+" Value ="+String.valueOf(phone_no_prashant)); 20 | System.out.println("Key= Patrick"+" Value ="+String.valueOf(phone_no_patrick)); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Java/HashTables/OpenAddressing/DoubleHashing.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by prashant on 3/15/2017. 3 | */ 4 | 5 | package hashtables.openaddressing; 6 | 7 | public class DoubleHashing extends OpenAddressing { 8 | 9 | public DoubleHashing(int size){ 10 | super(size); 11 | } 12 | /** 13 | * 14 | * @param key: key fot hashfunction (h1) 15 | * @return integer hash index 16 | */ 17 | public int h1(Object key){ 18 | return key.hashCode(); 19 | } 20 | 21 | /** 22 | * 23 | * @param key : key for the hashfunction (h2) 24 | * @return integer hash index 25 | */ 26 | public int h2(Object key){ 27 | return 1+key.hashCode(); 28 | } 29 | 30 | 31 | /** 32 | * 33 | * @param k : Key to be hashed 34 | * @param i : index 35 | * @return the hash value 36 | */ 37 | @Override 38 | int hash(Object k, int i) { 39 | return ((h1(k)+i*h2(k))%size); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Java/HashTables/OpenAddressing/LinearProbing.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by prashant on 3/15/2017. 3 | */ 4 | 5 | package hashtables.openaddressing; 6 | 7 | public class LinearProbing extends OpenAddressing { 8 | 9 | /** 10 | *Created the Linear Probing class which extends the OpenAddressing Class 11 | *According to the textbook the hash function for the Linear Probing is 12 | * h(k,i) = (h'(k)+ i) mod m; 13 | * for the h'(k) we will use Java's default hash function that is hashCode(). 14 | * Although we can use any has function we want. 15 | */ 16 | 17 | public LinearProbing(int size){ 18 | super(size); 19 | } 20 | 21 | /** 22 | * 23 | * @param k : Key which is to be hashed. 24 | * @param i : Index 25 | * @return : Hash value 26 | */ 27 | @Override 28 | int hash(Object k, int i) { 29 | return (k.hashCode()+ i) % size; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Java/HashTables/OpenAddressing/QuadraticProbing.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by prashant on 3/15/2017. 3 | */ 4 | 5 | package hashtables.openaddressing; 6 | 7 | public class QuadraticProbing extends OpenAddressing { 8 | 9 | private int c1; 10 | private int c2; 11 | 12 | public QuadraticProbing(int c1,int c2,int size){ 13 | super(size); 14 | this.c1=c1; 15 | this.c2=c2; 16 | } 17 | 18 | /** 19 | * 20 | * @param k : Key to be hashed 21 | * @param i : index 22 | * @return the hash value 23 | */ 24 | @Override 25 | int hash(Object k, int i) { 26 | return ((k.hashCode() + c1*i +c1*i*i) % size); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Java/Heapsort/test/MaxHeapTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by Zebin Xu. 3 | * Test Heapsort algorithm for MaxHeap. 4 | */ 5 | 6 | import static org.junit.Assert.assertEquals; 7 | import org.junit.Test; 8 | import java.util.List; 9 | import java.util.ArrayList; 10 | import java.util.Arrays; 11 | import java.util.stream.Collectors; 12 | 13 | public class MaxHeapTest { 14 | 15 | @Test public void testHeapsort() { 16 | int[] array = {4, 1, 3, 2, 16, 9, 10, 14, 8, 7}; 17 | List heapArray = Arrays.stream(array).boxed().collect(Collectors.toList()); 18 | 19 | MaxHeap maxHeap = new MaxHeap(heapArray); 20 | maxHeap.sort(); 21 | 22 | int[] sortedArray = {1, 2, 3, 4, 7, 8, 9, 10, 14, 16}; 23 | assertEquals(maxHeap.toString(), Arrays.toString(sortedArray)); 24 | } 25 | } -------------------------------------------------------------------------------- /Java/Heapsort/test/MinHeapTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by Zebin Xu. 3 | * Test Heapsort algorithm for MinHeap. 4 | */ 5 | 6 | import static org.junit.Assert.assertEquals; 7 | import org.junit.Test; 8 | import java.util.List; 9 | import java.util.ArrayList; 10 | import java.util.Arrays; 11 | import java.util.stream.Collectors; 12 | 13 | public class MinHeapTest { 14 | 15 | @Test public void testHeapsort() { 16 | int[] array = {4, 1, 3, 2, 16, 9, 10, 14, 8, 7}; 17 | List heapArray = Arrays.stream(array).boxed().collect(Collectors.toList()); 18 | 19 | MinHeap minHeap = new MinHeap(heapArray); 20 | minHeap.sort(); 21 | 22 | int[] sortedArray = {16, 14, 10, 9, 8, 7, 4, 3, 2, 1}; 23 | assertEquals(minHeap.toString(), Arrays.toString(sortedArray)); 24 | } 25 | } -------------------------------------------------------------------------------- /Java/Heapsort/test/Test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # compile and run the unit tests for heapsort algorithm of MinHeap, MaxHeap. 3 | 4 | javac -cp :../../test/junit-4.12.jar ../Heap.java ../MinHeap.java ../MaxHeap.java MinHeapTest.java MaxHeapTest.java 5 | 6 | echo "[INFO] Running MaxHeapTest..." 7 | java -cp .:../:../../test/junit-4.12.jar:../../test/hamcrest-core-1.3.jar org.junit.runner.JUnitCore MaxHeapTest 8 | echo "[INFO] Running MinHeapTest..." 9 | java -cp .:../:../../test/junit-4.12.jar:../../test/hamcrest-core-1.3.jar org.junit.runner.JUnitCore MinHeapTest 10 | 11 | -------------------------------------------------------------------------------- /Java/LinearProgramming/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Java/LinearProgramming/README -------------------------------------------------------------------------------- /Java/MatrixOperations/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Java/MatrixOperations/README -------------------------------------------------------------------------------- /Java/MaximumFlow/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Java/MaximumFlow/README -------------------------------------------------------------------------------- /Java/MediansAndOrderStatistics/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Java/MediansAndOrderStatistics/README -------------------------------------------------------------------------------- /Java/MinimumSpanningTrees/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Java/MinimumSpanningTrees/README -------------------------------------------------------------------------------- /Java/MultithreadedAlgorithms/README: -------------------------------------------------------------------------------- 1 | # MultithreadedAlgorithms 2 | ## Running Examples 3 | ``` 4 | algorithms/Java$ javac MultithreadedAlgorithms/MultithreadedAlgorithms.java 5 | algorithms/Java$ java MultithreadedAlgorithms.MultithreadedAlgorithms 6 | ``` 7 | 8 | ## Running tests 9 | ``` 10 | algorithms/Java$ source tests.sh 11 | ``` -------------------------------------------------------------------------------- /Java/MultithreadedAlgorithms/tests/FibonacciTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by Zebin Xu on 8/22/17. 3 | */ 4 | 5 | package MultithreadedAlgorithms.tests; 6 | 7 | import static org.junit.Assert.assertEquals; 8 | import org.junit.Test; 9 | import MultithreadedAlgorithms.Fibonacci; 10 | 11 | public class FibonacciTest { 12 | 13 | // nth element means nth fibonacci number (n >= 0) 14 | private static final int[] fibonacciNumbers = new int[] { 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 }; 15 | 16 | @Test public void testFib() { 17 | Fibonacci fibonacci = new Fibonacci(); 18 | for (int i = 0; i < fibonacciNumbers.length; i++) { 19 | assertEquals(fibonacci.fib(i), fibonacciNumbers[i]); 20 | } 21 | } 22 | 23 | @Test public void testPFib() { 24 | Fibonacci fibonacci = new Fibonacci(); 25 | for (int i = 0; i < fibonacciNumbers.length; i++) { 26 | assertEquals(fibonacci.pFib(i), fibonacciNumbers[i]); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /Java/NPCompleteness/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Java/NPCompleteness/README -------------------------------------------------------------------------------- /Java/NumberTheoreticAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Java/NumberTheoreticAlgorithms/README -------------------------------------------------------------------------------- /Java/PolynomialsAndTheFFT/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Java/PolynomialsAndTheFFT/README -------------------------------------------------------------------------------- /Java/Quicksort/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Java/Quicksort/README -------------------------------------------------------------------------------- /Java/RedBlackTrees/README.md: -------------------------------------------------------------------------------- 1 | #Red-Black Tree
2 | A red-black tree is a binary search tree in which each node is colored red or black such that. The root is black. The children of a red node are black. Every path from the root to a 0-node or a 1-node has the same number of black nodes.
3 | #Input nodes: 4 | 5 | a,l,g,o,r,i,t,h,m,s 6 | 7 | 8 | #Output:(Not displaying the nill nodes) 9 | 10 | 11 | Inorder Traversal:element(node-color),(parent information):
12 | A(B),(left child of G)
13 | G(R),(left child of I)
14 | H(B),(right child of G)
15 | I(B),(root)
16 | L(B),(left child of O)
17 | M(R),(right child of L)
18 | O(R),(right child of I)
19 | R(R),(left child of S)
20 | S(B),(right child of O)
21 | T(R),(right child of S)
22 | -------------------------------------------------------------------------------- /Java/RedBlackTrees/com/tree/Node.java: -------------------------------------------------------------------------------- 1 | package com.tree; 2 | 3 | public class Node{ 4 | public int data; 5 | public Node left,right,parent; 6 | public int size,sum; 7 | public String color; 8 | public Node(int data){ 9 | this.data=data; 10 | this.left=null; 11 | this.right=null; 12 | this.parent=null; 13 | this.size=0; 14 | this.sum=0; 15 | this.color="B"; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Java/SingleSourceShortestPaths/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Java/SingleSourceShortestPaths/README -------------------------------------------------------------------------------- /Java/SortingInLinearTime/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Java/SortingInLinearTime/README -------------------------------------------------------------------------------- /Java/StringMatching/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Java/StringMatching/README -------------------------------------------------------------------------------- /Java/TheRoleOfAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Java/TheRoleOfAlgorithms/README -------------------------------------------------------------------------------- /Java/test/hamcrest-core-1.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Java/test/hamcrest-core-1.3.jar -------------------------------------------------------------------------------- /Java/test/junit-4.12.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Java/test/junit-4.12.jar -------------------------------------------------------------------------------- /Java/vanEmdeBoasTrees/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Java/vanEmdeBoasTrees/README -------------------------------------------------------------------------------- /Javascript/AllPairsShortestPaths/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Javascript/AllPairsShortestPaths/README -------------------------------------------------------------------------------- /Javascript/AmortizedAnalysis/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Javascript/AmortizedAnalysis/README -------------------------------------------------------------------------------- /Javascript/ApproximationAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Javascript/ApproximationAlgorithms/README -------------------------------------------------------------------------------- /Javascript/AugmentingDataStructures/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Javascript/AugmentingDataStructures/README -------------------------------------------------------------------------------- /Javascript/BTrees/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Javascript/BTrees/README -------------------------------------------------------------------------------- /Javascript/BinarySearchTrees/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Javascript/BinarySearchTrees/README -------------------------------------------------------------------------------- /Javascript/ComputationalGeometry/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Javascript/ComputationalGeometry/README -------------------------------------------------------------------------------- /Javascript/DataStructuresForDisjointSets/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Javascript/DataStructuresForDisjointSets/README -------------------------------------------------------------------------------- /Javascript/DivideAndConquer/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Javascript/DivideAndConquer/README -------------------------------------------------------------------------------- /Javascript/DynamicProgramming/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Javascript/DynamicProgramming/README -------------------------------------------------------------------------------- /Javascript/ElementaryDataStructures/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Javascript/ElementaryDataStructures/README -------------------------------------------------------------------------------- /Javascript/FibonacciHeaps/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Javascript/FibonacciHeaps/README -------------------------------------------------------------------------------- /Javascript/GettingStarted/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Javascript/GettingStarted/README -------------------------------------------------------------------------------- /Javascript/GraphAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Javascript/GraphAlgorithms/README -------------------------------------------------------------------------------- /Javascript/GreedyAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Javascript/GreedyAlgorithms/README -------------------------------------------------------------------------------- /Javascript/GrowthOfFunctions/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Javascript/GrowthOfFunctions/README -------------------------------------------------------------------------------- /Javascript/HashTables/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Javascript/HashTables/README -------------------------------------------------------------------------------- /Javascript/Heapsort/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Javascript/Heapsort/README -------------------------------------------------------------------------------- /Javascript/LinearProgramming/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Javascript/LinearProgramming/README -------------------------------------------------------------------------------- /Javascript/MatrixOperations/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Javascript/MatrixOperations/README -------------------------------------------------------------------------------- /Javascript/MaximumFlow/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Javascript/MaximumFlow/README -------------------------------------------------------------------------------- /Javascript/MediansAndOrderStatistics/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Javascript/MediansAndOrderStatistics/README -------------------------------------------------------------------------------- /Javascript/MinimumSpanningTrees/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Javascript/MinimumSpanningTrees/README -------------------------------------------------------------------------------- /Javascript/MultithreadedAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Javascript/MultithreadedAlgorithms/README -------------------------------------------------------------------------------- /Javascript/NPCompleteness/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Javascript/NPCompleteness/README -------------------------------------------------------------------------------- /Javascript/NumberTheoreticAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Javascript/NumberTheoreticAlgorithms/README -------------------------------------------------------------------------------- /Javascript/PolynomialsAndTheFFT/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Javascript/PolynomialsAndTheFFT/README -------------------------------------------------------------------------------- /Javascript/Quicksort/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Javascript/Quicksort/README -------------------------------------------------------------------------------- /Javascript/RandomizedAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Javascript/RandomizedAlgorithms/README -------------------------------------------------------------------------------- /Javascript/RedBlackTrees/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Javascript/RedBlackTrees/README -------------------------------------------------------------------------------- /Javascript/SingleSourceShortestPaths/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Javascript/SingleSourceShortestPaths/README -------------------------------------------------------------------------------- /Javascript/SortingInLinearTime/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Javascript/SortingInLinearTime/README -------------------------------------------------------------------------------- /Javascript/StringMatching/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Javascript/StringMatching/README -------------------------------------------------------------------------------- /Javascript/TheRoleOfAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Javascript/TheRoleOfAlgorithms/README -------------------------------------------------------------------------------- /Javascript/tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # put tests here! 4 | 5 | exit 0 6 | -------------------------------------------------------------------------------- /Javascript/vanEmdeBoasTrees/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Javascript/vanEmdeBoasTrees/README -------------------------------------------------------------------------------- /Python/AllPairsShortestPaths/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/AllPairsShortestPaths/README -------------------------------------------------------------------------------- /Python/AmortizedAnalysis/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/AmortizedAnalysis/README -------------------------------------------------------------------------------- /Python/ApproximationAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/ApproximationAlgorithms/README -------------------------------------------------------------------------------- /Python/ApproximationAlgorithms/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/ApproximationAlgorithms/__init__.py -------------------------------------------------------------------------------- /Python/ApproximationAlgorithms/test_approximation_algorithms.py: -------------------------------------------------------------------------------- 1 | #!/Users/gcallah/anaconda/bin/python3 2 | """ 3 | Test our heap code. 4 | """ 5 | 6 | from unittest import TestCase, main 7 | from utils.graph import Graph, Edge, graph_from_alist, test_alist 8 | from .approximation_algorithms import approx_vertex_cover 9 | 10 | 11 | class ApproximationTestCase(TestCase): 12 | def test_approx_vertex_cover(self): 13 | g = graph_from_alist(test_alist) 14 | cover_set = approx_vertex_cover(g) 15 | self.assertEqual(True, g.iscover(cover_set)) 16 | 17 | 18 | if __name__ == '__main__': 19 | main() 20 | -------------------------------------------------------------------------------- /Python/AugmentingDataStructures/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/AugmentingDataStructures/README -------------------------------------------------------------------------------- /Python/BTrees/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/BTrees/README -------------------------------------------------------------------------------- /Python/BinarySearchTrees/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/BinarySearchTrees/README -------------------------------------------------------------------------------- /Python/BinarySearchTrees/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Algorithms form the Binary Search Tree chapter of CLRS. 3 | """ 4 | -------------------------------------------------------------------------------- /Python/ComputationalGeometry/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/ComputationalGeometry/README -------------------------------------------------------------------------------- /Python/DataStructuresForDisjointSets/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/DataStructuresForDisjointSets/README -------------------------------------------------------------------------------- /Python/DivideAndConquer/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/DivideAndConquer/README -------------------------------------------------------------------------------- /Python/DivideAndConquer/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/DivideAndConquer/__init__.py -------------------------------------------------------------------------------- /Python/DynamicProgramming/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/DynamicProgramming/README -------------------------------------------------------------------------------- /Python/DynamicProgramming/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/DynamicProgramming/__init__.py -------------------------------------------------------------------------------- /Python/ElementaryDataStructures/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/ElementaryDataStructures/README -------------------------------------------------------------------------------- /Python/FibonacciHeaps/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/FibonacciHeaps/README -------------------------------------------------------------------------------- /Python/GettingStarted/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/GettingStarted/README -------------------------------------------------------------------------------- /Python/GettingStarted/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Algorithms form the Getting Started chapter of CLRS. 3 | """ 4 | -------------------------------------------------------------------------------- /Python/GraphAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/GraphAlgorithms/README -------------------------------------------------------------------------------- /Python/GraphAlgorithms/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/GraphAlgorithms/__init__.py -------------------------------------------------------------------------------- /Python/GreedyAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/GreedyAlgorithms/README -------------------------------------------------------------------------------- /Python/GreedyAlgorithms/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Algorithms form the Greedy Algorithms chapter of CLRS. 3 | """ 4 | -------------------------------------------------------------------------------- /Python/GrowthOfFunctions/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/GrowthOfFunctions/README -------------------------------------------------------------------------------- /Python/HashTables/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/HashTables/README -------------------------------------------------------------------------------- /Python/Heapsort/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/Heapsort/README -------------------------------------------------------------------------------- /Python/Heapsort/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/Heapsort/__init__.py -------------------------------------------------------------------------------- /Python/LinearProgramming/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/LinearProgramming/README -------------------------------------------------------------------------------- /Python/MatrixOperations/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/MatrixOperations/README -------------------------------------------------------------------------------- /Python/MaximumFlow/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/MaximumFlow/README -------------------------------------------------------------------------------- /Python/MediansAndOrderStatistics/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/MediansAndOrderStatistics/README -------------------------------------------------------------------------------- /Python/MediansAndOrderStatistics/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/MediansAndOrderStatistics/__init__.py -------------------------------------------------------------------------------- /Python/MinimumSpanningTrees/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/MinimumSpanningTrees/README -------------------------------------------------------------------------------- /Python/MinimumSpanningTrees/mst.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | This file contains Python implementations of 5 | approximation algorithms from Intro to Algorithms (Cormen et al.). 6 | The aim here is not efficient Python implementations 7 | but to duplicate the pseudo-code in the book as closely as possible. 8 | Also, since the goal is to help students to see how the algorithm 9 | works, there are print statements placed at key points in the code. 10 | The performance of each function is stated in the docstring, and 11 | loop invariants are expressed as assert statements when they 12 | are not too complex. 13 | This file contains: 14 | """ 15 | 16 | import random 17 | from utils.graph import Graph, Edge 18 | 19 | 20 | def mst_prim(g): 21 | """ 22 | Args: 23 | g: the graph for which we are creating a minimum spanning tree 24 | r: the root of the MST 25 | Return: 26 | ? 27 | """ 28 | -------------------------------------------------------------------------------- /Python/MultithreadedAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/MultithreadedAlgorithms/README -------------------------------------------------------------------------------- /Python/NPCompleteness/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/NPCompleteness/README -------------------------------------------------------------------------------- /Python/NumberTheoreticAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/NumberTheoreticAlgorithms/README -------------------------------------------------------------------------------- /Python/PolynomialsAndTheFFT/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/PolynomialsAndTheFFT/README -------------------------------------------------------------------------------- /Python/Quicksort/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/Quicksort/README -------------------------------------------------------------------------------- /Python/Quicksort/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/Quicksort/__init__.py -------------------------------------------------------------------------------- /Python/RandomizedAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/RandomizedAlgorithms/README -------------------------------------------------------------------------------- /Python/RedBlackTrees/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/RedBlackTrees/README -------------------------------------------------------------------------------- /Python/SingleSourceShortestPaths/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/SingleSourceShortestPaths/README -------------------------------------------------------------------------------- /Python/SortingInLinearTime/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/SortingInLinearTime/README -------------------------------------------------------------------------------- /Python/StringMatching/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/StringMatching/README -------------------------------------------------------------------------------- /Python/TheRoleOfAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/TheRoleOfAlgorithms/README -------------------------------------------------------------------------------- /Python/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/__init__.py -------------------------------------------------------------------------------- /Python/print_dups.py: -------------------------------------------------------------------------------- 1 | 2 | def print_dups(a): 3 | n = len(a) 4 | ichecks = [0] * n 5 | pair_checks = [[0 for i in range(n)] for j in range(n)] 6 | for i in range(n): 7 | assert ichecks[i] == 0 # we haven't checked this before 8 | ichecks[i] = 1 # now set that we HAVE checked this 9 | for j in range(i + 1, n): 10 | assert pair_checks[i][j] == 0 # we haven't checked this before 11 | pair_checks[i][j] = 1 # now set that we HAVE checked this 12 | if a[i] == a[j]: 13 | print(str(a[i])) 14 | -------------------------------------------------------------------------------- /Python/test_fibonacci.py: -------------------------------------------------------------------------------- 1 | #!/Users/gcallah/anaconda/bin/python3 2 | """ 3 | Test our sorting code. 4 | """ 5 | 6 | from unittest import TestCase, main 7 | import DivideAndConquer.fibonacci as fib 8 | 9 | fibs = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987] 10 | 11 | 12 | class FibonacciTestCase(TestCase): 13 | def test_naive(self): 14 | fnum = 13 15 | n = fib.naive_fib(fnum) 16 | self.assertEqual(fibs[fnum], n) 17 | 18 | def test_memo(self): 19 | fnum = 14 # might as well try different numbers 20 | n = fib.memo_fib(fnum) 21 | self.assertEqual(fibs[fnum], n) 22 | 23 | def test_iter(self): 24 | fnum = 11 # might as well try different numbers 25 | n = fib.iter_fib(fnum) 26 | self.assertEqual(fibs[fnum], n) 27 | 28 | def test_closed_form(self): 29 | fnum = 15 # might as well try different numbers 30 | n = fib.closed_form_fib(fnum) 31 | self.assertEqual(fibs[fnum], n) 32 | 33 | 34 | if __name__ == '__main__': 35 | main() 36 | -------------------------------------------------------------------------------- /Python/test_getting_started.py: -------------------------------------------------------------------------------- 1 | #!/Users/gcallah/miniconda/bin/python3 2 | """ 3 | Test our sorting code. 4 | """ 5 | 6 | from unittest import TestCase, main 7 | from GettingStarted.getting_started import merge_sort, insert_sort, bubble_sort 8 | from utils.test_utils import rand_list, assert_sorted 9 | 10 | NUM_TESTS = 10 11 | MAX_LIST = 100 12 | 13 | 14 | class SortingTestCase(TestCase): 15 | 16 | def test_merge(self): 17 | for j in range(NUM_TESTS): 18 | l = rand_list(max_list=MAX_LIST) 19 | l2 = merge_sort(l) 20 | assert_sorted(self, l2) 21 | 22 | def test_insert(self): 23 | for j in range(NUM_TESTS): 24 | l = rand_list(max_list=MAX_LIST) 25 | l2 = insert_sort(l) 26 | assert_sorted(self, l2) 27 | 28 | def test_bubble(self): 29 | for j in range(NUM_TESTS): 30 | l = rand_list(max_list=MAX_LIST) 31 | l2 = bubble_sort(l) 32 | assert_sorted(self, l2) 33 | 34 | if __name__ == '__main__': 35 | main() 36 | -------------------------------------------------------------------------------- /Python/test_greedy_algorithms.py: -------------------------------------------------------------------------------- 1 | #!/Users/gcallah/anaconda/bin/python3 2 | """ 3 | Test our heap code. 4 | """ 5 | 6 | from unittest import TestCase, main 7 | from GreedyAlgorithms.greedy_algorithms import recursive_activity_selector 8 | from GreedyAlgorithms.greedy_algorithms import greedy_activity_selector 9 | 10 | s = [0, 1, 3, 0, 5, 3, 5, 6, 8, 8, 2, 12] 11 | f = [0, 4, 5, 6, 7, 9, 9, 10, 11, 12, 14, 16] 12 | opt = [1, 4, 8, 11] 13 | 14 | 15 | class GreedyTestCase(TestCase): 16 | def test_recursive_activity_selector(self): 17 | out = recursive_activity_selector(s, f, 0, 12) 18 | self.assertEqual(out, opt) 19 | 20 | def test_greedy_activity_selector(self): 21 | out = greedy_activity_selector(s, f) 22 | self.assertEqual(out, opt) 23 | 24 | if __name__ == '__main__': 25 | main() 26 | -------------------------------------------------------------------------------- /Python/test_heapsort.py: -------------------------------------------------------------------------------- 1 | #!/Users/gcallah/anaconda/bin/python3 2 | """ 3 | Test our heap code. 4 | """ 5 | 6 | from unittest import TestCase, main 7 | from Heapsort.heapsort import heapsort, build_heap, heap_extract_extr 8 | from utils.test_utils import rand_list, assert_sorted 9 | 10 | NUM_TESTS = 10 11 | MAX_LIST = 100 12 | 13 | 14 | class HeapsortTestCase(TestCase): 15 | def test_heapsort(self): 16 | for j in range(NUM_TESTS): 17 | l = rand_list(max_list=MAX_LIST) 18 | 19 | # no return! 20 | heapsort(l) 21 | assert_sorted(self, l) 22 | 23 | def test_heap_extract_extr(self): 24 | for j in range(NUM_TESTS): 25 | l = rand_list(max_list=MAX_LIST) 26 | build_heap(l) # heapifies l in place 27 | out = [] 28 | for i in range(0, len(l)): 29 | out.append(heap_extract_extr(l)) 30 | 31 | for i in range(0, len(out) - 1): 32 | self.assertGreaterEqual(out[i], out[i + 1]) 33 | 34 | 35 | if __name__ == '__main__': 36 | main() 37 | -------------------------------------------------------------------------------- /Python/test_quicksort.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | """ 3 | Test our sorting code. 4 | """ 5 | 6 | from unittest import TestCase, main 7 | from Quicksort.quicksort import quicksort, hoare_partition 8 | from utils.test_utils import rand_list, assert_sorted 9 | 10 | NUM_TESTS = 100 11 | MAX_LIST = 100 12 | 13 | class QuicksortTestCase(TestCase): 14 | def test_quicksort(self): 15 | for j in range(NUM_TESTS): 16 | l = rand_list(max_list=MAX_LIST) 17 | 18 | # no return! 19 | quicksort(l, prnt=False) 20 | assert_sorted(self, l) 21 | 22 | """ 23 | def test_hoare(self): 24 | for j in range(10): 25 | l = rand_list(max_list=100) 26 | 27 | # no return! 28 | quicksort(l, partf=hoare_partition) 29 | self.assert_sorted(l) 30 | """ 31 | 32 | if __name__ == '__main__': 33 | main() 34 | -------------------------------------------------------------------------------- /Python/test_template.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | """ 3 | Template for testing a chapter's algorithms. 4 | """ 5 | 6 | from unittest import TestCase, main 7 | # from ChapNm.file import routines_to_test 8 | # you might want something from test_utils: 9 | # from utils.test_utils import rand_list, assert_sorted 10 | 11 | NUM_TESTS = 100 12 | 13 | class ChapNmTestCase(TestCase): 14 | def test_algorithm(self): 15 | return True 16 | 17 | if __name__ == '__main__': 18 | main() 19 | -------------------------------------------------------------------------------- /Python/tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Python tests 4 | 5 | function run_test { 6 | echo "Running $1 tests." 7 | $2 > /dev/null 8 | if [ "$?" != "0" ]; then 9 | echo "$1 test failure." 10 | exit 1 11 | fi 12 | } 13 | 14 | run_test "Getting Started" "python ./test_getting_started.py" 15 | run_test "Fibonacci" "python ./test_fibonacci.py" 16 | run_test "Heapsort" "python ./test_heapsort.py" 17 | run_test "Quicksort" "python ./test_quicksort.py" 18 | run_test "Binary Search Trees" "python ./test_binary_search_trees.py" 19 | run_test "Greedy Algorithms" "python ./test_greedy_algorithms.py" 20 | 21 | exit 0 22 | -------------------------------------------------------------------------------- /Python/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/utils/__init__.py -------------------------------------------------------------------------------- /Python/utils/misc.py: -------------------------------------------------------------------------------- 1 | """ 2 | Miscellaneous utilities used by Python algorithms code. 3 | """ 4 | 5 | import sys 6 | 7 | MAX_SENTINEL = sys.maxsize 8 | MIN_SENTINEL = -1 * sys.maxsize 9 | 10 | def swap(l, i, j): 11 | """ 12 | Since several sort algorithms need to swap list 13 | elements, we provide a swap function. 14 | 15 | Args: 16 | l: the list 17 | i, j: the indices of the elements to swap. 18 | """ 19 | temp = l[i] 20 | l[i] = l[j] 21 | l[j] = temp 22 | -------------------------------------------------------------------------------- /Python/utils/test_utils.py: -------------------------------------------------------------------------------- 1 | """ 2 | Utilities used by test programs. 3 | """ 4 | 5 | import random 6 | 7 | 8 | def rand_list(max_list=20, lrange=-1000, hrange=1000): 9 | # set up a random list of a random length 10 | return random.sample(range(lrange, hrange), random.randint(0, max_list)) 11 | 12 | def assert_sorted(testobj, l): 13 | for i in range(0, len(l) - 1): 14 | testobj.assertLessEqual(l[i], l[i + 1]) 15 | 16 | -------------------------------------------------------------------------------- /Python/vanEmdeBoasTrees/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Python/vanEmdeBoasTrees/README -------------------------------------------------------------------------------- /RegularityCondition.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/RegularityCondition.xlsx -------------------------------------------------------------------------------- /Ruby/AllPairsShortestPaths/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/AllPairsShortestPaths/README -------------------------------------------------------------------------------- /Ruby/AmortizedAnalysis/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/AmortizedAnalysis/README -------------------------------------------------------------------------------- /Ruby/ApproximationAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/ApproximationAlgorithms/README -------------------------------------------------------------------------------- /Ruby/AugmentingDataStructures/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/AugmentingDataStructures/README -------------------------------------------------------------------------------- /Ruby/BTrees/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/BTrees/README -------------------------------------------------------------------------------- /Ruby/BinarySearchTrees/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/BinarySearchTrees/README -------------------------------------------------------------------------------- /Ruby/BinarySearchTrees/node.rb: -------------------------------------------------------------------------------- 1 | # Public: Analogous to a struct in C/C++ for building linked lists. 2 | # This class only contains an initialize method which acts a constructor for 3 | # setting and accessing the object properties 4 | # 5 | # NOTE: Two constructors, one with satellite data and another without. The later 6 | # one will be used predominantly 7 | # 8 | # Examples 9 | # Node.new(10, "HELLO", nil, nil, nil) 10 | # # => # 11 | class Node 12 | attr_accessor :key, :satellite_data, :p, :left, :right 13 | def initialize(key, satellite_data, p, left, right) 14 | @key, @satellite_data, @p, @left, @right = key, satellite_data, p, left, right 15 | end 16 | 17 | # Node.new(10, nil, nil, nil) 18 | # # => # 19 | def initialize(key, p, left, right) 20 | @key, @p, @left, @right = key, p, left, right 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /Ruby/BinarySearchTrees/ruby_graphviz_images/Order 0 - Inserted F.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/BinarySearchTrees/ruby_graphviz_images/Order 0 - Inserted F.png -------------------------------------------------------------------------------- /Ruby/BinarySearchTrees/ruby_graphviz_images/Order 1 - Inserted B.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/BinarySearchTrees/ruby_graphviz_images/Order 1 - Inserted B.png -------------------------------------------------------------------------------- /Ruby/BinarySearchTrees/ruby_graphviz_images/Order 2 - Inserted G.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/BinarySearchTrees/ruby_graphviz_images/Order 2 - Inserted G.png -------------------------------------------------------------------------------- /Ruby/BinarySearchTrees/ruby_graphviz_images/Order 3 - Inserted A.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/BinarySearchTrees/ruby_graphviz_images/Order 3 - Inserted A.png -------------------------------------------------------------------------------- /Ruby/BinarySearchTrees/ruby_graphviz_images/Order 4 - Inserted D.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/BinarySearchTrees/ruby_graphviz_images/Order 4 - Inserted D.png -------------------------------------------------------------------------------- /Ruby/BinarySearchTrees/ruby_graphviz_images/Order 5 - Inserted C.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/BinarySearchTrees/ruby_graphviz_images/Order 5 - Inserted C.png -------------------------------------------------------------------------------- /Ruby/BinarySearchTrees/ruby_graphviz_images/Order 6 - Inserted E.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/BinarySearchTrees/ruby_graphviz_images/Order 6 - Inserted E.png -------------------------------------------------------------------------------- /Ruby/BinarySearchTrees/ruby_graphviz_images/Order 7 - Inserted I.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/BinarySearchTrees/ruby_graphviz_images/Order 7 - Inserted I.png -------------------------------------------------------------------------------- /Ruby/BinarySearchTrees/ruby_graphviz_images/Order 8 - Inserted H.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/BinarySearchTrees/ruby_graphviz_images/Order 8 - Inserted H.png -------------------------------------------------------------------------------- /Ruby/BinarySearchTrees/tree.rb: -------------------------------------------------------------------------------- 1 | # Public: Analogous to a struct in C/C++ for building linked lists. 2 | # This class only contains an initialize method which acts a constructor for 3 | # setting and accessing the object properties 4 | # 5 | # There are multiple ways this can be defined, this is my personal favorite 6 | # Other ways are listed at the bottom of the file 7 | # Choose whatever is convenient for YOU. 8 | # 9 | # Examples 10 | # Tree.new(nil) 11 | # # => # 12 | class Tree 13 | attr_accessor :root 14 | 15 | def initialize(root) 16 | @root = root 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /Ruby/BinarySearchTrees/unit_tests/insertion_deletion_test.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/BinarySearchTrees/unit_tests/insertion_deletion_test.rb -------------------------------------------------------------------------------- /Ruby/BinarySearchTrees/unit_tests/search_test.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/BinarySearchTrees/unit_tests/search_test.rb -------------------------------------------------------------------------------- /Ruby/ComputationalGeometry/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/ComputationalGeometry/README -------------------------------------------------------------------------------- /Ruby/DataStructuresForDisjointSets/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/DataStructuresForDisjointSets/README -------------------------------------------------------------------------------- /Ruby/DivideAndConquer/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/DivideAndConquer/README -------------------------------------------------------------------------------- /Ruby/DivideAndConquer/unit_tests/find_max_subarray_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../find_max_subarray' 2 | require 'minitest/autorun' 3 | 4 | class FindMaxSubarrayTest < Minitest::Test 5 | def test_find_max_crossing_subarray 6 | assert_equal(DivideAndConquer::find_max_crossing_subarray([-2, -3, 4, -1, -2, 1, 5, -3], 0, 3, 7), [2, 6, 7]) 7 | end 8 | 9 | def test_find_max_subarray 10 | assert_equal(DivideAndConquer::find_max_subarray([-2, -3, 4, -1, -2, 1, 5, -3]), [2, 6, 7]) 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /Ruby/DynamicProgramming/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/DynamicProgramming/README -------------------------------------------------------------------------------- /Ruby/DynamicProgramming/dynamic_programming_tests.sh: -------------------------------------------------------------------------------- 1 | ruby unit_tests/rod_cutting_test.rb 2 | ruby unit_tests/matrix_chain_multiplication_test.rb 3 | ruby unit_tests/lcs_test.rb 4 | ruby unit_tests/optimal_binary_search_tree_test.rb 5 | -------------------------------------------------------------------------------- /Ruby/DynamicProgramming/optimal_binary_search_tree.rb: -------------------------------------------------------------------------------- 1 | module DynamicProgramming 2 | class OBST 3 | class << self 4 | def optimal_bst(p, q, n) 5 | e = Array.new(n+2) { Array.new(n+1) } 6 | w = Array.new(n+2) { Array.new(n+1) } 7 | root = Array.new(n+1) { Array.new(n) } 8 | 9 | (1..n+1).each do |i| 10 | e[i][i-1] = q[i-1] 11 | w[i][i-1] = q[i-1] 12 | end 13 | 14 | (1..n).each do |l| 15 | (1..n-l+1).each do |i| 16 | j = i + l - 1 17 | e[i][j] = Float::INFINITY 18 | w[i][j] = w[i][j-1] + p[j] + q[j] 19 | (i..j).each do |r| 20 | t = e[i][r-1] + e[r+1][j] + w[i][j] 21 | if t < e[i][j] 22 | e[i][j] = t 23 | root[i][j] = r 24 | end 25 | end 26 | end 27 | end 28 | [e, root] 29 | end 30 | end 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /Ruby/DynamicProgramming/unit_tests/lcs_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../lcs' 2 | require 'minitest/autorun' 3 | 4 | class LCSTest < Minitest::Test 5 | def test_lcs_length 6 | x = "ABCBDAB" 7 | y = "BDCABA" 8 | assert_equal(DynamicProgramming::LCS.LCS_length(x, y).first[x.length][y.length], 4) 9 | end 10 | 11 | def test_lcs_print 12 | x = "ABCBDAB" 13 | y = "BDCABA" 14 | assert_equal(DynamicProgramming::LCS.print_LCS(DynamicProgramming::LCS.LCS_length(x, y).last, x, x.length, y.length), "BCBA") 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /Ruby/DynamicProgramming/unit_tests/matrix_chain_multiplication_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../matrix_chain_multiplication' 2 | require 'minitest/autorun' 3 | 4 | class MatrixChainMultiplicationTest < Minitest::Test 5 | def test_matrix_chain_order 6 | p = [30, 35, 15, 5, 10, 20, 25] # implies number of matrices = 6 = p.length - 1 7 | assert_equal(DynamicProgramming::MatrixChain.matrix_chain_order(p).first[0][p.length-2], 15125) 8 | end 9 | 10 | def test_recursive_matrix_chain 11 | p = [30, 35, 15, 5, 10, 20, 25] # implies number of matrices = 6 = p.length - 1 12 | assert_equal(DynamicProgramming::MatrixChain.recursive_matrix_chain(p, 0, p.length-2), 15125) 13 | end 14 | 15 | def test_memoized_matrix_chain 16 | p = [30, 35, 15, 5, 10, 20, 25] 17 | assert_equal(DynamicProgramming::MatrixChain.memoized_matrix_chain(p), 15125) 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /Ruby/DynamicProgramming/unit_tests/optimal_binary_search_tree_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../optimal_binary_search_tree' 2 | require 'minitest/autorun' 3 | 4 | class OptimalBinarySearchTreeTest < Minitest::Test 5 | def test_optimal_bst 6 | p = [0.00, 0.15, 0.10, 0.05, 0.10, 0.20] 7 | q = [0.05, 0.10, 0.05, 0.05, 0.05, 0.10] 8 | k = DynamicProgramming::OBST.optimal_bst(p, q, 5) 9 | assert_equal(k.first[1][5], 2.75) 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /Ruby/ElementaryDataStructures/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/ElementaryDataStructures/README -------------------------------------------------------------------------------- /Ruby/FibonacciHeaps/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/FibonacciHeaps/README -------------------------------------------------------------------------------- /Ruby/GettingStarted/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/GettingStarted/README -------------------------------------------------------------------------------- /Ruby/GettingStarted/insertion_sort.rb: -------------------------------------------------------------------------------- 1 | module GettingStarted 2 | # Internal: Sorts the elements of the array using INSERTION sort algorithm 3 | # 4 | # arr - Array of interger elements for now 5 | # 6 | # COMPLEXITY: Θ(n^2) 7 | # TODO: Update the code to handle any kind of datatype 8 | # 9 | # Examples 10 | # insertion_sort([5, 3, 8, 7, 9, 6, 2, 4, 1]) 11 | # => [1, 2, 3, 4, 5, 6, 7, 8, 9] 12 | # 13 | # Returns a sorted array. 14 | def self.insertion_sort(arr) 15 | for i in 1..arr.length-1 16 | j=i-1; 17 | key = arr[i] 18 | while j >= 0 && arr[j] > key 19 | arr[j+1] = arr[j] 20 | j = j-1 21 | end 22 | arr[j+1] = key 23 | end 24 | arr 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /Ruby/GettingStarted/unit_tests/bubble_sort_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../bubble_sort' 2 | require 'minitest/autorun' 3 | 4 | class BubbleSortTest < Minitest::Test 5 | def test_bubble_sort 6 | sorted_arr = [1, 2, 3, 4, 5, 6, 7, 8, 9] 7 | arr = [5, 3, 8, 7, 9, 6, 2, 4, 1] 8 | GettingStarted::bubble_sort(arr) 9 | assert_equal(arr, sorted_arr) 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /Ruby/GettingStarted/unit_tests/getting_started.sh: -------------------------------------------------------------------------------- 1 | ruby "./bubble_sort_test.rb" 2 | ruby "./insertion_sort_test.rb" 3 | ruby "./merge_sort_test.rb" 4 | -------------------------------------------------------------------------------- /Ruby/GettingStarted/unit_tests/insertion_sort_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../insertion_sort' 2 | require 'minitest/autorun' 3 | 4 | class InsertionSortTest < Minitest::Test 5 | def test_insertion_sort 6 | sorted_arr = [1, 2, 3, 4, 5, 6, 7, 8, 9] 7 | arr = [5, 3, 8, 7, 9, 6, 2, 4, 1] 8 | GettingStarted::insertion_sort(arr) 9 | assert_equal(arr, sorted_arr) 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /Ruby/GettingStarted/unit_tests/merge_sort_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../merge_sort' 2 | require 'minitest/autorun' 3 | 4 | class MergeSortTest < Minitest::Test 5 | def test_merge_sort 6 | sorted_arr = [1, 2, 3, 4, 5, 6, 7, 8, 9] 7 | arr = [5, 3, 8, 7, 9, 6, 2, 4, 1] 8 | GettingStarted::merge_sort(arr) 9 | assert_equal(arr, sorted_arr) 10 | end 11 | 12 | def test_merge 13 | arr = [5, 3, 8, 7, 9, 6, 2, 4, 1] 14 | GettingStarted::merge(arr, 0, 4, 8) 15 | assert_equal(arr, [5, 3, 6, 2, 4, 1, 8, 7, 9]) 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /Ruby/GraphAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/GraphAlgorithms/README -------------------------------------------------------------------------------- /Ruby/GraphAlgorithms/topological_sort.rb: -------------------------------------------------------------------------------- 1 | require_relative './depth_first_search' 2 | 3 | module Graphs 4 | class TopologicalSort 5 | class << self 6 | def topological_sort(g, searchable, topological) 7 | Graphs::DepthFirstSearch.DFS(g, nil, true) 8 | end 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /Ruby/GraphAlgorithms/unit_tests/breadth_first_search_test.rb: -------------------------------------------------------------------------------- 1 | require_relative './seed_graph' 2 | require_relative '../breadth_first_search' 3 | require 'minitest/autorun' 4 | 5 | class BreadthFirstSearchTest < Minitest::Test 6 | def test_bfs 7 | graph = SeedGraph.undirected_graph 8 | assert_equal(Graphs::BreadthFirstSearch.BFS(graph, graph.vertices.first, graph.vertices.last), "FOUND!!") 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /Ruby/GraphAlgorithms/unit_tests/depth_first_search_test.rb: -------------------------------------------------------------------------------- 1 | require_relative './seed_graph' 2 | require_relative '../depth_first_search' 3 | require 'minitest/autorun' 4 | 5 | class DepthFirstSearchTest < Minitest::Test 6 | def test_dfs 7 | graph = SeedGraph.undirected_graph 8 | assert_equal(Graphs::DepthFirstSearch.DFS(graph, graph.vertices.last), "FOUND!!") 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /Ruby/GraphAlgorithms/unit_tests/disjoint_set_test.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/GraphAlgorithms/unit_tests/disjoint_set_test.rb -------------------------------------------------------------------------------- /Ruby/GraphAlgorithms/unit_tests/graph_test.rb: -------------------------------------------------------------------------------- 1 | require_relative './seed_graph' 2 | require_relative '../graph' 3 | 4 | def graph_test 5 | 6 | end 7 | -------------------------------------------------------------------------------- /Ruby/GraphAlgorithms/unit_tests/minimum_spanning_tree_test.rb: -------------------------------------------------------------------------------- 1 | require_relative './seed_graph' 2 | require_relative '../minimum_spanning_tree' 3 | require 'minitest/autorun' 4 | 5 | class MinimumSpanningTreeTest < Minitest::Test 6 | def test_mst_kruskal 7 | graph = SeedGraph.kruskal_undirected_graph 8 | possible_solution_1 = [["g", "h"], ["c", "i"], ["f", "g"], ["c", "f"], ["a", "b"], ["c", "d"], ["b", "c"], ["d", "e"]] 9 | possible_solution_2 = [["g", "h"], ["f", "g"], ["c", "i"], ["a", "b"], ["c", "f"], ["c", "d"], ["h", "a"], ["d", "e"]] 10 | solution = Graphs::MinimumSpanningTree.MST_kruskal(graph).map { |x| [x.v1.key, x.v2.key] } 11 | assertion = (solution == possible_solution_1 || solution == possible_solution_2) 12 | assert_equal(assertion, true) 13 | end 14 | 15 | def test_mst_prim 16 | graph = SeedGraph.prim_undirected_graph 17 | Graphs::MinimumSpanningTree.MST_prim(graph, graph.vertices.first) 18 | assert_equal(graph.vertices.map { |x| x.d }, ["i", "b", "c", "d", "e", "f", "g", "h", "i"]) 19 | assert_equal(graph.vertices.map { |x| x.pi.d }, ["c", "a", "b", "c", "d", "c", "f", "g", "c"]) 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /Ruby/GraphAlgorithms/weighted_graph.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/GraphAlgorithms/weighted_graph.rb -------------------------------------------------------------------------------- /Ruby/GreedyAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/GreedyAlgorithms/README -------------------------------------------------------------------------------- /Ruby/GreedyAlgorithms/unit_tests/activity_selection_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../activity_selection' 2 | require 'minitest/autorun' 3 | 4 | class ActivitySelectionTest < Minitest::Test 5 | def test_recursive_activity_selector 6 | s = [0, 1, 3, 0, 5, 3, 5, 6, 8, 8, 2, 12] 7 | f = [0, 4, 5, 6, 7, 9, 9, 10, 11, 12, 14, 16] 8 | assert_equal(GreedyAlgorithms::ActivitySelection. 9 | recursive_activity_selector(s, f, 0, 11), [1, 4, 8, 11]) 10 | end 11 | 12 | def test_greedy_activity_selector 13 | s = [0, 1, 3, 0, 5, 3, 5, 6, 8, 8, 2, 12] 14 | f = [0, 4, 5, 6, 7, 9, 9, 10, 11, 12, 14, 16] 15 | assert_equal(GreedyAlgorithms::ActivitySelection. 16 | greedy_activity_selector(s, f), [1, 4, 8, 11]) 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /Ruby/GrowthOfFunctions/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/GrowthOfFunctions/README -------------------------------------------------------------------------------- /Ruby/HashTables/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/HashTables/README -------------------------------------------------------------------------------- /Ruby/HashTables/node.rb: -------------------------------------------------------------------------------- 1 | module Hashing 2 | # Public: Analogous to a struct in C/C++ for building linked lists. 3 | # This class only contains an initialize method which acts a constructor for 4 | # setting and accessing the object properties 5 | # 6 | # There are multiple ways this can be defined, this is my personal favorite 7 | # Other ways are listed at the bottom of the file 8 | # Choose whatever is convenient for YOU 9 | # 10 | # Examples 11 | # 12 | # Node.new(10, "HELLO", nil, nil) 13 | # # => # 14 | class Node 15 | attr_accessor :key, :satellite_data, :prev, :next 16 | # C/C++ too have this initialization technique but is less used in textbooks AFAIK 17 | def initialize(key, satellite_data, prev_pointer, next_pointer) 18 | @key, @satellite_data, @prev, @next = key, satellite_data, prev_pointer, next_pointer 19 | end 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /Ruby/HashTables/popular_hashes.rb: -------------------------------------------------------------------------------- 1 | def md5(str = "hello") 2 | 3 | end 4 | -------------------------------------------------------------------------------- /Ruby/HashTables/unit_tests/direct_addressing_test.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/HashTables/unit_tests/direct_addressing_test.rb -------------------------------------------------------------------------------- /Ruby/HashTables/unit_tests/open_addressing_test.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/HashTables/unit_tests/open_addressing_test.rb -------------------------------------------------------------------------------- /Ruby/Heapsort/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/Heapsort/README.md -------------------------------------------------------------------------------- /Ruby/Heapsort/monkey_patch.rb: -------------------------------------------------------------------------------- 1 | module MonkeyPatch 2 | # Public: In-Built Integer class override 3 | # Extended Integer class methods to get the feel of how much a pseudo code 4 | # can be related to interpreted code 5 | # Methods are invoked on an integer 6 | # 7 | # Examples 8 | # 9 | # 10.parent 10 | # => 5 11 | # 10.left 12 | # => 20 13 | # 10.right 14 | # => 21 15 | refine Integer do 16 | def parent 17 | ( self / 2 ).floor 18 | end 19 | 20 | def left 21 | ( 2 * self ) + 1 22 | end 23 | 24 | def right 25 | ( 2 * self ) + 2 26 | end 27 | 28 | def half 29 | ( self / 2 ).floor 30 | end 31 | end 32 | 33 | # Public: In-Built Array class override 34 | # Extended array class to add a method heap_size to be as close to the 35 | # textbook as possible 36 | # 37 | # Examples 38 | # 39 | # [1, 2, 3, 4].heap_size 40 | # => nil 41 | # [1, 2, 3, 4].heap_size = 10 42 | # [1, 2, 3, 4].heap_size 43 | # => 10 44 | refine Array do 45 | attr_accessor :heap_size 46 | end 47 | end 48 | -------------------------------------------------------------------------------- /Ruby/Heapsort/unit_tests/heap_sort_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../heap_sort' 2 | require 'minitest/autorun' 3 | 4 | class HeapSortTest < Minitest::Test 5 | def test_max_heap_sort 6 | sorted_arr = [1, 2, 3, 4, 5, 6, 7, 8, 9] 7 | arr = [5, 3, 8, 7, 9, 6, 2, 4, 1] 8 | Heap::max_heap_sort(arr) 9 | assert_equal(arr, sorted_arr) 10 | end 11 | 12 | def test_min_heap_sort 13 | sorted_arr = [9, 8, 7, 6, 5, 4, 3, 2, 1] 14 | arr = [5, 3, 8, 7, 9, 6, 2, 4, 1] 15 | Heap::min_heap_sort(arr) 16 | assert_equal(arr, sorted_arr) 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /Ruby/Heapsort/unit_tests/max_heap_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../max_heap' 2 | require_relative '../monkey_patch' 3 | 4 | using MonkeyPatch 5 | 6 | require 'minitest/autorun' 7 | 8 | class MaxHeapTest < Minitest::Test 9 | def test_max_heapify 10 | arr = [4, 1, 3, 2, 16, 9, 10, 14, 18, 7] 11 | assert_equal((arr[2] < arr[2.left]) && (arr[2] < arr[2.right]), true) 12 | Heap::MaxHeap.max_heapify(arr, 2) 13 | assert_equal((arr[2] > arr[2.left]) && (arr[2] > arr[2.right]), true) 14 | end 15 | 16 | def test_build_max_heap 17 | arr = [4, 1, 3, 2, 16, 9, 10, 14, 18, 7] 18 | assert(arr[0] != arr.max) 19 | Heap::MaxHeap.build_max_heap(arr) 20 | assert(arr[0] == arr.max) 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /Ruby/Heapsort/unit_tests/max_priority_queue_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../max_priority_queue' 2 | require_relative '../max_heap' 3 | require 'minitest/autorun' 4 | 5 | class MaxPrioriryQueue < Minitest::Test 6 | def test_heap_maximum 7 | arr = [4, 1, 3, 2, 16, 9, 10, 14, 18, 7] 8 | Heap::MaxHeap.build_max_heap(arr) 9 | assert_equal(Heap::MaxPriorityQueue.heap_maximum(arr), arr.max) 10 | end 11 | 12 | def test_heap_extract_max 13 | arr = [4, 1, 3, 2, 16, 9, 10, 14, 18, 7] 14 | Heap::MaxHeap.build_max_heap(arr) 15 | max = Heap::MaxPriorityQueue.heap_extract_max(arr) 16 | assert_equal(max, 18) 17 | max = Heap::MaxPriorityQueue.heap_extract_max(arr) 18 | assert_equal(max, 16) 19 | end 20 | 21 | def test_heap_increase_key 22 | 23 | end 24 | 25 | def test_max_heap_insert 26 | 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /Ruby/Heapsort/unit_tests/min_heap_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../min_heap' 2 | require_relative '../monkey_patch' 3 | require 'minitest/autorun' 4 | 5 | using MonkeyPatch 6 | 7 | class MinHeapTest < Minitest::Test 8 | def test_min_heapify 9 | arr = [5, 3, 8, 7, 9, 6, 2, 4, 1] 10 | assert_equal((arr[2] > arr[2.left]) && (arr[2] > arr[2.right]), true) 11 | Heap::MinHeap.min_heapify(arr, 2) 12 | assert_equal((arr[2] < arr[2.left]) && (arr[2] < arr[2.right]), true) 13 | end 14 | 15 | def test_build_min_heap 16 | arr = [4, 1, 3, 2, 16, 9, 10, 14, 18, 7] 17 | assert(arr[0] != arr.min) 18 | Heap::MinHeap.build_min_heap(arr) 19 | assert(arr[0] == arr.min) 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /Ruby/Heapsort/unit_tests/min_priority_queue_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../min_priority_queue' 2 | require_relative '../min_heap' 3 | require 'minitest/autorun' 4 | 5 | class MinPrioriryQueue < Minitest::Test 6 | def test_heap_minimum 7 | arr = [4, 1, 3, 2, 16, 9, 10, 14, 18, 7] 8 | Heap::MinHeap.build_min_heap(arr) 9 | assert_equal(Heap::MinPriorityQueue.heap_minimum(arr), arr.min) 10 | end 11 | 12 | def test_heap_extract_min 13 | arr = [4, 1, 3, 2, 16, 9, 10, 14, 18, 7] 14 | Heap::MinHeap.build_min_heap(arr) 15 | min = Heap::MinPriorityQueue.heap_extract_min(arr) 16 | assert_equal(min, 1) 17 | min = Heap::MinPriorityQueue.heap_extract_min(arr) 18 | assert_equal(min, 2) 19 | end 20 | 21 | def test_heap_decrease_key 22 | 23 | end 24 | 25 | def test_min_heap_insert 26 | 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /Ruby/LinearProgramming/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/LinearProgramming/README -------------------------------------------------------------------------------- /Ruby/MatrixOperations/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/MatrixOperations/README -------------------------------------------------------------------------------- /Ruby/MaximumFlow/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/MaximumFlow/README -------------------------------------------------------------------------------- /Ruby/MediansAndOrderStatistics/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/MediansAndOrderStatistics/README -------------------------------------------------------------------------------- /Ruby/MediansAndOrderStatistics/min_max.rb: -------------------------------------------------------------------------------- 1 | module MedianAndOrderStatistics 2 | class << self 3 | # Public: Returns the minimum number in an array. 4 | # 5 | # ARGS: 6 | # a - Input array 7 | # 8 | # RETURN: Number 9 | # NOTE: Ruby in-built method is array.min 10 | # 11 | # COMPLEXITY: Θ(n) 12 | # 13 | # Examples 14 | # minimum([4, 1, 3, 2, 16, 9, 10, 14, 18, 7]) 15 | # => 1 16 | def minimum(a) 17 | min = a[0] 18 | (1..a.length-1).each do |i| 19 | if a[i] < min 20 | min = a[i] 21 | end 22 | end 23 | min 24 | end 25 | 26 | # Public: Returns the maximum number in an array. 27 | # 28 | # ARGS: 29 | # a - Input array 30 | # 31 | # RETURN: Number 32 | # NOTE: Ruby in-built method is array.max 33 | # 34 | # COMPLEXITY: Θ(n) 35 | # 36 | # Examples 37 | # maximum([4, 1, 3, 2, 16, 9, 10, 14, 18, 7]) 38 | # => 18 39 | def maximum(a) 40 | max = a[0] 41 | (1..a.length-1).each do |i| 42 | if a[i] > max 43 | max = a[i] 44 | end 45 | end 46 | max 47 | end 48 | 49 | end 50 | end 51 | -------------------------------------------------------------------------------- /Ruby/MediansAndOrderStatistics/unit_tests/min_max_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../min_max' 2 | require 'minitest/autorun' 3 | 4 | class MinMaxTest < Minitest::Test 5 | def test_maximum 6 | arr = [4, 1, 3, 2, 16, 9, 10, 14, 18, 7] 7 | assert_equal(MedianAndOrderStatistics::maximum(arr), arr.max) 8 | end 9 | 10 | def test_minimum 11 | arr = [4, 1, 3, 2, 16, 9, 10, 14, 18, 7] 12 | assert_equal(MedianAndOrderStatistics::minimum(arr), arr.min) 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /Ruby/MediansAndOrderStatistics/unit_tests/randomized_select_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../randomized_select' 2 | require 'minitest/autorun' 3 | 4 | class RandomizedSelectTest < Minitest::Test 5 | def test_randomized_select 6 | arr = [4, 1, 3, 2, 16, 9, 10, 14, 18, 7] 7 | sorted_arr = arr.sort 8 | (1..sorted_arr.length).each do |i| 9 | assert_equal(MedianAndOrderStatistics::randomized_select(arr, 0, 9, i), sorted_arr[i-1]) 10 | end 11 | end 12 | 13 | def test_randomized_select_iterative 14 | arr = [4, 1, 3, 2, 16, 9, 10, 14, 18, 7] 15 | sorted_arr = arr.sort 16 | (1..sorted_arr.length).each do |i| 17 | assert_equal(MedianAndOrderStatistics::randomized_select_iterative(arr, 0, 9, i), sorted_arr[i-1]) 18 | end 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /Ruby/MinimumSpanningTrees/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/MinimumSpanningTrees/README -------------------------------------------------------------------------------- /Ruby/MultithreadedAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/MultithreadedAlgorithms/README -------------------------------------------------------------------------------- /Ruby/NPCompleteness/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/NPCompleteness/README -------------------------------------------------------------------------------- /Ruby/NumberTheoreticAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/NumberTheoreticAlgorithms/README -------------------------------------------------------------------------------- /Ruby/PolynomialsAndTheFFT/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/PolynomialsAndTheFFT/README -------------------------------------------------------------------------------- /Ruby/Quicksort/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/Quicksort/README.md -------------------------------------------------------------------------------- /Ruby/Quicksort/unit_tests/quick_sort_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../quick_sort' 2 | require 'minitest/autorun' 3 | 4 | class QuickSortTest < Minitest::Test 5 | def test_quick_sort 6 | sorted_arr = [1, 2, 3, 4, 5, 6, 7, 8, 9] 7 | arr = [5, 3, 8, 7, 9, 6, 2, 4, 1] 8 | Quicksort::quick_sort(arr) 9 | assert_equal(arr, sorted_arr) 10 | end 11 | 12 | def test_hoare_parition_quick_sort 13 | sorted_arr = [1, 2, 3, 4, 5, 6, 7, 8, 9] 14 | arr = [5, 3, 8, 7, 9, 6, 2, 4, 1] 15 | Quicksort::tail_recursive_quick_sort(arr, 0, 8, 'hoare_partition') 16 | assert_equal(arr, sorted_arr) 17 | end 18 | 19 | def test_partition 20 | arr = [1, 3, 8, 7, 9, 6, 2, 4, 5] 21 | partition_index = Quicksort::partition(arr, 0, 8) 22 | assert_equal(partition_index, 4) 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /Ruby/Quicksort/unit_tests/randomized_quick_sort_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../randomized_quick_sort' 2 | require 'minitest/autorun' 3 | 4 | class RandomizedQuickSortTest < Minitest::Test 5 | def test_randomized_quick_sort 6 | sorted_arr = [1, 2, 3, 4, 5, 6, 7, 8, 9] 7 | arr = [5, 3, 8, 7, 9, 6, 2, 4, 1] 8 | Quicksort::randomized_quick_sort(arr) 9 | assert_equal(arr, sorted_arr) 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /Ruby/Quicksort/unit_tests/tail_recursive_quick_sort_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../tail_recursive_quick_sort' 2 | require 'minitest/autorun' 3 | 4 | class TailRecursiveQuickSortTest < Minitest::Test 5 | def test_tail_recursive_quick_sort 6 | sorted_arr = [1, 2, 3, 4, 5, 6, 7, 8, 9] 7 | arr = [5, 3, 8, 7, 9, 6, 2, 4, 1] 8 | Quicksort::tail_recursive_quick_sort(arr) 9 | assert_equal(arr, sorted_arr) 10 | end 11 | 12 | def test_normal_parition_tail_recursive_quick_sort 13 | sorted_arr = [1, 2, 3, 4, 5, 6, 7, 8, 9] 14 | arr = [5, 3, 8, 7, 9, 6, 2, 4, 1] 15 | Quicksort::tail_recursive_quick_sort(arr, 0, 8, 'partition') 16 | assert_equal(arr, sorted_arr) 17 | end 18 | 19 | def test_hoare_partition 20 | arr = [5, 3, 8, 7, 9, 6, 2, 4, 1] 21 | partition_index = Quicksort::hoare_partition(arr, 0, 8) 22 | assert_equal(partition_index, 4) 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /Ruby/RandomizedAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/RandomizedAlgorithms/README -------------------------------------------------------------------------------- /Ruby/RandomizedAlgorithms/unit_tests/hire_assistant_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../hire_assistant' 2 | require 'minitest/autorun' 3 | 4 | class HireAssistantTest < Minitest::Test 5 | def test_hire_assistant 6 | candidates = [0, 9, 2, 15, 17, 9, 10, 20] 7 | hired_candidates = RandomizedAlgorithms::hire_assistant(candidates) 8 | assert_equal(hired_candidates, [1, 3, 4, 7]) 9 | end 10 | 11 | def test_randomized_hire_assistant 12 | candidates = [0, 9, 2, 15, 17, 9, 10, 20] 13 | first_run_hired = RandomizedAlgorithms::randomized_hire_assistant(candidates) 14 | candidates = [0, 9, 2, 15, 17, 9, 10, 20] 15 | second_run_hired = RandomizedAlgorithms::randomized_hire_assistant(candidates) 16 | assert(first_run_hired != second_run_hired) 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /Ruby/RandomizedAlgorithms/unit_tests/permuting_arrays_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../permuting_arrays' 2 | require 'minitest/autorun' 3 | 4 | class PermutingArraysTest < Minitest::Test 5 | def test_permute_by_sorting 6 | 7 | end 8 | 9 | def test_randomize_in_place 10 | end 11 | 12 | def test_permute_without_identity 13 | end 14 | 15 | def test_permute_with_all 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /Ruby/RedBlackTrees/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/RedBlackTrees/README -------------------------------------------------------------------------------- /Ruby/SingleSourceShortestPaths/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/SingleSourceShortestPaths/README -------------------------------------------------------------------------------- /Ruby/SortingInLinearTime/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/SortingInLinearTime/README -------------------------------------------------------------------------------- /Ruby/SortingInLinearTime/bucket_sort.rb: -------------------------------------------------------------------------------- 1 | require_relative '../GettingStarted/insertion_sort' 2 | 3 | module SortingInLinearTime 4 | class << self 5 | # Public: Distribute the elements of an array into a number of buckets. 6 | # Each bucket is then sorted individually, either using a different 7 | # sorting algorithm, or by recursively applying the bucket sorting 8 | # algorithm 9 | # 10 | # ARGS: 11 | # a - Input array 12 | # 13 | # RETURN: Sorted array 14 | # 15 | # COMPLEXITY: Θ(n) 16 | # 17 | # Examples 18 | # bucket_sort([0.78, 0.17, 0.39, 0.26, 0.72, 0.94, 0.21, 0.12, 0.23, 0.68]) 19 | # => [0.12, 0.17, 0.21, 0.23, 0.26, 0.39, 0.68, 0.72, 0.78, 0.94] 20 | def bucket_sort(a, n=10) 21 | b = Array.new(n) 22 | n = a.length 23 | 24 | b = n.times.map { |i| [] } 25 | 26 | (0..n-1).each do |i| 27 | b[(n*a[i]).floor] << a[i] 28 | end 29 | 30 | (0..n-1).each do |i| 31 | GettingStarted::insertion_sort(b[i]) 32 | end 33 | 34 | b.flatten 35 | end 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /Ruby/SortingInLinearTime/unit_tests/bucket_sort_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../bucket_sort' 2 | require 'minitest/autorun' 3 | 4 | class BucketSortTest < Minitest::Test 5 | def test_bucket_sort 6 | arr = [0.78, 0.17, 0.39, 0.26, 0.72, 0.94, 0.21, 0.12, 0.23, 0.68] 7 | sorted_arr = [0.12, 0.17, 0.21, 0.23, 0.26, 0.39, 0.68, 0.72, 0.78, 0.94] 8 | assert_equal(SortingInLinearTime::bucket_sort(arr), sorted_arr) 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /Ruby/SortingInLinearTime/unit_tests/counting_sort_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../counting_sort' 2 | require 'minitest/autorun' 3 | 4 | class CountingSortTest < Minitest::Test 5 | def test_counting_sort 6 | sorted_arr = [0, 0, 2, 2, 3, 3, 3, 5] 7 | a = [2, 5, 3, 0, 2, 3, 0, 3] 8 | b = [] 9 | k = 5 10 | 11 | SortingInLinearTime::counting_sort(a, b, 18) 12 | assert_equal(b, sorted_arr) 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /Ruby/SortingInLinearTime/unit_tests/radix_sort_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../radix_sort' 2 | require 'minitest/autorun' 3 | 4 | class RadixSortTest < Minitest::Test 5 | def test_radix_sort 6 | arr = [329, 457, 657, 839, 436, 720, 355] 7 | sorted_arr = [329, 355, 436, 457, 657, 720, 839] 8 | assert_equal(SortingInLinearTime::radix_sort(arr, 3), sorted_arr) 9 | end 10 | 11 | def test_radix_sort_unstable 12 | arr = [329, 457, 657, 839, 436, 720, 355] 13 | sorted_arr = [329, 355, 436, 457, 657, 720, 839] 14 | assert_equal(SortingInLinearTime::radix_sort_unstable(arr, 3), sorted_arr) 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /Ruby/StringMatching/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/StringMatching/README -------------------------------------------------------------------------------- /Ruby/TheRoleOfAlgorithms/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/TheRoleOfAlgorithms/README -------------------------------------------------------------------------------- /Ruby/tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # put tests here! 4 | rake test 5 | if [ $? -eq 0 ]; then 6 | echo OK 7 | else 8 | exit 1 9 | fi 10 | -------------------------------------------------------------------------------- /Ruby/travis_test.rb: -------------------------------------------------------------------------------- 1 | require "minitest/autorun" 2 | 3 | class TravisTest < Minitest::Test 4 | def test_travis 5 | assert_equal 1, 1 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /Ruby/utils.rb: -------------------------------------------------------------------------------- 1 | module Utils 2 | # Internal: Swap two elements in an array - THE RUBY WAY 3 | # 4 | # arr - Array of integer elements 5 | # v1 - Location of element in the array 6 | # v2 - Location of element in the array 7 | # 8 | # Examples 9 | # swap([5, 3, 8, 7, 9, 6, 2, 4, 1], 2, 5) 10 | # => [5, 3, 6, 7, 9, 8, 2, 4, 1] 11 | # 12 | self.def cool_swap(arr, v1, v2) 13 | arr[v1], arr[v2] = arr[v2], arr[v1] 14 | end 15 | 16 | # Internal: Swap two elements in an array 17 | # 18 | # arr - Array of integer elements 19 | # v1 - Location of element in the array 20 | # v2 - Location of element in the array 21 | # 22 | # Examples 23 | # swap([5, 3, 8, 7, 9, 6, 2, 4, 1], 2, 5) 24 | # => [5, 3, 6, 7, 9, 8, 2, 4, 1] 25 | # 26 | self.def swap(arr, v1, v2) 27 | temp = arr[v1] 28 | arr[v1] = arr[v2] 29 | arr[v2] = temp 30 | end 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /Ruby/vanEmdeBoasTrees/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Ruby/vanEmdeBoasTrees/README -------------------------------------------------------------------------------- /Syllabus2017F.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Syllabus2017F.docx -------------------------------------------------------------------------------- /Union-FindClassPresentation.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/Union-FindClassPresentation.pdf -------------------------------------------------------------------------------- /checked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/checked.png -------------------------------------------------------------------------------- /cross.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/cross.png -------------------------------------------------------------------------------- /gen_dirs.awk: -------------------------------------------------------------------------------- 1 | #!/usr/bin/awk -f 2 | 3 | # This program generates the program dirs for the Algorithm Museum's languages. 4 | # It reads langs.txt to get the language list, and stdin for the chapter names. 5 | 6 | BEGIN { 7 | file = "langs.txt"; 8 | while((getline < file ) > 0 ) { 9 | langs[$1] = 1 # record each language 10 | } 11 | } 12 | 13 | /^$/ { } # blank lines allowed 14 | 15 | /^\;/ { } # allows comments in the chapter file 16 | 17 | /^[IVXCM]/ { } # skip the major section names (Roman numberals) 18 | 19 | /^[0-9]/ { # this is a chapter name 20 | print $2 21 | for( lang in langs ) { 22 | new_dir = lang "/" $2 23 | if (system( "[ -d " new_dir " ] ") == 0) 24 | print new_dir " already exists." 25 | else { 26 | print "We are going to add " new_dir 27 | if (system( "mkdir " new_dir) == 0) { 28 | system( "touch " new_dir "/README.md") 29 | system( "git add " new_dir "/README.md") 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /gen_md.awk: -------------------------------------------------------------------------------- 1 | #!/usr/bin/awk -f 2 | 3 | # This program generates the program dirs for the Algorithm Museum's languages. 4 | # It reads langs.txt to get the language list, and stdin for the chapter names. 5 | 6 | BEGIN { 7 | header = "| CHAPTER |" 8 | separator = "| :---: |" 9 | file = "langs.txt"; 10 | while((getline < file ) > 0 ) { 11 | langs[$1] = 1 # record each language 12 | } 13 | for (lang in langs) { 14 | header = header " " lang " |" 15 | separator = separator " :---: |" 16 | } 17 | print header 18 | print separator 19 | } 20 | 21 | /^[0-9]/ { # this is a chapter name 22 | k = " | **" $2 "** | " 23 | for( lang in langs ) { 24 | dir = lang "/" $2 25 | cmd = "ls " dir " | egrep -v 'README' | awk 'END{print NR}'" 26 | cmd | getline x 27 | close(cmd) 28 | if (x == 0) { 29 | k = k " |" 30 | } else { 31 | k = k " |" 32 | } 33 | } 34 | print k 35 | } 36 | -------------------------------------------------------------------------------- /graphics/4TRec.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/4TRec.gif -------------------------------------------------------------------------------- /graphics/AdjList.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/AdjList.png -------------------------------------------------------------------------------- /graphics/AdjMatrix.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/AdjMatrix.png -------------------------------------------------------------------------------- /graphics/Big-O-notation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/Big-O-notation.png -------------------------------------------------------------------------------- /graphics/BinTree1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/BinTree1.png -------------------------------------------------------------------------------- /graphics/BinTree2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/BinTree2.png -------------------------------------------------------------------------------- /graphics/Board.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/Board.jpg -------------------------------------------------------------------------------- /graphics/CommonSubsequence.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/CommonSubsequence.png -------------------------------------------------------------------------------- /graphics/EdgeList.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/EdgeList.png -------------------------------------------------------------------------------- /graphics/EqCaseRec.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/EqCaseRec.gif -------------------------------------------------------------------------------- /graphics/GraphForFinal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/GraphForFinal.png -------------------------------------------------------------------------------- /graphics/GraphForFinal2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/GraphForFinal2.png -------------------------------------------------------------------------------- /graphics/GraphForFinal3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/GraphForFinal3.png -------------------------------------------------------------------------------- /graphics/GraphForFinal4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/GraphForFinal4.png -------------------------------------------------------------------------------- /graphics/GraphsEq1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/GraphsEq1.gif -------------------------------------------------------------------------------- /graphics/H3Eq1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/H3Eq1.gif -------------------------------------------------------------------------------- /graphics/H3Eq2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/H3Eq2.gif -------------------------------------------------------------------------------- /graphics/H3Eq3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/H3Eq3.gif -------------------------------------------------------------------------------- /graphics/H3Eq4.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/H3Eq4.gif -------------------------------------------------------------------------------- /graphics/H3Eq5.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/H3Eq5.gif -------------------------------------------------------------------------------- /graphics/H3Eq6.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/H3Eq6.gif -------------------------------------------------------------------------------- /graphics/H3Eq7.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/H3Eq7.gif -------------------------------------------------------------------------------- /graphics/Huffman.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/Huffman.png -------------------------------------------------------------------------------- /graphics/Julia.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/Julia.png -------------------------------------------------------------------------------- /graphics/Kruskal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/Kruskal.png -------------------------------------------------------------------------------- /graphics/Kruskal2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/Kruskal2.jpg -------------------------------------------------------------------------------- /graphics/Lec3Eq1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/Lec3Eq1.gif -------------------------------------------------------------------------------- /graphics/Lec3Eq2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/Lec3Eq2.gif -------------------------------------------------------------------------------- /graphics/Lec3Eq3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/Lec3Eq3.gif -------------------------------------------------------------------------------- /graphics/Lec3Eq4.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/Lec3Eq4.gif -------------------------------------------------------------------------------- /graphics/Lec3Eq5.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/Lec3Eq5.gif -------------------------------------------------------------------------------- /graphics/Lec3Eq6.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/Lec3Eq6.gif -------------------------------------------------------------------------------- /graphics/LinearityOfExp.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/LinearityOfExp.gif -------------------------------------------------------------------------------- /graphics/MatrixChainRun.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/MatrixChainRun.png -------------------------------------------------------------------------------- /graphics/MatroidGraph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/MatroidGraph.png -------------------------------------------------------------------------------- /graphics/MatroidMatching.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/MatroidMatching.png -------------------------------------------------------------------------------- /graphics/MatroidVectors.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/MatroidVectors.png -------------------------------------------------------------------------------- /graphics/MinSpanTree1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/MinSpanTree1.png -------------------------------------------------------------------------------- /graphics/MinSpanTree2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/MinSpanTree2.png -------------------------------------------------------------------------------- /graphics/NSquaredRec.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/NSquaredRec.gif -------------------------------------------------------------------------------- /graphics/NSquaredTree1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/NSquaredTree1.png -------------------------------------------------------------------------------- /graphics/NSquaredTree2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/NSquaredTree2.png -------------------------------------------------------------------------------- /graphics/Notations.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/Notations.png -------------------------------------------------------------------------------- /graphics/PolynomialLine.xml: -------------------------------------------------------------------------------- 1 | 7VhNj5swEP01OVbiK8AeN+mmvVSquoeejRnAWoNTY5psf30HMN+OkibpqpU2l8CzPR6/95gJWbnb/PhJkn32RcTAV44VH1fux5Xj2P6DhV818toiD4HXAqlksZ40AM/sF2hQr0srFkM5maiE4IrtpyAVRQFUTTAipThMpyWCT3fdkxQWwDMlfIl+Z7HKWjRcWwP+GViadTvblh6JCH1JpagKvd/KcZPm0w7npIul55cZicVhBLlPK3crhVDtVX7cAq+57Whr1+1OjPZ5SyjUJQu0LD8Jr6DLuMlLvXZccFbg1aZUUrz0bGCim5hJ5J6JAu9LUdX4JlM5x1sbL3VkkAqOJ7Oz+zOjl0DkoOQrTtELvI6mzkb69jBo0jkmG8nhaYxoF6R94IEJvNBkmInxzxMDRfxYew3vKCdlyeiUgCljXk8JxAvznSVkdOK14cQdJoETxX5Ow5to0Dt8FQw3HvG9nvBt2zMmUWZJQa8a22oWyPbOBFJEpqAWgRpV+mNfJFTwLtQNQgXWmwn1YBDK58jLJhFNSoNi/o9KdAMfyqY7POIE190fh0G8SuvvoguDCbSRWryDy2p/SXDHNwXnIh2Fb0LNo0fXR48msaO7Zk5O5T17OLA6K9PjsBVcSEQK0ZT/hHE+gwhnaV37KT4TgPimrvUMm+ijHshZHNfbbA4ZU/C8J7Te84A/GWbd4wDlkNttHWPm52DZMTzDY+ncoWPY9t+oRGPe8cdETCBM6EIkHPFpCFGCI6kkMUO6RmMBEB+s/6GuhdOGb/vX1jX7TKD71TXbeQPdk5ACNeoehWtvbZl1R9kj379J9+OMvzmfF/ricgu497KA7b2dBdybe5vjmYr4N6CVLOsiie9SImcFUfhadKrf/SOVvU5qZMLdzsXPfcr7QtNwaUOjD+faX1XgTS9LE5Vpf+pByPrwbv3+N0DXumFXFW3HfDeDsVkE66UZXIMZgj83A94OL+VthRj++XCffgM= -------------------------------------------------------------------------------- /graphics/RandEq1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/RandEq1.gif -------------------------------------------------------------------------------- /graphics/RandEq10.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/RandEq10.gif -------------------------------------------------------------------------------- /graphics/RandEq2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/RandEq2.gif -------------------------------------------------------------------------------- /graphics/RandEq3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/RandEq3.gif -------------------------------------------------------------------------------- /graphics/RandEq4.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/RandEq4.gif -------------------------------------------------------------------------------- /graphics/RandEq5.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/RandEq5.gif -------------------------------------------------------------------------------- /graphics/RandEq6.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/RandEq6.gif -------------------------------------------------------------------------------- /graphics/RandEq7.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/RandEq7.gif -------------------------------------------------------------------------------- /graphics/RandEq8.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/RandEq8.gif -------------------------------------------------------------------------------- /graphics/RandEq9.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/RandEq9.gif -------------------------------------------------------------------------------- /graphics/RecEq1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/RecEq1.gif -------------------------------------------------------------------------------- /graphics/RecEq2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/RecEq2.gif -------------------------------------------------------------------------------- /graphics/RecEq3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/RecEq3.gif -------------------------------------------------------------------------------- /graphics/RecEq4.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/RecEq4.gif -------------------------------------------------------------------------------- /graphics/RecEq5.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/RecEq5.gif -------------------------------------------------------------------------------- /graphics/RecEq6.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/RecEq6.gif -------------------------------------------------------------------------------- /graphics/RecEq7.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/RecEq7.gif -------------------------------------------------------------------------------- /graphics/RecEq8.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/RecEq8.gif -------------------------------------------------------------------------------- /graphics/RecEq9.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/RecEq9.gif -------------------------------------------------------------------------------- /graphics/RecRodCutEqn.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/RecRodCutEqn.gif -------------------------------------------------------------------------------- /graphics/RedBlackBalance.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/RedBlackBalance.png -------------------------------------------------------------------------------- /graphics/RedBlackRightRotate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/RedBlackRightRotate.png -------------------------------------------------------------------------------- /graphics/RedBlackUnbalanced.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/RedBlackUnbalanced.png -------------------------------------------------------------------------------- /graphics/RegularityCond.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/RegularityCond.png -------------------------------------------------------------------------------- /graphics/ShortPath.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/ShortPath.png -------------------------------------------------------------------------------- /graphics/ThreeTree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/ThreeTree.png -------------------------------------------------------------------------------- /graphics/TwoToTheN.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/graphics/TwoToTheN.png -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | # Need to export as ENV var 2 | export TEMPLATE_DIR = templates 3 | export QUIZ_DIR = quizzes 4 | PTML_DIR = ptml 5 | 6 | INCS = $(TEMPLATE_DIR)/menu.txt $(TEMPLATE_DIR)/chap_menu.txt $(TEMPLATE_DIR)/lang_menu.txt 7 | 8 | HTMLFILES = $(shell ls $(PTML_DIR)/*.ptml | sed -e 's/.ptml/.html/' | sed -e 's/ptml\///') 9 | SUBPROJ_FILES = $(shell ls Algocynfas/*.html) 10 | 11 | %.html: $(PTML_DIR)/%.ptml $(INCS) 12 | python3 utils/html_checker.py $< 13 | utils/html_include.awk <$< >$@ 14 | 15 | website: template tests $(INCS) $(HTMLFILES) $(SUBPROJ_FILES) 16 | ./C++/tests.sh 17 | ./Clojure/tests.sh 18 | ./Go/tests.sh 19 | ./Java/tests.sh 20 | ./Javascript/tests.sh 21 | ./Ruby/tests.sh 22 | cd Python; ./tests.sh 23 | cd .. 24 | -git commit -a -m "Website rebuild." 25 | git push origin master 26 | 27 | tests: $(QUIZ_DIR) 28 | cd $(QUIZ_DIR) ; make all 29 | 30 | local: template tests $(INCS) $(HTMLFILES) 31 | 32 | template: $(TEMPLATE_DIR) 33 | cd $(TEMPLATE_DIR) ; make all 34 | 35 | clean: 36 | rm $(HTMLFILES) 37 | cd $(TEMPLATE_DIR) ; make clean 38 | -------------------------------------------------------------------------------- /ptml/ApproximationAlgorithms.ptml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Design and Analyis of Algorithms: Approximation Algorithms 6 | 7 | 8 | 9 | 10 | 11 |

12 | Design and Analyis of Algorithms: Approximation Algorithms 13 |

14 | 15 |
16 |

17 | 18 |

19 |
20 | 21 |

22 | Overview 23 |

24 | 25 |

26 | Source Code 27 |

28 |

29 | 30 |

31 | 32 |

33 | For Further Study 34 |

35 |
    36 |
37 | 38 |

39 | Homework 40 |

41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /ptml/FibonacciHeaps.ptml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Design and Analyis of Algorithms: Fibonacci Heaps 6 | 7 | 8 | 9 | 10 | 11 |

12 | Design and Analyis of Algorithms: Fibonacci Heaps 13 |

14 | 15 |
16 |

17 | 18 |

19 |
20 | 21 |

22 | Overview 23 |

24 | 25 |

26 | Source Code 27 |

28 |

29 | 31 | Python 32 | 33 |
34 |

35 | 36 |

37 | For Further Study 38 |

39 |
    40 |
41 | 42 |

43 | Homework 44 |

45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /ptml/MaximumFlow.ptml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Design and Analyis of Algorithms: Maximum Flow 6 | 7 | 8 | 9 | 10 | 11 |

12 | Design and Analyis of Algorithms: Maximum Flow 13 |

14 | 15 |
16 |

17 | 18 |

19 |
20 | 21 |

22 | Overview 23 |

24 | 25 |

26 | Source Code 27 |

28 |

29 | 31 | Python 32 | 33 |
34 |

35 | 36 |

37 | For Further Study 38 |

39 |
    40 |
41 | 42 |

43 | Homework 44 |

45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /ptml/SortingInLinearTime.ptml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Design and Analyis of Algorithms: Sorting In Linear Time 6 | 7 | 8 | 9 | 10 | 11 |

12 | Design and Analyis of Algorithms: Sorting In Linear Time 13 |

14 | 15 |
16 |

17 | 18 |

19 |
20 | 21 |

22 | Overview 23 |

24 | 25 |

26 | Source Code 27 |

28 |

29 | 30 |

31 | 32 |

33 | For Further Study 34 |

35 |
    36 |
37 | 38 |

39 | Homework 40 |

41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /ptml/about.ptml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | About 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

14 | About this site 15 |

16 |

17 | This site has been developed primarily by Dr. Eugene Callahan 18 | at the NYU Tandon School of Engineering for use in the class 19 | Design and Analysis of Algorithms. Others working on the site 20 | have included Nanda Kalidindi, Prashant Patel, Xiaohang Su, 21 | Zebin Xu, Jatri Dave, Abhishek Kuntal, Saniya Alekar, 22 | and Robert Dodson. 23 | 24 |
25 | You may re-use any material you wish to so long as you give credit. 26 |

27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /qentry.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | python3 utils/question_entry.py quizzes 4 | git add quizzes/*.txt 5 | git commit quizzes/*.txt -m "Added questions." 6 | cd quizzes; make all 7 | -------------------------------------------------------------------------------- /quizzes/makefile: -------------------------------------------------------------------------------- 1 | QINCS = $(shell ls quiz*.txt | sed -e 's/txt/qhtm/g') 2 | TEST = $(shell ls quiz*.txt | sed -e 's/txt/thtm/g') 3 | QUIZZES = $(shell ls quiz*.txt) 4 | 5 | %.qhtm: %.txt 6 | ../utils/quiz2html.py $< \# >$@ 7 | git add $@ 8 | 9 | %.thtm: %.txt 10 | ../utils/quiz2test.py $< \# >$@ 11 | 12 | all: $(QINCS) 13 | 14 | test: $(TEST) 15 | 16 | clean: 17 | touch *.txt 18 | -------------------------------------------------------------------------------- /quizzes/quiz11.1.txt: -------------------------------------------------------------------------------- 1 | A good use for a direct-address table might be:#^All answers are fine#Memoization#Bingo#Marking members of a set as present 2 | We can't use direct-address tables when#^there are a large number of (potential) entries#all answers are fine#we are programming the Sieve of Eratosthenes#we are dealing with zipcodes 3 | What is direct addressing?#Fewer keys than array positions#^Every key specifies a distinct array position #Fewer array positions than keys#None of the mentioned 4 | -------------------------------------------------------------------------------- /quizzes/quiz12.1.txt: -------------------------------------------------------------------------------- 1 | Suppose the numbers 7, 5, 1, 8, 3, 6, 0, 9, 4, 2 are inserted in that order into an initially empty binary search tree. The binary search tree uses the usual ordering on natural numbers. What is the in-order traversal sequence of the resultant tree?#8 9 4 6 2 3 0 1 5 7#^0 1 2 3 4 5 6 7 8 9#0 2 4 3 1 6 5 9 7 8#7 5 1 0 3 2 4 6 8 9 2 | Given a binary search tree, which traversal type would print the values in the nodes in sorted order?#None of the above#Postorder#Preorder#^Inorder 3 | Preorder and in order of a tree is given Inorder — D H B E A I F C J G Preorder -- A B D H E C F I G J K. What will be the post order traversal of the tree?#H D E B F I J K G C A#^H D E B I F J K G C A#H D E B I F J K C G A#None of the above -------------------------------------------------------------------------------- /quizzes/quiz13.1.txt: -------------------------------------------------------------------------------- 1 | The maximum height for a red-black tree is#n#8lg(n + 1)#lg(n)#^2lg(n + 1) 2 | A red-black tree is#^a type of binary search tree#a minimum spanning tree#a B-tree 3 | The goal of red-black trees is to#^keep a BST balanced#minimize insert time in a BST#minimize delete time in a BST#minimize search time in a BST 4 | Given the properties of a red-black tree, one can never have#a root node that is black#nil leaf nodes#two black nodes linked#^two red nodes linked 5 | -------------------------------------------------------------------------------- /quizzes/quiz13.3.txt: -------------------------------------------------------------------------------- 1 | Why do we left rotate at line 11 of RB-Insert-Fixup?#^z is its parent's right child, which means the tree is growing to the left#because z's parent is the right child of z's grandparent#because z's grandparent is RED 2 | Line 4 of RB-Insert-Fixup, where the color of y is checked, is determining#the color of z's niece#the color of z's grandparent#^the color of z's uncle#the color of z's parent 3 | -------------------------------------------------------------------------------- /quizzes/quiz2.2.txt: -------------------------------------------------------------------------------- 1 | In a theoretical analysis of algorithms, we want to discuss running time in nanoseconds.#^False#True 2 | We will generally consider:#best-case running time#^worst-case running time#memory usage#average-case running time 3 | We will mostly concern ourselves with an algorithm's behavior#for small inputs#egregiously#^asymptotically#exponentially 4 | In analyzing an algorithm in terms of n, the number of inputs, we would like to focus on:#the lowest power of n#^the highest power of n#the logarithm of n#all of the above 5 | -------------------------------------------------------------------------------- /quizzes/quiz3.3.txt: -------------------------------------------------------------------------------- 1 | Linked lists are best suited#for both of above situation#for the size of the structure and the data in the structure are constantly changing#^for relatively permanent collections of data#for none of above situation 2 | -------------------------------------------------------------------------------- /quizzes/quiz4.1.txt: -------------------------------------------------------------------------------- 1 | The problem with the brute force max-subarray solution is#it is too complicated#the force used might break the code#^it is too slow 2 | The three possible arrays containing the maximum sequence are#An array of ints, an array of doubles, and an array of strings#^The array from A[0] to the mid-point; an array that crosses the midpoint, and the array from A[midpoint + 1] to the end#The whole array, the null array, and the middle array 3 | What does FIND-MAXIMUM-SUBARRAY return when all elements of A are negative?#Largest Positive Number in A#^Largest Negative Number in A#First index of A#Lase index of A 4 | -------------------------------------------------------------------------------- /quizzes/quiz4.5.txt: -------------------------------------------------------------------------------- 1 | Using master method (mm), the runtime for T(n) = 3T(n/2) + n2 is:#n log n#Θ(n3/2)#MM does not apply#^Θ(n2) 2 | Using mm, the runtime for T(n) = 2n(n/2) + nn is:#Θ(n)#^MM does not apply#Θ(2n)#Θ(nn) 3 | Using mm, the runtime for T(n) = 0.5T(n/2) + 1/n is:#Θ(.5n)#Θ(n)#^MM does not apply#Θ(1/n) 4 | -------------------------------------------------------------------------------- /quizzes/quiz6.2.txt: -------------------------------------------------------------------------------- 1 | The max heap property means that#^a node can't have a greater value than its parent#a node must have a value equal to its parent#a node can't have a lesser than its parent#all values must be heaped up in one node 2 | In a max-heap, element with the greatest key is always in the which node?#first node to the right#^root node#first node to the left#leaf node 3 | What is the complexity of adding an element to the heap.#O(nlogn)#o(n^2)#^O(logn)#O(n) 4 | -------------------------------------------------------------------------------- /quizzes/quiz999.999.qhtm: -------------------------------------------------------------------------------- 1 |
2 | 3 | Quiz 4 | 5 |
    6 |
  1. 7 | How does this work? 8 |
  2. 9 |
      10 |
    1. 11 | 12 | Very well! 13 |
    2. 14 |
    3. 15 | 16 | Badly 17 |
    4. 18 |
    19 |
20 |
21 | 22 | Answers 23 | 24 |

25 | 1. a; 26 |

27 |
28 |
29 | -------------------------------------------------------------------------------- /quizzes/quiz999.999.txt: -------------------------------------------------------------------------------- 1 | How does this work?#^Very well!#Badly 2 | -------------------------------------------------------------------------------- /recurrence.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/recurrence.pdf -------------------------------------------------------------------------------- /rel.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | git commit -a -m "$1" 3 | git push origin master 4 | -------------------------------------------------------------------------------- /run_ruby_and_python_tests.sh: -------------------------------------------------------------------------------- 1 | rake test 2 | if [ $? -eq 0 ]; then 3 | echo OK 4 | else 5 | exit 1 6 | fi 7 | 8 | # py.test Python/ 9 | -------------------------------------------------------------------------------- /sample.awk: -------------------------------------------------------------------------------- 1 | #!/usr/bin/awk -f 2 | 3 | /href/ { print NF } 4 | -------------------------------------------------------------------------------- /templates/.gitignore: -------------------------------------------------------------------------------- 1 | *_langs.txt -------------------------------------------------------------------------------- /templates/AllPairsShortestPaths_langs.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /templates/AmortizedAnalysis_langs.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /templates/ApproximationAlgorithms_langs.txt: -------------------------------------------------------------------------------- 1 | 2 | Python
3 | -------------------------------------------------------------------------------- /templates/AugmentingDataStructures_langs.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /templates/BTrees_langs.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /templates/BinarySearchTrees_langs.txt: -------------------------------------------------------------------------------- 1 | 2 | Java
3 | Ruby
4 | Python
5 | -------------------------------------------------------------------------------- /templates/ChapTemplate.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |

11 |

12 | 13 |
14 |

15 | 16 |

17 |
18 | 19 |

20 | Overview 21 |

22 | 23 |

24 | Source Code 25 |

26 |

27 | 29 | Python 30 | 31 |
32 |

33 | 34 |

35 | External Links 36 |

37 | 42 | 43 |

44 | Homework 45 |

46 | 47 | 48 | -------------------------------------------------------------------------------- /templates/ComputationalGeometry_langs.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /templates/DataStructuresForDisjointSets_langs.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /templates/DivideAndConquer_langs.txt: -------------------------------------------------------------------------------- 1 | 2 | Java
3 | Ruby
4 | Python
5 | -------------------------------------------------------------------------------- /templates/DynamicProgramming_langs.txt: -------------------------------------------------------------------------------- 1 | 2 | Java
3 | Ruby
4 | Python
5 | Clojure
6 | -------------------------------------------------------------------------------- /templates/ElementaryDataStructures_langs.txt: -------------------------------------------------------------------------------- 1 | 2 | Java
3 | C++
4 | -------------------------------------------------------------------------------- /templates/FibonacciHeaps_langs.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /templates/GettingStarted_langs.txt: -------------------------------------------------------------------------------- 1 | 2 | Java
3 | Ruby
4 | Go
5 | C++
6 | Python
7 | Clojure
8 | -------------------------------------------------------------------------------- /templates/GraphAlgorithms_langs.txt: -------------------------------------------------------------------------------- 1 | 2 | Java
3 | Ruby
4 | Python
5 | -------------------------------------------------------------------------------- /templates/GreedyAlgorithms_langs.txt: -------------------------------------------------------------------------------- 1 | 2 | Java
3 | Ruby
4 | Go
5 | Python
6 | -------------------------------------------------------------------------------- /templates/GrowthOfFunctions_langs.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /templates/HashTables_langs.txt: -------------------------------------------------------------------------------- 1 | 2 | Java
3 | Ruby
4 | C++
5 | Python
6 | -------------------------------------------------------------------------------- /templates/Heapsort_langs.txt: -------------------------------------------------------------------------------- 1 | 2 | Java
3 | Ruby
4 | C++
5 | Python
6 | -------------------------------------------------------------------------------- /templates/LatexCode.txt: -------------------------------------------------------------------------------- 1 | 2 | Recurrence: 3 | T(n) = 4 | \begin{cases} 5 | \Theta (1)\qquad\qquad\quad \mbox{if}\ n=1\\ 6 | 2T(n/2) + \Theta (n)\ \mbox{if}\ n>1 7 | \end{cases} 8 | 9 | T(n) = 10 | \begin{cases} 11 | c \qquad\qquad\qquad\qquad\quad\quad\quad \ \mbox{if}\ n=0\\ 12 | T(n / 2) + T(n / 2) + \Theta(n) \quad \mbox{if}\ n>0 13 | \end{cases} 14 | 15 | T(n) = 4T(1) + \sum_{i=0}^{h-1}2^i n 16 | 17 | 18 | Geometric series: 19 | n^{2} + \frac{n^{2}}{2} + \frac{n^{2}}{4} + \frac{n^{2}}{8}... 20 | 21 | a + ar + ar^{2} + ar^{3} +...+ + ar^{n - 1} = \sum_{k = 0}^{\infty}ar^{k} = 22 | \frac{a}{1 - r},\ for \left | r \right | < 1 23 | 24 | Matrix: 25 | X = \begin{bmatrix} 26 | A & B\\ 27 | C & D 28 | \end{bmatrix} 29 | 30 | Y = \begin{bmatrix} 31 | E & F\\ 32 | G & H 33 | \end{bmatrix} 34 | 35 | 36 | -------------------------------------------------------------------------------- /templates/LinearProgramming_langs.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /templates/MatrixOperations_langs.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /templates/MaximumFlow_langs.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /templates/MediansAndOrderStatistics_langs.txt: -------------------------------------------------------------------------------- 1 | 2 | Ruby
3 | C++
4 | Python
5 | -------------------------------------------------------------------------------- /templates/MinimumSpanningTrees_langs.txt: -------------------------------------------------------------------------------- 1 | 2 | Python
3 | -------------------------------------------------------------------------------- /templates/MultithreadedAlgorithms_langs.txt: -------------------------------------------------------------------------------- 1 | 2 | Java
3 | C++
4 | -------------------------------------------------------------------------------- /templates/NPCompleteness_langs.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /templates/NumberTheoreticAlgorithms_langs.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /templates/PolynomialsAndTheFFT_langs.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /templates/Quicksort_langs.txt: -------------------------------------------------------------------------------- 1 | 2 | Java
3 | Ruby
4 | Go
5 | C++
6 | Python
7 | -------------------------------------------------------------------------------- /templates/RandomizedAlgorithms_langs.txt: -------------------------------------------------------------------------------- 1 | 2 | Java
3 | Ruby
4 | C++
5 | Python
6 | -------------------------------------------------------------------------------- /templates/RedBlackTrees_langs.txt: -------------------------------------------------------------------------------- 1 | 2 | Java
3 | -------------------------------------------------------------------------------- /templates/SingleSourceShortestPaths_langs.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /templates/SortingInLinearTime_langs.txt: -------------------------------------------------------------------------------- 1 | 2 | Java
3 | Ruby
4 | C++
5 | -------------------------------------------------------------------------------- /templates/StringMatching_langs.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /templates/TheRoleOfAlgorithms_langs.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /templates/ToDo.txt: -------------------------------------------------------------------------------- 1 | Algorithm Museum To-Do List 2 | _____________________________________ 3 | 4 | ALL: All code should be stored in a single file named for the chapter in CLRS 5 | for which it implements the algorithms, OR it should be in a directory with 6 | such a name, if there is more than one file for the code. So, if the C source 7 | code for chapter 4 is in a single file, it should be called 8 | divide_and_conquer.c. 9 | 10 | ALL: Write tests for each algorithm you have implemented. 11 | 12 | -------------------------------------------------------------------------------- /templates/chapters.txt: -------------------------------------------------------------------------------- 1 | I Foundations 2 | 1 TheRoleOfAlgorithms 3 | 2 GettingStarted 4 | 3 GrowthOfFunctions 5 | 4 DivideAndConquer 6 | 5 RandomizedAlgorithms 7 | II SortingAndOrderStatistics 8 | 6 Heapsort 9 | 7 Quicksort 10 | 8 SortingInLinearTime 11 | 9 MediansAndOrderStatistics 12 | III DataStructures 13 | 10 ElementaryDataStructures 14 | 11 HashTables 15 | 12 BinarySearchTrees 16 | 13 RedBlackTrees 17 | 14 AugmentingDataStructures 18 | IV AdvancedDesignAndAnalysisTechniques 19 | 15 DynamicProgramming 20 | 16 GreedyAlgorithms 21 | 17 AmortizedAnalysis 22 | V AdvancedDataStructures 23 | 18 BTrees 24 | 19 FibonacciHeaps 25 | 20 vanEmdeBoasTrees 26 | 21 DataStructuresForDisjointSets 27 | VI GraphAlgorithms 28 | 22 GraphAlgorithms 29 | 23 MinimumSpanningTrees 30 | 24 SingleSourceShortestPaths 31 | 25 AllPairsShortestPaths 32 | 26 MaximumFlow 33 | VII SelectedTopics 34 | 27 MultithreadedAlgorithms 35 | 28 MatrixOperations 36 | 29 LinearProgramming 37 | 30 PolynomialsAndTheFFT 38 | 31 NumberTheoreticAlgorithms 39 | 32 StringMatching 40 | 33 ComputationalGeometry 41 | 34 NPCompleteness 42 | 35 ApproximationAlgorithms 43 | -------------------------------------------------------------------------------- /templates/gen_chap_files.awk: -------------------------------------------------------------------------------- 1 | 2 | # this is failing right now: eliminate until we get it right 3 | # if (system( "[ -f " chap_file " ] ") != 0) { 4 | # system("touch " chap_html) 5 | # system(create_pg " <" templ " >" chap_file " \"" daa chap_nm "\"") 6 | # } 7 | -------------------------------------------------------------------------------- /templates/gen_lang_bin.awk: -------------------------------------------------------------------------------- 1 | #!/usr/bin/awk -f 2 | 3 | # This program generates the language menu for the Algorithm Museum's languages. 4 | # It reads langs.txt to get the language list, and stdin for the chapter names. 5 | 6 | BEGIN { 7 | header = "CHAPTER" 8 | file = "langs.txt" 9 | while((getline < file ) > 0 ) { 10 | langs[$1] = $2 # record each language and ext 11 | } 12 | for (lang in langs) { 13 | header = header " " lang 14 | } 15 | print header 16 | } 17 | 18 | /^[0-9]/ { # this is a chapter name 19 | chapnm = $2 20 | entry = chapnm 21 | for( lang in langs ) { 22 | ext = langs[lang] 23 | files = "../" lang "/" chapnm "/*" ext 24 | if(system("ls " files " 1> /dev/null 2>&1")) { 25 | # print "Got nuttin" 26 | entry = entry " 0 " 27 | } else { 28 | # print "Got one" 29 | entry = entry " 1 " 30 | } 31 | } 32 | print entry 33 | } 34 | -------------------------------------------------------------------------------- /templates/gen_lang_menu.awk: -------------------------------------------------------------------------------- 1 | #!/usr/bin/awk -f 2 | 3 | BEGIN { 4 | url = "https://github.com/gcallah/algorithms/tree/master/" 5 | indent1 = " " 6 | indent2 = indent1 indent1 7 | indent3 = indent2 indent1 8 | print indent1 "" 9 | } 10 | 11 | /^CHAPTER/ { 12 | tr() 13 | print indent3 "" 14 | for (i = 2; i <= NF; i++) { 15 | print indent3 "" 16 | langs[i] = $i 17 | } 18 | endtr() 19 | next 20 | } 21 | 22 | { 23 | chap = $1 24 | chap_langs = chap "_langs.txt" 25 | 26 | tr() 27 | print indent3 "" 28 | print indent3 "" > chap_langs 29 | for (i = 2; i <= NF; i++) { 30 | yn = "No" 31 | if($i) { 32 | yn = "Yes" 33 | print "" langs[i] "
" >> chap_langs 34 | } 35 | print indent3 "" 36 | } 37 | close(chap_langs) 38 | endtr() 39 | } 40 | 41 | END { 42 | print indent1 "
Chapter" $i "" chap "" yn "
" 43 | } 44 | 45 | function tr() { 46 | print indent2 "" 47 | } 48 | 49 | function endtr() { 50 | print indent2 "" 51 | } 52 | -------------------------------------------------------------------------------- /templates/google_analytics.txt: -------------------------------------------------------------------------------- 1 | 9 | -------------------------------------------------------------------------------- /templates/langs.txt: -------------------------------------------------------------------------------- 1 | C++ .cpp 2 | Clojure .clj 3 | Go .go 4 | Java .java 5 | Javascript .js 6 | Python .py 7 | Ruby .rb 8 | -------------------------------------------------------------------------------- /templates/makefile: -------------------------------------------------------------------------------- 1 | all: lang_menu.txt lang_chapter_binary.txt chap_menu.txt 2 | 3 | lang_menu.txt: lang_chapter_binary.txt gen_lang_menu.awk 4 | ./gen_lang_menu.awk lang_menu.txt 5 | 6 | lang_chapter_binary.txt: chapters.txt langs.txt gen_lang_bin.awk 7 | ./gen_lang_bin.awk lang_chapter_binary.txt 8 | 9 | chap_menu.txt: chapters.txt gen_chaps.awk 10 | ./gen_chaps.awk chap_menu.txt 11 | 12 | clean: 13 | rm *_langs.txt 14 | rm lang_chapter_binary.txt 15 | -------------------------------------------------------------------------------- /templates/menu.txt: -------------------------------------------------------------------------------- 1 | 13 | 14 | -------------------------------------------------------------------------------- /templates/python_anywhere.txt: -------------------------------------------------------------------------------- 1 |
2 | 6 |
7 | Python console 8 |
9 |
10 | 11 | -------------------------------------------------------------------------------- /templates/vanEmdeBoasTrees_langs.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /test.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/test.html -------------------------------------------------------------------------------- /test_runner.sh: -------------------------------------------------------------------------------- 1 | (cd ./Python; ./tests.sh) 2 | ./Ruby/tests.sh 3 | -------------------------------------------------------------------------------- /tests/FinalFall2017.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/tests/FinalFall2017.pdf -------------------------------------------------------------------------------- /tests/MidTermFall2017.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gcallah/algorithms/61915f5d8786cd7ac991475e5915644586aaa999/tests/MidTermFall2017.pdf -------------------------------------------------------------------------------- /tests/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Past Tests 8 | 9 | 10 | 11 | 12 |

13 | Past Tests 14 |

15 | 16 | 42 | 43 | 44 | 45 | --------------------------------------------------------------------------------