├── .gitignore ├── .swiftlint.yml ├── .travis.yml ├── AVL Tree ├── AVLTree.playground │ ├── Contents.swift │ ├── Sources │ │ └── AVLTree.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata ├── AVLTree.swift ├── Images │ ├── BalanceNotOK.graffle │ ├── BalanceNotOK.png │ ├── BalanceOK.graffle │ ├── BalanceOK.png │ ├── Balanced.graffle │ ├── Balanced.png │ ├── Height.graffle │ ├── Height.png │ ├── RotationStep0.jpg │ ├── RotationStep1.jpg │ ├── RotationStep2.jpg │ ├── RotationStep3.jpg │ ├── Unbalanced.graffle │ └── Unbalanced.png ├── README.markdown └── Tests │ ├── AVLTreeTests.swift │ ├── Info.plist │ ├── Tests.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ └── contents.xcworkspacedata │ └── xcshareddata │ │ └── xcschemes │ │ └── Tests.xcscheme │ └── TreeNodeTests.swift ├── Algorithm Design.markdown ├── All-Pairs Shortest Paths ├── APSP │ ├── APSP.playground │ │ ├── Contents.swift │ │ ├── contents.xcplayground │ │ ├── playground.xcworkspace │ │ │ └── contents.xcworkspacedata │ │ └── timeline.xctimeline │ ├── APSP.xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ └── xcshareddata │ │ │ │ └── WorkspaceSettings.xcsettings │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ ├── APSP.xcscheme │ │ │ └── APSPTests.xcscheme │ ├── APSP.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── WorkspaceSettings.xcsettings │ ├── APSP │ │ ├── APSP.h │ │ ├── APSP.swift │ │ ├── FloydWarshall.swift │ │ ├── Helpers.swift │ │ └── Info.plist │ └── APSPTests │ │ ├── APSPTests.swift │ │ └── Info.plist ├── README.markdown └── img │ ├── d0.png │ ├── d1.png │ ├── d2.png │ ├── d3.png │ ├── example_graph.png │ ├── original_adjacency_matrix.png │ ├── pi0.png │ ├── pi1.png │ ├── pi2.png │ ├── pi3.png │ └── weight_comparison_formula.png ├── Array2D ├── Array2D.playground │ ├── Contents.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata ├── Array2D.swift ├── README.markdown └── Tests │ ├── Array2DTests.swift │ ├── Info.plist │ └── Tests.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ └── contents.xcworkspacedata │ └── xcshareddata │ └── xcschemes │ └── Tests.xcscheme ├── B-Tree ├── BTree.playground │ ├── Contents.swift │ ├── Sources │ │ └── BTree.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata ├── BTree.swift ├── Images │ ├── BTree20.png │ ├── InsertionSplit.png │ ├── MergingNodes.png │ ├── MovingKey.png │ └── Node.png ├── README.md └── Tests │ ├── Tests.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ └── contents.xcworkspacedata │ └── xcshareddata │ │ └── xcschemes │ │ └── Tests.xcscheme │ └── Tests │ ├── BTreeNodeTests.swift │ ├── BTreeTests.swift │ └── Info.plist ├── Big-O Notation.markdown ├── Binary Search Tree ├── Images │ ├── DeleteLeaf.graffle │ ├── DeleteLeaf.png │ ├── DeleteOneChild.graffle │ ├── DeleteOneChild.png │ ├── DeleteTwoChildren.graffle │ ├── DeleteTwoChildren.png │ ├── MinimumMaximum.graffle │ ├── MinimumMaximum.png │ ├── Searching.graffle │ ├── Searching.png │ ├── Traversing.graffle │ ├── Traversing.png │ ├── Tree1.graffle │ ├── Tree1.png │ ├── Tree2.graffle │ └── Tree2.png ├── README.markdown ├── Solution 1 │ ├── BinarySearchTree.playground │ │ ├── Contents.swift │ │ ├── Sources │ │ │ └── BinarySearchTree.swift │ │ ├── contents.xcplayground │ │ ├── playground.xcworkspace │ │ │ └── contents.xcworkspacedata │ │ └── timeline.xctimeline │ └── Tests │ │ ├── BinarySearchTreeTests.swift │ │ ├── Info.plist │ │ └── Tests.xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── WorkspaceSettings.xcsettings │ │ └── xcshareddata │ │ └── xcschemes │ │ └── Tests.xcscheme └── Solution 2 │ ├── BinarySearchTree.playground │ ├── Contents.swift │ ├── Sources │ │ └── BinarySearchTree.swift │ ├── contents.xcplayground │ ├── playground.xcworkspace │ │ └── contents.xcworkspacedata │ └── timeline.xctimeline │ └── BinarySearchTree.swift ├── Binary Search ├── BinarySearch.playground │ ├── Contents.swift │ ├── Sources │ │ └── BinarySearch.swift │ ├── contents.xcplayground │ ├── playground.xcworkspace │ │ └── contents.xcworkspacedata │ └── timeline.xctimeline ├── BinarySearch.swift ├── README.markdown └── Tests │ ├── BinarySearchTests.swift │ ├── Info.plist │ └── Tests.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ └── contents.xcworkspacedata │ └── xcshareddata │ └── xcschemes │ └── Tests.xcscheme ├── Binary Tree ├── BinaryTree.playground │ ├── Contents.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata ├── BinaryTree.swift ├── Images │ ├── BinaryTree.graffle │ ├── BinaryTree.png │ ├── Operations.graffle │ └── Operations.png └── README.markdown ├── Bit Set ├── BitSet.playground │ ├── Contents.swift │ ├── Sources │ │ └── BitSet.swift │ ├── contents.xcplayground │ ├── playground.xcworkspace │ │ └── contents.xcworkspacedata │ └── timeline.xctimeline ├── BitSet.swift └── README.markdown ├── Bloom Filter ├── BloomFilter.playground │ ├── Contents.swift │ ├── contents.xcplayground │ ├── playground.xcworkspace │ │ └── contents.xcworkspacedata │ └── timeline.xctimeline ├── BloomFilter.swift ├── README.markdown └── Tests │ ├── BloomFilterTests.swift │ ├── Info.plist │ └── Tests.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ └── contents.xcworkspacedata │ └── xcshareddata │ └── xcschemes │ └── Tests.xcscheme ├── Bounded Priority Queue ├── BoundedPriorityQueue.playground │ ├── Contents.swift │ ├── Sources │ │ └── BoundedPriorityQueue.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata ├── BoundedPriorityQueue.swift ├── README.markdown └── Tests │ ├── BoundedPriorityQueueTests.swift │ ├── Info.plist │ └── Tests.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── WorkspaceSettings.xcsettings │ └── xcshareddata │ └── xcschemes │ └── Tests.xcscheme ├── Boyer-Moore ├── BoyerMoore.playground │ ├── Contents.swift │ ├── contents.xcplayground │ ├── playground.xcworkspace │ │ └── contents.xcworkspacedata │ └── timeline.xctimeline ├── BoyerMoore.swift ├── README.markdown └── Tests │ ├── BoyerMooreHorspoolTests.swift │ ├── BoyerMooreTests.swift │ ├── Info.plist │ └── Tests.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── WorkspaceSettings.xcsettings │ └── xcshareddata │ └── xcschemes │ └── Tests.xcscheme ├── Breadth-First Search ├── BreadthFirstSearch.playground │ ├── Pages │ │ └── Simple example.xcplaygroundpage │ │ │ └── Contents.swift │ ├── Sources │ │ ├── Edge.swift │ │ ├── Graph.swift │ │ ├── Node.swift │ │ └── Queue.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata ├── BreadthFirstSearch.swift ├── Images │ ├── AnimatedExample.gif │ ├── AnimatedExample.graffle │ ├── AnimatedExample.psd │ ├── TraversalTree.graffle │ └── TraversalTree.png ├── README.markdown └── Tests │ ├── BreadthFirstSearchTests.swift │ ├── Graph.swift │ ├── Info.plist │ ├── Queue.swift │ └── Tests.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ └── contents.xcworkspacedata │ └── xcshareddata │ └── xcschemes │ └── Tests.xcscheme ├── Brute-Force String Search ├── BruteForceStringSearch.playground │ ├── Contents.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata ├── BruteForceStringSearch.swift └── README.markdown ├── Bubble Sort └── README.markdown ├── Bucket Sort ├── BucketSort.playground │ ├── Contents.swift │ ├── Sources │ │ └── BucketSort.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata ├── BucketSort.swift ├── Docs │ └── BucketSort.png ├── README.markdown └── Tests │ ├── Info.plist │ ├── Tests.swift │ └── Tests.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ └── contents.xcworkspacedata │ └── xcshareddata │ └── xcschemes │ └── Tests.xcscheme ├── Comb Sort ├── Comb Sort.playground │ ├── Contents.swift │ ├── Sources │ │ └── Comb Sort.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata ├── Comb Sort.swift ├── README.markdown └── Tests │ ├── CombSortTests.swift │ ├── Info.plist │ └── Tests.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ └── contents.xcworkspacedata │ └── xcshareddata │ └── xcschemes │ └── Tests.xcscheme ├── Combinatorics ├── Combinatorics.playground │ ├── Contents.swift │ ├── contents.xcplayground │ ├── playground.xcworkspace │ │ └── contents.xcworkspacedata │ └── timeline.xctimeline └── README.markdown ├── Count Occurrences ├── CountOccurrences.playground │ ├── Contents.swift │ ├── contents.xcplayground │ ├── playground.xcworkspace │ │ └── contents.xcworkspacedata │ └── timeline.xctimeline ├── CountOccurrences.swift └── README.markdown ├── Counting Sort ├── CountingSort.playground │ ├── Contents.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata ├── CountingSort.swift ├── README.markdown └── Tests │ ├── CountingSortTest.swift │ ├── Info.plist │ └── Tests.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ └── contents.xcworkspacedata │ └── xcshareddata │ └── xcschemes │ └── Tests.xcscheme ├── Depth-First Search ├── DepthFirstSearch.playground │ ├── Pages │ │ └── Simple Example.xcplaygroundpage │ │ │ └── Contents.swift │ ├── Sources │ │ ├── Edge.swift │ │ ├── Graph.swift │ │ └── Node.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata ├── DepthFirstSearch.swift ├── Images │ ├── AnimatedExample.gif │ ├── AnimatedExample.graffle │ ├── AnimatedExample.psd │ ├── TraversalTree.graffle │ └── TraversalTree.png ├── README.markdown └── Tests │ ├── DepthFirstSearchTests.swift │ ├── Graph.swift │ ├── Info.plist │ └── Tests.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── WorkspaceSettings.xcsettings │ └── xcshareddata │ └── xcschemes │ └── Tests.xcscheme ├── Deque ├── Deque-Optimized.swift ├── Deque-Simple.swift ├── Deque.playground │ ├── Contents.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata └── README.markdown ├── DiningPhilosophers ├── DiningPhilosophers.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ └── contents.xcworkspacedata │ └── xcshareddata │ │ └── xcschemes │ │ ├── DiningPhilosophers.xcscheme │ │ └── xcschememanagement.plist ├── LICENSE ├── Package.swift ├── README.md └── Sources │ └── main.swift ├── Fixed Size Array ├── FixedSizeArray.playground │ ├── Contents.swift │ ├── contents.xcplayground │ ├── playground.xcworkspace │ │ └── contents.xcworkspacedata │ └── timeline.xctimeline ├── Images │ ├── FixedSizeArrays.graffle │ ├── append.png │ ├── array.png │ ├── delete-no-copy.png │ ├── delete.png │ ├── indexing.png │ └── insert.png └── README.markdown ├── Fizz Buzz ├── FizzBuzz.playground │ ├── Contents.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata ├── FizzBuzz.swift └── README.markdown ├── GCD ├── GCD.playground │ ├── Contents.swift │ ├── contents.xcplayground │ ├── playground.xcworkspace │ │ └── contents.xcworkspacedata │ └── timeline.xctimeline ├── GCD.swift └── README.markdown ├── Graph ├── Graph.playground │ ├── Contents.swift │ ├── contents.xcplayground │ ├── playground.xcworkspace │ │ └── contents.xcworkspacedata │ └── timeline.xctimeline ├── Graph.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ └── contents.xcworkspacedata │ └── xcshareddata │ │ └── xcschemes │ │ ├── Graph.xcscheme │ │ └── GraphTests.xcscheme ├── Graph.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── WorkspaceSettings.xcsettings ├── Graph │ ├── AdjacencyListGraph.swift │ ├── AdjacencyMatrixGraph.swift │ ├── Edge.swift │ ├── Graph.h │ ├── Graph.swift │ ├── Info.plist │ └── Vertex.swift ├── GraphTests │ ├── GraphTests.swift │ └── Info.plist ├── Images │ ├── AdjacencyList.graffle │ ├── AdjacencyList.png │ ├── AdjacencyMatrix.graffle │ ├── AdjacencyMatrix.png │ ├── ChordMap.graffle │ ├── ChordMap.png │ ├── CoreData.graffle │ ├── CoreData.png │ ├── DAG.graffle │ ├── DAG.png │ ├── Demo1.graffle │ ├── Demo1.png │ ├── Flights.graffle │ ├── Flights.png │ ├── FlightsDirected.graffle │ ├── FlightsDirected.png │ ├── Graph.graffle │ ├── Graph.png │ ├── SocialNetwork.graffle │ ├── SocialNetwork.png │ ├── StateMachine.graffle │ ├── StateMachine.png │ ├── Tasks.graffle │ ├── Tasks.png │ ├── TreeAndList.graffle │ └── TreeAndList.png └── README.markdown ├── Hash Set ├── HashSet.playground │ ├── Contents.swift │ ├── Sources │ │ └── HashSet.swift │ ├── contents.xcplayground │ ├── playground.xcworkspace │ │ └── contents.xcworkspacedata │ └── timeline.xctimeline ├── HashSet.swift ├── Images │ ├── CombineSets.graffle │ └── CombineSets.png └── README.markdown ├── Hash Table ├── HashTable.playground │ ├── Contents.swift │ ├── Sources │ │ └── HashTable.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata └── README.markdown ├── HaversineDistance ├── HaversineDistance.playground │ ├── Contents.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata └── README.md ├── Heap Sort ├── HeapSort.swift ├── Images │ ├── MaxHeap.graffle │ └── MaxHeap.png ├── README.markdown └── Tests │ ├── HeapSortTests.swift │ ├── Info.plist │ └── Tests.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ └── contents.xcworkspacedata │ └── xcshareddata │ └── xcschemes │ └── Tests.xcscheme ├── Heap ├── Heap.swift ├── Images │ ├── Array.graffle │ ├── Array.png │ ├── Heap1.graffle │ ├── Heap1.png │ ├── HeapShape.graffle │ ├── HeapShape.png │ ├── Insert1.graffle │ ├── Insert1.png │ ├── Insert2.graffle │ ├── Insert2.png │ ├── Insert3.graffle │ ├── Insert3.png │ ├── LargeHeap.graffle │ ├── LargeHeap.png │ ├── RegularTree.graffle │ ├── RegularTree.png │ ├── Remove1.graffle │ ├── Remove1.png │ ├── Remove2.graffle │ ├── Remove2.png │ ├── Remove3.graffle │ ├── Remove3.png │ ├── Remove4.graffle │ ├── Remove4.png │ ├── Remove5.graffle │ ├── Remove5.png │ ├── SortedArray.graffle │ └── SortedArray.png ├── README.markdown └── Tests │ ├── HeapTests.swift │ ├── Info.plist │ └── Tests.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ └── contents.xcworkspacedata │ └── xcshareddata │ └── xcschemes │ └── Tests.xcscheme ├── How to Contribute.markdown ├── Huffman Coding ├── Huffman.playground │ ├── Contents.swift │ ├── Sources │ │ ├── Heap.swift │ │ ├── Huffman.swift │ │ ├── NSData+Bits.swift │ │ └── PriorityQueue.swift │ ├── contents.xcplayground │ ├── playground.xcworkspace │ │ └── contents.xcworkspacedata │ └── timeline.xctimeline ├── Huffman.swift ├── Images │ ├── BuildTree.gif │ ├── BuildTree.graffle │ ├── BuildTree.psd │ ├── Compression.graffle │ ├── Compression.png │ ├── Decompression.graffle │ ├── Decompression.png │ ├── Tree.graffle │ └── Tree.png ├── NSData+Bits.swift └── README.markdown ├── Images ├── SwiftAlgorithm-410-transp.png └── scheme-settings-for-travis.png ├── Insertion Sort ├── InsertionSort.playground │ ├── Contents.swift │ ├── contents.xcplayground │ ├── playground.xcworkspace │ │ └── contents.xcworkspacedata │ └── timeline.xctimeline ├── InsertionSort.swift ├── README.markdown └── Tests │ ├── Info.plist │ ├── InsertionSortTests.swift │ └── Tests.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ └── contents.xcworkspacedata │ └── xcshareddata │ └── xcschemes │ └── Tests.xcscheme ├── K-Means ├── Images │ ├── k_means_bad1.png │ ├── k_means_bad2.png │ └── k_means_good.png ├── KMeans.swift ├── README.markdown └── Tests │ ├── Info.plist │ ├── KMeansTests.swift │ ├── Tests.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ └── contents.xcworkspacedata │ └── xcshareddata │ │ └── xcschemes │ │ └── Tests.xcscheme │ └── Vector.swift ├── Karatsuba Multiplication ├── KaratsubaMultiplication.playground │ ├── Contents.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata ├── KaratsubaMultiplication.swift └── README.markdown ├── Knuth-Morris-Pratt ├── KnuthMorrisPratt.playground │ ├── Contents.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata ├── KnuthMorrisPratt.swift └── README.markdown ├── Kth Largest Element ├── README.markdown ├── kthLargest.playground │ ├── Contents.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ └── kthLargest.xcscmblueprint └── kthLargest.swift ├── LICENSE.txt ├── Linear Regression ├── Images │ ├── graph1.png │ ├── graph2.png │ └── graph3.png ├── LinearRegression.playground │ ├── Contents.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata └── README.markdown ├── Linear Search ├── LinearSearch.playground │ ├── Contents.swift │ ├── contents.xcplayground │ ├── playground.xcworkspace │ │ └── contents.xcworkspacedata │ └── timeline.xctimeline ├── LinearSearch.swift └── README.markdown ├── Linked List ├── LinkedList.playground │ ├── Contents.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata ├── LinkedList.swift ├── README.markdown └── Tests │ ├── Info.plist │ ├── LinkedListTests.swift │ └── Tests.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ └── contents.xcworkspacedata │ └── xcshareddata │ └── xcschemes │ └── Tests.xcscheme ├── Longest Common Subsequence ├── LongestCommonSubsequence.playground │ ├── Contents.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata ├── LongestCommonSubsequence.swift ├── README.markdown └── Tests │ ├── LongestCommonSubsequenceTests.swift │ ├── Tests.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ └── contents.xcworkspacedata │ └── xcshareddata │ │ └── xcschemes │ │ └── Tests.xcscheme │ └── Tests │ └── Info.plist ├── Merge Sort ├── MergeSort.playground │ ├── Contents.swift │ ├── contents.xcplayground │ ├── playground.xcworkspace │ │ └── contents.xcworkspacedata │ └── timeline.xctimeline ├── MergeSort.swift └── README.markdown ├── Miller-Rabin Primality Test ├── Images │ └── img_pseudo.png ├── MRPrimality.playground │ ├── Contents.swift │ ├── Sources │ │ └── MRPrimality.swift │ └── contents.xcplayground ├── MRPrimality.swift └── README.markdown ├── Minimum Edit Distance ├── MinimumEditDistance.playground │ ├── Contents.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata └── README.markdown ├── Minimum Spanning Tree (Unweighted) ├── Images │ ├── Graph.png │ ├── Graph.sketch │ ├── MinimumSpanningTree.png │ ├── MinimumSpanningTree.sketch │ ├── Tree.graffle │ └── Tree.png ├── MinimumSpanningTree.playground │ ├── Pages │ │ └── Minimum spanning tree example.xcplaygroundpage │ │ │ └── Contents.swift │ ├── Resources │ │ └── Minimum_Spanning_Tree.png │ ├── Sources │ │ ├── Edge.swift │ │ ├── Graph.swift │ │ ├── Node.swift │ │ └── Queue.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata ├── MinimumSpanningTree.swift ├── README.markdown └── Tests │ ├── Graph.swift │ ├── Info.plist │ ├── MinimumSpanningTreeTests.swift │ ├── Queue.swift │ └── Tests.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ └── contents.xcworkspacedata │ └── xcshareddata │ └── xcschemes │ └── Tests.xcscheme ├── Monty Hall Problem ├── MontyHall.playground │ ├── Contents.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata └── README.markdown ├── Ordered Array ├── OrderedArray.playground │ ├── Contents.swift │ ├── contents.xcplayground │ ├── playground.xcworkspace │ │ └── contents.xcworkspacedata │ └── timeline.xctimeline ├── OrderedArray.swift └── README.markdown ├── Ordered Set ├── OrderedSet.playground │ ├── Pages │ │ ├── Example 1.xcplaygroundpage │ │ │ ├── Contents.swift │ │ │ └── timeline.xctimeline │ │ ├── Example 2.xcplaygroundpage │ │ │ └── Contents.swift │ │ └── Example 3.xcplaygroundpage │ │ │ ├── Contents.swift │ │ │ └── timeline.xctimeline │ ├── Sources │ │ ├── OrderedSet.swift │ │ ├── Player.swift │ │ └── Random.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata ├── OrderedSet.swift └── README.markdown ├── Palindromes ├── Palindromes.playground │ ├── Contents.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata ├── Palindromes.swift ├── README.markdown └── Test │ ├── Palindromes.swift │ ├── Test.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ └── contents.xcworkspacedata │ └── xcshareddata │ │ └── xcschemes │ │ └── Test.xcscheme │ └── Test │ ├── Info.plist │ └── Test.swift ├── Priority Queue ├── PriorityQueue.swift ├── README.markdown └── Tests │ ├── Info.plist │ ├── PriorityQueueTests.swift │ └── Tests.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ └── contents.xcworkspacedata │ └── xcshareddata │ └── xcschemes │ └── Tests.xcscheme ├── Queue ├── Queue-Optimized.swift ├── Queue-Simple.swift ├── Queue.playground │ ├── Contents.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata ├── README.markdown └── Tests │ ├── Info.plist │ ├── QueueTests.swift │ └── Tests.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ └── contents.xcworkspacedata │ └── xcshareddata │ └── xcschemes │ └── Tests.xcscheme ├── Quicksort ├── Images │ ├── Example.graffle │ └── Example.png ├── Quicksort.playground │ ├── Contents.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata ├── Quicksort.swift ├── README.markdown └── Tests │ ├── Info.plist │ ├── QuicksortTests.swift │ ├── SortingTestHelpers.swift │ └── Tests.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ └── contents.xcworkspacedata │ └── xcshareddata │ └── xcschemes │ └── Tests.xcscheme ├── README.markdown ├── Rabin-Karp ├── README.markdown ├── Rabin-Karp.playground │ ├── Contents.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata └── rabin-karp.swift ├── Radix Sort ├── RadixSort.playground │ ├── Contents.swift │ ├── Sources │ │ └── radixSort.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata ├── ReadMe.md ├── Tests │ ├── Info.plist │ ├── RadixSortTests.swift │ └── Tests.xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ └── contents.xcworkspacedata │ │ └── xcshareddata │ │ └── xcschemes │ │ └── Tests.xcscheme └── radixSort.swift ├── Radix Tree ├── Images │ └── radixtree.png ├── README.markdown ├── RadixTree.playground │ ├── Contents.swift │ ├── Sources │ │ └── RadixTree.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata └── RadixTree.swift ├── Red-Black Tree ├── README.markdown └── Red-Black Tree 2.playground │ ├── Contents.swift │ ├── Sources │ └── RBTree.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ └── contents.xcworkspacedata ├── Ring Buffer ├── README.markdown ├── RingBuffer.playground │ ├── Contents.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata └── RingBuffer.swift ├── Rootish Array Stack ├── README.md ├── RootishArrayStack.playground │ ├── Contents.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata ├── RootishArrayStack.swift ├── Tests │ ├── Info.plist │ ├── RootishArrayStack.swift │ ├── RootishArrayStackTests.swift │ └── Tests.xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ └── contents.xcworkspacedata │ │ └── xcshareddata │ │ └── xcschemes │ │ └── Tests.xcscheme └── images │ ├── RootishArrayStackExample.png │ ├── RootishArrayStackExample2.png │ └── RootishArrayStackIntro.png ├── Run-Length Encoding ├── README.markdown └── RLE.playground │ ├── Contents.swift │ ├── Sources │ └── RLE.swift │ ├── contents.xcplayground │ ├── playground.xcworkspace │ └── contents.xcworkspacedata │ └── timeline.xctimeline ├── Segment Tree ├── Images │ ├── EqualSegments.png │ ├── LeftSegment.png │ ├── MixedSegment.png │ ├── RightSegment.png │ └── Structure.png ├── README.markdown ├── SegmentTree.playground │ ├── Contents.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata └── SegmentTree.swift ├── Select Minimum Maximum ├── Maximum.swift ├── Minimum.swift ├── MinimumMaximumPairs.swift ├── README.markdown ├── SelectMinimumMaximum.playground │ ├── Contents.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata └── Tests │ ├── Info.plist │ ├── MaximumTests.swift │ ├── MinimumMaximumPairsTests.swift │ ├── MinimumTests.swift │ ├── TestHelper.swift │ └── Tests.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ └── contents.xcworkspacedata │ └── xcshareddata │ └── xcschemes │ └── Tests.xcscheme ├── Selection Sampling ├── README.markdown ├── SelectionSampling.playground │ ├── Contents.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata └── SelectionSampling.swift ├── Selection Sort ├── README.markdown ├── SelectionSort.playground │ ├── Contents.swift │ ├── contents.xcplayground │ ├── playground.xcworkspace │ │ └── contents.xcworkspacedata │ └── timeline.xctimeline ├── SelectionSort.swift └── Tests │ ├── Info.plist │ ├── SelectionSortTests.swift │ └── Tests.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ └── contents.xcworkspacedata │ └── xcshareddata │ └── xcschemes │ └── Tests.xcscheme ├── Set Cover (Unweighted) ├── README.markdown ├── SetCover.playground │ ├── Contents.swift │ ├── Sources │ │ ├── RandomArrayOfSets.swift │ │ └── SetCover.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata └── SetCover.swift ├── Shell Sort ├── README.markdown ├── Tests │ ├── Info.plist │ ├── ShellSortTests.swift │ └── Tests.xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ └── contents.xcworkspacedata │ │ └── xcshareddata │ │ └── xcschemes │ │ └── Tests.xcscheme └── shellsort.swift ├── Shortest Path (Unweighted) ├── Images │ ├── Graph.graffle │ └── Graph.png ├── README.markdown ├── ShortestPath.playground │ ├── Pages │ │ └── Shortest path example.xcplaygroundpage │ │ │ └── Contents.swift │ ├── Sources │ │ ├── Edge.swift │ │ ├── Graph.swift │ │ ├── Node.swift │ │ └── Queue.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata ├── ShortestPath.swift └── Tests │ ├── Graph.swift │ ├── Info.plist │ ├── Queue.swift │ ├── ShortestPathTests.swift │ └── Tests.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ └── contents.xcworkspacedata │ └── xcshareddata │ └── xcschemes │ └── Tests.xcscheme ├── Shuffle ├── README.markdown ├── Shuffle.playground │ ├── Contents.swift │ ├── contents.xcplayground │ ├── playground.xcworkspace │ │ └── contents.xcworkspacedata │ └── timeline.xctimeline └── Shuffle.swift ├── Shunting Yard ├── README.markdown ├── ShuntingYard.playground │ ├── Contents.swift │ ├── Sources │ │ └── Stack.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata └── ShuntingYard.swift ├── Single-Source Shortest Paths (Weighted) ├── README.markdown ├── SSSP.playground │ ├── Contents.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata ├── SSSP.xcodeproj │ ├── project.pbxproj │ └── xcshareddata │ │ └── xcschemes │ │ ├── SSSP.xcscheme │ │ └── SSSPTests.xcscheme ├── SSSP.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── WorkspaceSettings.xcsettings ├── SSSP │ ├── BellmanFord.swift │ ├── Info.plist │ ├── SSSP.h │ └── SSSP.swift ├── SSSPTests │ ├── Info.plist │ └── SSSPTests.swift └── img │ ├── example_graph.png │ └── negative_cycle_example.png ├── Skip-List ├── Images │ ├── Insert1.png │ ├── Insert10.png │ ├── Insert11.png │ ├── Insert12.png │ ├── Insert2.png │ ├── Insert3.png │ ├── Insert4.png │ ├── Insert5.png │ ├── Insert6.png │ ├── Insert8.png │ ├── Insert9.png │ ├── Intro.png │ ├── Search1.png │ └── insert7.png ├── README.md └── SkipList.swift ├── Slow Sort ├── README.markdown └── SlowSort.swift ├── Stack ├── README.markdown ├── Stack.playground │ ├── Contents.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata ├── Stack.swift └── Tests │ ├── Info.plist │ ├── StackTests.swift │ └── Tests.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ └── contents.xcworkspacedata │ └── xcshareddata │ └── xcschemes │ └── Tests.xcscheme ├── Ternary Search Tree ├── README.markdown ├── TST.playground │ ├── Contents.swift │ ├── Sources │ │ ├── TSTNode.swift │ │ ├── TernarySearchTree.swift │ │ └── Utils.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata ├── TSTNode.swift ├── TernarySearchTree.swift ├── Tests │ ├── Info.plist │ ├── TernarySearchTreeTests.swift │ └── Tests.xcodeproj │ │ ├── project.pbxproj │ │ └── xcshareddata │ │ └── xcschemes │ │ └── Tests.xcscheme └── Utils.swift ├── Threaded Binary Tree ├── Images │ ├── Base.png │ ├── Full.png │ ├── Insert1.png │ ├── Insert2.png │ ├── Insert3.png │ ├── Partial.png │ ├── Remove1.png │ ├── Remove2.png │ ├── Remove3.png │ └── Remove4.png ├── README.markdown └── ThreadedBinaryTree.playground │ ├── Contents.swift │ ├── Sources │ └── ThreadedBinaryTree.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ └── contents.xcworkspacedata ├── Topological Sort ├── Graph.swift ├── Images │ ├── Algorithms.graffle │ ├── Algorithms.png │ ├── Example.graffle │ ├── Example.png │ ├── Graph.graffle │ ├── Graph.png │ ├── GraphResult.graffle │ ├── GraphResult.png │ ├── InvalidSort.graffle │ ├── InvalidSort.png │ ├── TopologicalSort.graffle │ └── TopologicalSort.png ├── README.markdown ├── Tests │ ├── Info.plist │ ├── Tests.xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ │ └── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── Tests.xcscheme │ └── TopologicalSortTests.swift ├── Topological Sort.playground │ ├── Contents.swift │ ├── Sources │ │ ├── Graph.swift │ │ ├── TopologicalSort1.swift │ │ ├── TopologicalSort2.swift │ │ └── TopologicalSort3.swift │ ├── contents.xcplayground │ ├── playground.xcworkspace │ │ └── contents.xcworkspacedata │ └── timeline.xctimeline ├── TopologicalSort1.swift ├── TopologicalSort2.swift └── TopologicalSort3.swift ├── Treap ├── Treap.swift ├── Treap │ ├── Treap.xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ └── xcshareddata │ │ │ │ └── WorkspaceSettings.xcsettings │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── Tests.xcscheme │ ├── Treap │ │ └── Info.plist │ └── TreapTests │ │ ├── Info.plist │ │ └── TreapTests.swift ├── TreapCollectionType.swift └── TreapMergeSplit.swift ├── Tree ├── Images │ ├── Cycles.graffle │ ├── Cycles.png │ ├── Example.graffle │ ├── Example.png │ ├── ParentChildren.graffle │ ├── ParentChildren.png │ ├── Tree.graffle │ └── Tree.png ├── README.markdown ├── Tree.playground │ ├── Contents.swift │ ├── contents.xcplayground │ ├── playground.xcworkspace │ │ └── contents.xcworkspacedata │ └── timeline.xctimeline └── Tree.swift ├── Trie ├── ReadMe.md ├── Trie.playground │ ├── Contents.swift │ ├── Sources │ │ └── Trie.swift │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata ├── Trie │ ├── Trie.xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ │ └── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── xcbaselines │ │ │ └── EB798E0A1DFEF79900F0628D.xcbaseline │ │ │ ├── 6ABF2F62-9363-4450-8DE1-D20F57026950.plist │ │ │ └── Info.plist │ ├── Trie │ │ ├── AppDelegate.swift │ │ ├── Assets.xcassets │ │ │ └── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ ├── Base.lproj │ │ │ └── Main.storyboard │ │ ├── Info.plist │ │ ├── ReadMe.md │ │ ├── Trie.swift │ │ ├── ViewController.swift │ │ └── dictionary.txt │ ├── TrieTests │ │ ├── Info.plist │ │ └── TrieTests.swift │ └── TrieUITests │ │ ├── Info.plist │ │ └── TrieUITests.swift └── images │ └── trie.png ├── Two-Sum Problem ├── README.markdown ├── Solution 1 │ └── 2Sum.playground │ │ ├── Contents.swift │ │ ├── contents.xcplayground │ │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata └── Solution 2 │ └── 2Sum.playground │ ├── Contents.swift │ ├── contents.xcplayground │ ├── playground.xcworkspace │ └── contents.xcworkspacedata │ └── timeline.xctimeline ├── Under Construction.markdown ├── Union-Find ├── Images │ ├── AfterFind.png │ ├── AfterUnion.png │ ├── BeforeFind.png │ └── BeforeUnion.png ├── README.markdown ├── UnionFind.playground │ ├── Contents.swift │ ├── contents.xcplayground │ ├── playground.xcworkspace │ │ └── contents.xcworkspacedata │ └── timeline.xctimeline └── UnionFind.swift ├── What are Algorithms.markdown ├── Why Algorithms.markdown ├── Z-Algorithm ├── README.markdown ├── ZAlgorithm.swift ├── ZetaAlgorithm.playground │ ├── Contents.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ │ └── contents.xcworkspacedata └── ZetaAlgorithm.swift ├── install_swiftlint.sh └── swift-algorithm-club.xcworkspace └── contents.xcworkspacedata /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | build/ 3 | DerivedData/ 4 | 5 | *.pbxuser 6 | *.mode1v3 7 | *.mode2v3 8 | *.perspectivev3 9 | *.xccheckout 10 | *.moved-aside 11 | *.xcuserstate 12 | 13 | xcuserdata 14 | 15 | !default.pbxuser 16 | !default.mode1v3 17 | !default.mode2v3 18 | !default.perspectivev3 19 | !default.xcworkspace 20 | 21 | profile 22 | *.hmap 23 | *.ipa 24 | 25 | # CocoaPods 26 | Pods/ 27 | !Podfile.lock 28 | 29 | # Temporary files 30 | .DS_Store 31 | .Trashes 32 | .Spotlight-V100 33 | *.swp 34 | *.lock 35 | -------------------------------------------------------------------------------- /.swiftlint.yml: -------------------------------------------------------------------------------- 1 | cyclomatic_complexity: 12 2 | file_length: 550 3 | function_body_length: 80 4 | function_parameter_count: 8 5 | line_length: 150 6 | type_body_length: 300 7 | variable_name: 8 | min_length: 9 | error: 1 10 | warning: 1 11 | excluded: 12 | - N 13 | 14 | disabled_rules: 15 | - valid_docs 16 | 17 | custom_rules: 18 | smiley_face: 19 | name: "Smiley Face" 20 | regex: "(\:\))" 21 | match_kinds: 22 | - comment 23 | - string 24 | message: "A closing parenthesis smiley :) creates a half-hearted smile, and thus is not preferred. Use :]" 25 | severity: warning 26 | -------------------------------------------------------------------------------- /AVL Tree/AVLTree.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | //: Playground - noun: a place where people can play 2 | 3 | let tree = AVLTree() 4 | 5 | tree.insert(key: 5, payload: "five") 6 | print(tree) 7 | 8 | tree.insert(key: 4, payload: "four") 9 | print(tree) 10 | 11 | tree.insert(key: 3, payload: "three") 12 | print(tree) 13 | 14 | tree.insert(key: 2, payload: "two") 15 | print(tree) 16 | 17 | tree.insert(key: 1, payload: "one") 18 | print(tree) 19 | print(tree.debugDescription) 20 | 21 | let node = tree.search(input: 2) // "two" 22 | 23 | tree.delete(key: 5) 24 | tree.delete(key: 2) 25 | tree.delete(key: 1) 26 | tree.delete(key: 4) 27 | tree.delete(key: 3) 28 | -------------------------------------------------------------------------------- /AVL Tree/AVLTree.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /AVL Tree/AVLTree.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /AVL Tree/Images/BalanceNotOK.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/AVL Tree/Images/BalanceNotOK.graffle -------------------------------------------------------------------------------- /AVL Tree/Images/BalanceNotOK.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/AVL Tree/Images/BalanceNotOK.png -------------------------------------------------------------------------------- /AVL Tree/Images/BalanceOK.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/AVL Tree/Images/BalanceOK.graffle -------------------------------------------------------------------------------- /AVL Tree/Images/BalanceOK.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/AVL Tree/Images/BalanceOK.png -------------------------------------------------------------------------------- /AVL Tree/Images/Balanced.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/AVL Tree/Images/Balanced.graffle -------------------------------------------------------------------------------- /AVL Tree/Images/Balanced.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/AVL Tree/Images/Balanced.png -------------------------------------------------------------------------------- /AVL Tree/Images/Height.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/AVL Tree/Images/Height.graffle -------------------------------------------------------------------------------- /AVL Tree/Images/Height.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/AVL Tree/Images/Height.png -------------------------------------------------------------------------------- /AVL Tree/Images/RotationStep0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/AVL Tree/Images/RotationStep0.jpg -------------------------------------------------------------------------------- /AVL Tree/Images/RotationStep1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/AVL Tree/Images/RotationStep1.jpg -------------------------------------------------------------------------------- /AVL Tree/Images/RotationStep2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/AVL Tree/Images/RotationStep2.jpg -------------------------------------------------------------------------------- /AVL Tree/Images/RotationStep3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/AVL Tree/Images/RotationStep3.jpg -------------------------------------------------------------------------------- /AVL Tree/Images/Unbalanced.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/AVL Tree/Images/Unbalanced.graffle -------------------------------------------------------------------------------- /AVL Tree/Images/Unbalanced.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/AVL Tree/Images/Unbalanced.png -------------------------------------------------------------------------------- /AVL Tree/Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /AVL Tree/Tests/Tests.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /All-Pairs Shortest Paths/APSP/APSP.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /All-Pairs Shortest Paths/APSP/APSP.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /All-Pairs Shortest Paths/APSP/APSP.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /All-Pairs Shortest Paths/APSP/APSP.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /All-Pairs Shortest Paths/APSP/APSP.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /All-Pairs Shortest Paths/APSP/APSP.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /All-Pairs Shortest Paths/APSP/APSP/APSP.h: -------------------------------------------------------------------------------- 1 | // 2 | // APSP.h 3 | // APSP 4 | // 5 | // Created by Andrew McKnight on 5/6/16. 6 | // 7 | 8 | #import 9 | 10 | //! Project version number for APSP. 11 | FOUNDATION_EXPORT double APSPVersionNumber; 12 | 13 | //! Project version string for APSP. 14 | FOUNDATION_EXPORT const unsigned char APSPVersionString[]; 15 | 16 | // In this header, you should import all the public headers of your framework using statements like #import 17 | 18 | 19 | -------------------------------------------------------------------------------- /All-Pairs Shortest Paths/img/d0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/All-Pairs Shortest Paths/img/d0.png -------------------------------------------------------------------------------- /All-Pairs Shortest Paths/img/d1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/All-Pairs Shortest Paths/img/d1.png -------------------------------------------------------------------------------- /All-Pairs Shortest Paths/img/d2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/All-Pairs Shortest Paths/img/d2.png -------------------------------------------------------------------------------- /All-Pairs Shortest Paths/img/d3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/All-Pairs Shortest Paths/img/d3.png -------------------------------------------------------------------------------- /All-Pairs Shortest Paths/img/example_graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/All-Pairs Shortest Paths/img/example_graph.png -------------------------------------------------------------------------------- /All-Pairs Shortest Paths/img/original_adjacency_matrix.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/All-Pairs Shortest Paths/img/original_adjacency_matrix.png -------------------------------------------------------------------------------- /All-Pairs Shortest Paths/img/pi0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/All-Pairs Shortest Paths/img/pi0.png -------------------------------------------------------------------------------- /All-Pairs Shortest Paths/img/pi1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/All-Pairs Shortest Paths/img/pi1.png -------------------------------------------------------------------------------- /All-Pairs Shortest Paths/img/pi2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/All-Pairs Shortest Paths/img/pi2.png -------------------------------------------------------------------------------- /All-Pairs Shortest Paths/img/pi3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/All-Pairs Shortest Paths/img/pi3.png -------------------------------------------------------------------------------- /All-Pairs Shortest Paths/img/weight_comparison_formula.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/All-Pairs Shortest Paths/img/weight_comparison_formula.png -------------------------------------------------------------------------------- /Array2D/Array2D.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Array2D/Array2D.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Array2D/Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Array2D/Tests/Tests.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /B-Tree/BTree.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | //: Playground - noun: a place where people can play 2 | 3 | import Foundation 4 | 5 | let bTree = BTree(order: 1)! 6 | 7 | bTree.insert(1, for: 1) 8 | bTree.insert(2, for: 2) 9 | bTree.insert(3, for: 3) 10 | bTree.insert(4, for: 4) 11 | 12 | bTree.value(for: 3) 13 | bTree[3] 14 | 15 | bTree.remove(2) 16 | 17 | bTree.traverseKeysInOrder { 18 | key in 19 | print(key) 20 | } 21 | 22 | bTree.numberOfKeys 23 | 24 | bTree.order 25 | 26 | bTree.inorderArrayFromKeys 27 | -------------------------------------------------------------------------------- /B-Tree/BTree.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /B-Tree/BTree.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /B-Tree/Images/BTree20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/B-Tree/Images/BTree20.png -------------------------------------------------------------------------------- /B-Tree/Images/InsertionSplit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/B-Tree/Images/InsertionSplit.png -------------------------------------------------------------------------------- /B-Tree/Images/MergingNodes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/B-Tree/Images/MergingNodes.png -------------------------------------------------------------------------------- /B-Tree/Images/MovingKey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/B-Tree/Images/MovingKey.png -------------------------------------------------------------------------------- /B-Tree/Images/Node.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/B-Tree/Images/Node.png -------------------------------------------------------------------------------- /B-Tree/Tests/Tests.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /B-Tree/Tests/Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Binary Search Tree/Images/DeleteLeaf.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Binary Search Tree/Images/DeleteLeaf.graffle -------------------------------------------------------------------------------- /Binary Search Tree/Images/DeleteLeaf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Binary Search Tree/Images/DeleteLeaf.png -------------------------------------------------------------------------------- /Binary Search Tree/Images/DeleteOneChild.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Binary Search Tree/Images/DeleteOneChild.graffle -------------------------------------------------------------------------------- /Binary Search Tree/Images/DeleteOneChild.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Binary Search Tree/Images/DeleteOneChild.png -------------------------------------------------------------------------------- /Binary Search Tree/Images/DeleteTwoChildren.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Binary Search Tree/Images/DeleteTwoChildren.graffle -------------------------------------------------------------------------------- /Binary Search Tree/Images/DeleteTwoChildren.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Binary Search Tree/Images/DeleteTwoChildren.png -------------------------------------------------------------------------------- /Binary Search Tree/Images/MinimumMaximum.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Binary Search Tree/Images/MinimumMaximum.graffle -------------------------------------------------------------------------------- /Binary Search Tree/Images/MinimumMaximum.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Binary Search Tree/Images/MinimumMaximum.png -------------------------------------------------------------------------------- /Binary Search Tree/Images/Searching.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Binary Search Tree/Images/Searching.graffle -------------------------------------------------------------------------------- /Binary Search Tree/Images/Searching.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Binary Search Tree/Images/Searching.png -------------------------------------------------------------------------------- /Binary Search Tree/Images/Traversing.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Binary Search Tree/Images/Traversing.graffle -------------------------------------------------------------------------------- /Binary Search Tree/Images/Traversing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Binary Search Tree/Images/Traversing.png -------------------------------------------------------------------------------- /Binary Search Tree/Images/Tree1.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Binary Search Tree/Images/Tree1.graffle -------------------------------------------------------------------------------- /Binary Search Tree/Images/Tree1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Binary Search Tree/Images/Tree1.png -------------------------------------------------------------------------------- /Binary Search Tree/Images/Tree2.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Binary Search Tree/Images/Tree2.graffle -------------------------------------------------------------------------------- /Binary Search Tree/Images/Tree2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Binary Search Tree/Images/Tree2.png -------------------------------------------------------------------------------- /Binary Search Tree/Solution 1/BinarySearchTree.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Binary Search Tree/Solution 1/BinarySearchTree.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Binary Search Tree/Solution 1/BinarySearchTree.playground/timeline.xctimeline: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Binary Search Tree/Solution 2/BinarySearchTree.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | //: Playground - noun: a place where people can play 2 | 3 | // Each time you insert something, you get back a completely new tree. 4 | var tree = BinarySearchTree.leaf(7) 5 | tree = tree.insert(newValue: 2) 6 | tree = tree.insert(newValue: 5) 7 | tree = tree.insert(newValue: 10) 8 | tree = tree.insert(newValue: 9) 9 | tree = tree.insert(newValue: 1) 10 | print(tree) 11 | 12 | tree.search(x: 10) 13 | tree.search(x: 1) 14 | tree.search(x: 11) 15 | -------------------------------------------------------------------------------- /Binary Search Tree/Solution 2/BinarySearchTree.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Binary Search Tree/Solution 2/BinarySearchTree.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Binary Search Tree/Solution 2/BinarySearchTree.playground/timeline.xctimeline: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Binary Search/BinarySearch.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Binary Search/BinarySearch.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Binary Search/BinarySearch.playground/timeline.xctimeline: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Binary Search/Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Binary Search/Tests/Tests.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Binary Tree/BinaryTree.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Binary Tree/BinaryTree.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Binary Tree/Images/BinaryTree.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Binary Tree/Images/BinaryTree.graffle -------------------------------------------------------------------------------- /Binary Tree/Images/BinaryTree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Binary Tree/Images/BinaryTree.png -------------------------------------------------------------------------------- /Binary Tree/Images/Operations.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Binary Tree/Images/Operations.graffle -------------------------------------------------------------------------------- /Binary Tree/Images/Operations.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Binary Tree/Images/Operations.png -------------------------------------------------------------------------------- /Bit Set/BitSet.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Bit Set/BitSet.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Bit Set/BitSet.playground/timeline.xctimeline: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Bloom Filter/BloomFilter.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Bloom Filter/BloomFilter.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Bloom Filter/BloomFilter.playground/timeline.xctimeline: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Bloom Filter/Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Bloom Filter/Tests/Tests.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Bounded Priority Queue/BoundedPriorityQueue.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Bounded Priority Queue/BoundedPriorityQueue.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Bounded Priority Queue/Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Bounded Priority Queue/Tests/Tests.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Bounded Priority Queue/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Boyer-Moore/BoyerMoore.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Boyer-Moore/BoyerMoore.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Boyer-Moore/Tests/BoyerMooreHorspoolTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // BoyerMooreHorspoolTests.swift 3 | // Tests 4 | // 5 | // Created by Matias Mazzei on 12/24/16. 6 | // Copyright © 2016 Swift Algorithm Club. All rights reserved. 7 | // 8 | 9 | class BoyerMooreHorspoolTests: BoyerMooreTest { 10 | override func setUp() { 11 | super.setUp() 12 | useHorspoolImprovement = false 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Boyer-Moore/Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Boyer-Moore/Tests/Tests.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Boyer-Moore/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Breadth-First Search/BreadthFirstSearch.playground/Sources/Edge.swift: -------------------------------------------------------------------------------- 1 | public class Edge: Equatable { 2 | public var neighbor: Node 3 | 4 | public init(_ neighbor: Node) { 5 | self.neighbor = neighbor 6 | } 7 | } 8 | 9 | public func == (_ lhs: Edge, rhs: Edge) -> Bool { 10 | return lhs.neighbor == rhs.neighbor 11 | } 12 | -------------------------------------------------------------------------------- /Breadth-First Search/BreadthFirstSearch.playground/Sources/Queue.swift: -------------------------------------------------------------------------------- 1 | public struct Queue { 2 | private var array: [T] 3 | 4 | public init() { 5 | array = [] 6 | } 7 | 8 | public var isEmpty: Bool { 9 | return array.isEmpty 10 | } 11 | 12 | public var count: Int { 13 | return array.count 14 | } 15 | 16 | public mutating func enqueue(_ element: T) { 17 | array.append(element) 18 | } 19 | 20 | public mutating func dequeue() -> T? { 21 | if isEmpty { 22 | return nil 23 | } else { 24 | return array.removeFirst() 25 | } 26 | } 27 | 28 | public func peek() -> T? { 29 | return array.first 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Breadth-First Search/BreadthFirstSearch.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Breadth-First Search/BreadthFirstSearch.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Breadth-First Search/BreadthFirstSearch.swift: -------------------------------------------------------------------------------- 1 | func breadthFirstSearch(_ graph: Graph, source: Node) -> [String] { 2 | var queue = Queue() 3 | queue.enqueue(source) 4 | 5 | var nodesExplored = [source.label] 6 | source.visited = true 7 | 8 | while let current = queue.dequeue() { 9 | for edge in current.neighbors { 10 | let neighborNode = edge.neighbor 11 | if !neighborNode.visited { 12 | queue.enqueue(neighborNode) 13 | neighborNode.visited = true 14 | nodesExplored.append(neighborNode.label) 15 | } 16 | } 17 | } 18 | 19 | return nodesExplored 20 | } 21 | -------------------------------------------------------------------------------- /Breadth-First Search/Images/AnimatedExample.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Breadth-First Search/Images/AnimatedExample.gif -------------------------------------------------------------------------------- /Breadth-First Search/Images/AnimatedExample.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Breadth-First Search/Images/AnimatedExample.graffle -------------------------------------------------------------------------------- /Breadth-First Search/Images/AnimatedExample.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Breadth-First Search/Images/AnimatedExample.psd -------------------------------------------------------------------------------- /Breadth-First Search/Images/TraversalTree.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Breadth-First Search/Images/TraversalTree.graffle -------------------------------------------------------------------------------- /Breadth-First Search/Images/TraversalTree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Breadth-First Search/Images/TraversalTree.png -------------------------------------------------------------------------------- /Breadth-First Search/Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Breadth-First Search/Tests/Queue.swift: -------------------------------------------------------------------------------- 1 | public struct Queue { 2 | private var array: [T] 3 | 4 | public init() { 5 | array = [] 6 | } 7 | 8 | public var isEmpty: Bool { 9 | return array.isEmpty 10 | } 11 | 12 | public var count: Int { 13 | return array.count 14 | } 15 | 16 | public mutating func enqueue(_ element: T) { 17 | array.append(element) 18 | } 19 | 20 | public mutating func dequeue() -> T? { 21 | if isEmpty { 22 | return nil 23 | } else { 24 | return array.removeFirst() 25 | } 26 | } 27 | 28 | public func peek() -> T? { 29 | return array.first 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Breadth-First Search/Tests/Tests.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Brute-Force String Search/BruteForceStringSearch.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | //: Playground - noun: a place where people can play 2 | 3 | extension String { 4 | func indexOf(_ pattern: String) -> String.Index? { 5 | 6 | for i in self.characters.indices { 7 | var j = i 8 | var found = true 9 | for p in pattern.characters.indices{ 10 | if j == self.characters.endIndex || self[j] != pattern[p] { 11 | found = false 12 | break 13 | } else { 14 | j = self.characters.index(after: j) 15 | } 16 | } 17 | if found { 18 | return i 19 | } 20 | } 21 | return nil 22 | } 23 | } 24 | 25 | 26 | 27 | // A few simple tests 28 | 29 | let s = "Hello, World" 30 | s.indexOf("World") // 7 31 | 32 | let animals = "🐶🐔🐷🐮🐱" 33 | animals.indexOf("🐮") // 6 34 | -------------------------------------------------------------------------------- /Brute-Force String Search/BruteForceStringSearch.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Brute-Force String Search/BruteForceStringSearch.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Brute-Force String Search/BruteForceStringSearch.swift: -------------------------------------------------------------------------------- 1 | /* 2 | Brute-force string search 3 | */ 4 | extension String { 5 | func indexOf(_ pattern: String) -> String.Index? { 6 | for i in self.characters.indices { 7 | var j = i 8 | var found = true 9 | for p in pattern.characters.indices{ 10 | if j == self.characters.endIndex || self[j] != pattern[p] { 11 | found = false 12 | break 13 | } else { 14 | j = self.characters.index(after: j) 15 | } 16 | } 17 | if found { 18 | return i 19 | } 20 | } 21 | return nil 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Bucket Sort/BucketSort.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Bucket Sort/BucketSort.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Bucket Sort/Docs/BucketSort.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Bucket Sort/Docs/BucketSort.png -------------------------------------------------------------------------------- /Bucket Sort/Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Bucket Sort/Tests/Tests.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Comb Sort/Comb Sort.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | // Comb Sort Function 2 | // Created by Stephen Rutstein 3 | // 7-16-2016 4 | 5 | import Cocoa 6 | 7 | // Test Comb Sort with small array of ten values 8 | let array = [2, 32, 9, -1, 89, 101, 55, -10, -12, 67] 9 | combSort(array) 10 | 11 | // Test Comb Sort with large array of 1000 random values 12 | var bigArray = [Int](repeating: 0, count: 1000) 13 | var i = 0 14 | while i < 1000 { 15 | bigArray[i] = Int(arc4random_uniform(1000) + 1) 16 | i += 1 17 | } 18 | combSort(bigArray) 19 | 20 | 21 | -------------------------------------------------------------------------------- /Comb Sort/Comb Sort.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Comb Sort/Comb Sort.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Comb Sort/Tests/CombSortTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CombSortTests.swift 3 | // Tests 4 | // 5 | // Created by theng on 2017-01-09. 6 | // Copyright © 2017 Swift Algorithm Club. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | 11 | class CombSortTests: XCTestCase { 12 | var sequence: [Int]! 13 | let expectedSequence: [Int] = [-12, -10, -1, 2, 9, 32, 55, 67, 89, 101] 14 | 15 | override func setUp() { 16 | super.setUp() 17 | sequence = [2, 32, 9, -1, 89, 101, 55, -10, -12, 67] 18 | } 19 | 20 | override func tearDown() { 21 | super.tearDown() 22 | } 23 | 24 | func testCombSort() { 25 | let sortedSequence = combSort(sequence) 26 | XCTAssertEqual(sortedSequence, expectedSequence) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Comb Sort/Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /Comb Sort/Tests/Tests.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Combinatorics/Combinatorics.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Combinatorics/Combinatorics.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Combinatorics/Combinatorics.playground/timeline.xctimeline: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Count Occurrences/CountOccurrences.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Count Occurrences/CountOccurrences.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Count Occurrences/CountOccurrences.playground/timeline.xctimeline: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Counting Sort/CountingSort.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Counting Sort/CountingSort.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Counting Sort/Tests/CountingSortTest.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CountingSort.swift 3 | // CountingSort 4 | // 5 | // Created by Kauserali on 11/04/16. 6 | // 7 | // 8 | 9 | import XCTest 10 | 11 | class CountingSort: XCTestCase { 12 | 13 | func testCountingSort() { 14 | let sequence = [10, 8, 1, 2, 5, 8] 15 | let sortedSequence = [1, 2, 5, 8, 8, 10] 16 | 17 | do { 18 | let afterCountingSort = try countingSort(sequence) 19 | XCTAssertEqual(afterCountingSort, sortedSequence) 20 | } catch { 21 | XCTFail("") 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Counting Sort/Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Counting Sort/Tests/Tests.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Depth-First Search/DepthFirstSearch.playground/Sources/Edge.swift: -------------------------------------------------------------------------------- 1 | public class Edge: Equatable { 2 | public var neighbor: Node 3 | 4 | public init(_ neighbor: Node) { 5 | self.neighbor = neighbor 6 | } 7 | } 8 | 9 | public func == (_ lhs: Edge, rhs: Edge) -> Bool { 10 | return lhs.neighbor == rhs.neighbor 11 | } 12 | -------------------------------------------------------------------------------- /Depth-First Search/DepthFirstSearch.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Depth-First Search/DepthFirstSearch.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Depth-First Search/DepthFirstSearch.swift: -------------------------------------------------------------------------------- 1 | func depthFirstSearch(_ graph: Graph, source: Node) -> [String] { 2 | var nodesExplored = [source.label] 3 | source.visited = true 4 | 5 | for edge in source.neighbors { 6 | if !edge.neighbor.visited { 7 | nodesExplored += depthFirstSearch(graph, source: edge.neighbor) 8 | } 9 | } 10 | return nodesExplored 11 | } 12 | -------------------------------------------------------------------------------- /Depth-First Search/Images/AnimatedExample.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Depth-First Search/Images/AnimatedExample.gif -------------------------------------------------------------------------------- /Depth-First Search/Images/AnimatedExample.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Depth-First Search/Images/AnimatedExample.graffle -------------------------------------------------------------------------------- /Depth-First Search/Images/AnimatedExample.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Depth-First Search/Images/AnimatedExample.psd -------------------------------------------------------------------------------- /Depth-First Search/Images/TraversalTree.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Depth-First Search/Images/TraversalTree.graffle -------------------------------------------------------------------------------- /Depth-First Search/Images/TraversalTree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Depth-First Search/Images/TraversalTree.png -------------------------------------------------------------------------------- /Depth-First Search/Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Depth-First Search/Tests/Tests.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Depth-First Search/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Deque/Deque.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Deque/Deque.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /DiningPhilosophers/DiningPhilosophers.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /DiningPhilosophers/DiningPhilosophers.xcodeproj/xcshareddata/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | SchemeUserState 5 | 6 | DiningPhilosophers.xcscheme 7 | 8 | 9 | SuppressBuildableAutocreation 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /DiningPhilosophers/Package.swift: -------------------------------------------------------------------------------- 1 | import PackageDescription 2 | 3 | let package = Package( 4 | name: "DiningPhilosophers" 5 | ) 6 | -------------------------------------------------------------------------------- /Fixed Size Array/FixedSizeArray.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Fixed Size Array/FixedSizeArray.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Fixed Size Array/Images/FixedSizeArrays.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Fixed Size Array/Images/FixedSizeArrays.graffle -------------------------------------------------------------------------------- /Fixed Size Array/Images/append.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Fixed Size Array/Images/append.png -------------------------------------------------------------------------------- /Fixed Size Array/Images/array.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Fixed Size Array/Images/array.png -------------------------------------------------------------------------------- /Fixed Size Array/Images/delete-no-copy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Fixed Size Array/Images/delete-no-copy.png -------------------------------------------------------------------------------- /Fixed Size Array/Images/delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Fixed Size Array/Images/delete.png -------------------------------------------------------------------------------- /Fixed Size Array/Images/indexing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Fixed Size Array/Images/indexing.png -------------------------------------------------------------------------------- /Fixed Size Array/Images/insert.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Fixed Size Array/Images/insert.png -------------------------------------------------------------------------------- /Fizz Buzz/FizzBuzz.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | func fizzBuzz(_ numberOfTurns: Int) { 2 | for i in 1...numberOfTurns { 3 | var result = "" 4 | 5 | if i % 3 == 0 { 6 | result += "Fizz" 7 | } 8 | 9 | if i % 5 == 0 { 10 | result += (result.isEmpty ? "" : " ") + "Buzz" 11 | } 12 | 13 | if result.isEmpty { 14 | result += "\(i)" 15 | } 16 | 17 | print(result) 18 | } 19 | } 20 | 21 | fizzBuzz(100) 22 | -------------------------------------------------------------------------------- /Fizz Buzz/FizzBuzz.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Fizz Buzz/FizzBuzz.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Fizz Buzz/FizzBuzz.swift: -------------------------------------------------------------------------------- 1 | func fizzBuzz(_ numberOfTurns: Int) { 2 | for i in 1...numberOfTurns { 3 | var result = "" 4 | 5 | if i % 3 == 0 { 6 | result += "Fizz" 7 | } 8 | 9 | if i % 5 == 0 { 10 | result += (result.isEmpty ? "" : " ") + "Buzz" 11 | } 12 | 13 | if result.isEmpty { 14 | result += "\(i)" 15 | } 16 | 17 | print(result) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /GCD/GCD.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | //: Playground - noun: a place where people can play 2 | 3 | // Recursive version 4 | func gcd(_ a: Int, _ b: Int) -> Int { 5 | let r = a % b 6 | if r != 0 { 7 | return gcd(b, r) 8 | } else { 9 | return b 10 | } 11 | } 12 | 13 | /* 14 | // Iterative version 15 | func gcd(m: Int, _ n: Int) -> Int { 16 | var a = 0 17 | var b = max(m, n) 18 | var r = min(m, n) 19 | 20 | while r != 0 { 21 | a = b 22 | b = r 23 | r = a % b 24 | } 25 | return b 26 | } 27 | */ 28 | 29 | func lcm(_ m: Int, _ n: Int) -> Int { 30 | return m*n / gcd(m, n) 31 | } 32 | 33 | gcd(52, 39) // 13 34 | gcd(228, 36) // 12 35 | gcd(51357, 3819) // 57 36 | gcd(841, 299) // 1 37 | 38 | lcm(2, 3) // 6 39 | lcm(10, 8) // 40 40 | -------------------------------------------------------------------------------- /GCD/GCD.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /GCD/GCD.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /GCD/GCD.playground/timeline.xctimeline: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /GCD/GCD.swift: -------------------------------------------------------------------------------- 1 | /* 2 | Euclid's algorithm for finding the greatest common divisor 3 | */ 4 | func gcd(_ m: Int, _ n: Int) -> Int { 5 | var a = 0 6 | var b = max(m, n) 7 | var r = min(m, n) 8 | 9 | while r != 0 { 10 | a = b 11 | b = r 12 | r = a % b 13 | } 14 | return b 15 | } 16 | 17 | /* 18 | // Recursive version 19 | func gcd(_ a: Int, _ b: Int) -> Int { 20 | let r = a % b 21 | if r != 0 { 22 | return gcd(b, r) 23 | } else { 24 | return b 25 | } 26 | } 27 | */ 28 | 29 | /* 30 | Returns the least common multiple of two numbers. 31 | */ 32 | func lcm(_ m: Int, _ n: Int) -> Int { 33 | return m*n / gcd(m, n) 34 | } 35 | -------------------------------------------------------------------------------- /Graph/Graph.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Graph/Graph.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Graph/Graph.playground/timeline.xctimeline: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Graph/Graph.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | -------------------------------------------------------------------------------- /Graph/Graph.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Graph/Graph.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Graph/Graph/Graph.h: -------------------------------------------------------------------------------- 1 | // 2 | // Graph.h 3 | // Graph 4 | // 5 | // Created by Andrew McKnight on 5/8/16. 6 | // 7 | 8 | #import 9 | 10 | //! Project version number for Graph. 11 | FOUNDATION_EXPORT double GraphVersionNumber; 12 | 13 | //! Project version string for Graph. 14 | FOUNDATION_EXPORT const unsigned char GraphVersionString[]; 15 | 16 | // In this header, you should import all the public headers of your framework using statements like #import 17 | 18 | 19 | -------------------------------------------------------------------------------- /Graph/GraphTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Graph/Images/AdjacencyList.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Graph/Images/AdjacencyList.graffle -------------------------------------------------------------------------------- /Graph/Images/AdjacencyList.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Graph/Images/AdjacencyList.png -------------------------------------------------------------------------------- /Graph/Images/AdjacencyMatrix.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Graph/Images/AdjacencyMatrix.graffle -------------------------------------------------------------------------------- /Graph/Images/AdjacencyMatrix.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Graph/Images/AdjacencyMatrix.png -------------------------------------------------------------------------------- /Graph/Images/ChordMap.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Graph/Images/ChordMap.graffle -------------------------------------------------------------------------------- /Graph/Images/ChordMap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Graph/Images/ChordMap.png -------------------------------------------------------------------------------- /Graph/Images/CoreData.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Graph/Images/CoreData.graffle -------------------------------------------------------------------------------- /Graph/Images/CoreData.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Graph/Images/CoreData.png -------------------------------------------------------------------------------- /Graph/Images/DAG.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Graph/Images/DAG.graffle -------------------------------------------------------------------------------- /Graph/Images/DAG.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Graph/Images/DAG.png -------------------------------------------------------------------------------- /Graph/Images/Demo1.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Graph/Images/Demo1.graffle -------------------------------------------------------------------------------- /Graph/Images/Demo1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Graph/Images/Demo1.png -------------------------------------------------------------------------------- /Graph/Images/Flights.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Graph/Images/Flights.graffle -------------------------------------------------------------------------------- /Graph/Images/Flights.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Graph/Images/Flights.png -------------------------------------------------------------------------------- /Graph/Images/FlightsDirected.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Graph/Images/FlightsDirected.graffle -------------------------------------------------------------------------------- /Graph/Images/FlightsDirected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Graph/Images/FlightsDirected.png -------------------------------------------------------------------------------- /Graph/Images/Graph.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Graph/Images/Graph.graffle -------------------------------------------------------------------------------- /Graph/Images/Graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Graph/Images/Graph.png -------------------------------------------------------------------------------- /Graph/Images/SocialNetwork.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Graph/Images/SocialNetwork.graffle -------------------------------------------------------------------------------- /Graph/Images/SocialNetwork.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Graph/Images/SocialNetwork.png -------------------------------------------------------------------------------- /Graph/Images/StateMachine.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Graph/Images/StateMachine.graffle -------------------------------------------------------------------------------- /Graph/Images/StateMachine.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Graph/Images/StateMachine.png -------------------------------------------------------------------------------- /Graph/Images/Tasks.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Graph/Images/Tasks.graffle -------------------------------------------------------------------------------- /Graph/Images/Tasks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Graph/Images/Tasks.png -------------------------------------------------------------------------------- /Graph/Images/TreeAndList.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Graph/Images/TreeAndList.graffle -------------------------------------------------------------------------------- /Graph/Images/TreeAndList.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Graph/Images/TreeAndList.png -------------------------------------------------------------------------------- /Hash Set/HashSet.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Hash Set/HashSet.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Hash Set/HashSet.playground/timeline.xctimeline: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Hash Set/Images/CombineSets.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Hash Set/Images/CombineSets.png -------------------------------------------------------------------------------- /Hash Table/HashTable.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Hash Table/HashTable.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /HaversineDistance/HaversineDistance.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /HaversineDistance/HaversineDistance.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Heap Sort/HeapSort.swift: -------------------------------------------------------------------------------- 1 | extension Heap { 2 | public mutating func sort() -> [T] { 3 | for i in stride(from: (elements.count - 1), through: 1, by: -1) { 4 | swap(&elements[0], &elements[i]) 5 | shiftDown(0, heapSize: i) 6 | } 7 | return elements 8 | } 9 | } 10 | 11 | /* 12 | Sorts an array using a heap. 13 | Heapsort can be performed in-place, but it is not a stable sort. 14 | */ 15 | public func heapsort(_ a: [T], _ sort: @escaping (T, T) -> Bool) -> [T] { 16 | let reverseOrder = { i1, i2 in sort(i2, i1) } 17 | var h = Heap(array: a, sort: reverseOrder) 18 | return h.sort() 19 | } 20 | -------------------------------------------------------------------------------- /Heap Sort/Images/MaxHeap.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Heap Sort/Images/MaxHeap.graffle -------------------------------------------------------------------------------- /Heap Sort/Images/MaxHeap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Heap Sort/Images/MaxHeap.png -------------------------------------------------------------------------------- /Heap Sort/Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Heap Sort/Tests/Tests.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Heap/Images/Array.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Heap/Images/Array.graffle -------------------------------------------------------------------------------- /Heap/Images/Array.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Heap/Images/Array.png -------------------------------------------------------------------------------- /Heap/Images/Heap1.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Heap/Images/Heap1.graffle -------------------------------------------------------------------------------- /Heap/Images/Heap1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Heap/Images/Heap1.png -------------------------------------------------------------------------------- /Heap/Images/HeapShape.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Heap/Images/HeapShape.graffle -------------------------------------------------------------------------------- /Heap/Images/HeapShape.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Heap/Images/HeapShape.png -------------------------------------------------------------------------------- /Heap/Images/Insert1.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Heap/Images/Insert1.graffle -------------------------------------------------------------------------------- /Heap/Images/Insert1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Heap/Images/Insert1.png -------------------------------------------------------------------------------- /Heap/Images/Insert2.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Heap/Images/Insert2.graffle -------------------------------------------------------------------------------- /Heap/Images/Insert2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Heap/Images/Insert2.png -------------------------------------------------------------------------------- /Heap/Images/Insert3.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Heap/Images/Insert3.graffle -------------------------------------------------------------------------------- /Heap/Images/Insert3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Heap/Images/Insert3.png -------------------------------------------------------------------------------- /Heap/Images/LargeHeap.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Heap/Images/LargeHeap.graffle -------------------------------------------------------------------------------- /Heap/Images/LargeHeap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Heap/Images/LargeHeap.png -------------------------------------------------------------------------------- /Heap/Images/RegularTree.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Heap/Images/RegularTree.graffle -------------------------------------------------------------------------------- /Heap/Images/RegularTree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Heap/Images/RegularTree.png -------------------------------------------------------------------------------- /Heap/Images/Remove1.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Heap/Images/Remove1.graffle -------------------------------------------------------------------------------- /Heap/Images/Remove1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Heap/Images/Remove1.png -------------------------------------------------------------------------------- /Heap/Images/Remove2.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Heap/Images/Remove2.graffle -------------------------------------------------------------------------------- /Heap/Images/Remove2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Heap/Images/Remove2.png -------------------------------------------------------------------------------- /Heap/Images/Remove3.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Heap/Images/Remove3.graffle -------------------------------------------------------------------------------- /Heap/Images/Remove3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Heap/Images/Remove3.png -------------------------------------------------------------------------------- /Heap/Images/Remove4.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Heap/Images/Remove4.graffle -------------------------------------------------------------------------------- /Heap/Images/Remove4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Heap/Images/Remove4.png -------------------------------------------------------------------------------- /Heap/Images/Remove5.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Heap/Images/Remove5.graffle -------------------------------------------------------------------------------- /Heap/Images/Remove5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Heap/Images/Remove5.png -------------------------------------------------------------------------------- /Heap/Images/SortedArray.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Heap/Images/SortedArray.graffle -------------------------------------------------------------------------------- /Heap/Images/SortedArray.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Heap/Images/SortedArray.png -------------------------------------------------------------------------------- /Heap/Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Heap/Tests/Tests.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Huffman Coding/Huffman.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | //: Playground - noun: a place where people can play 2 | 3 | import Foundation 4 | 5 | let s1 = "so much words wow many compression" 6 | if let originalData = s1.data(using: .utf8) { 7 | print(originalData.count) 8 | 9 | let huffman1 = Huffman() 10 | let compressedData = huffman1.compressData(data: originalData as NSData) 11 | print(compressedData.length) 12 | 13 | let frequencyTable = huffman1.frequencyTable() 14 | //print(frequencyTable) 15 | 16 | let huffman2 = Huffman() 17 | let decompressedData = huffman2.decompressData(data: compressedData, frequencyTable: frequencyTable) 18 | print(decompressedData.length) 19 | 20 | let s2 = String(data: decompressedData as Data, encoding: .utf8)! 21 | print(s2) 22 | assert(s1 == s2) 23 | } 24 | -------------------------------------------------------------------------------- /Huffman Coding/Huffman.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Huffman Coding/Huffman.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Huffman Coding/Images/BuildTree.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Huffman Coding/Images/BuildTree.gif -------------------------------------------------------------------------------- /Huffman Coding/Images/BuildTree.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Huffman Coding/Images/BuildTree.graffle -------------------------------------------------------------------------------- /Huffman Coding/Images/BuildTree.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Huffman Coding/Images/BuildTree.psd -------------------------------------------------------------------------------- /Huffman Coding/Images/Compression.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Huffman Coding/Images/Compression.graffle -------------------------------------------------------------------------------- /Huffman Coding/Images/Compression.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Huffman Coding/Images/Compression.png -------------------------------------------------------------------------------- /Huffman Coding/Images/Decompression.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Huffman Coding/Images/Decompression.graffle -------------------------------------------------------------------------------- /Huffman Coding/Images/Decompression.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Huffman Coding/Images/Decompression.png -------------------------------------------------------------------------------- /Huffman Coding/Images/Tree.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Huffman Coding/Images/Tree.graffle -------------------------------------------------------------------------------- /Huffman Coding/Images/Tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Huffman Coding/Images/Tree.png -------------------------------------------------------------------------------- /Images/SwiftAlgorithm-410-transp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Images/SwiftAlgorithm-410-transp.png -------------------------------------------------------------------------------- /Images/scheme-settings-for-travis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Images/scheme-settings-for-travis.png -------------------------------------------------------------------------------- /Insertion Sort/InsertionSort.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | //: Playground - noun: a place where people can play 2 | 3 | func insertionSort(_ array: [T], _ isOrderedBefore: (T, T) -> Bool) -> [T] { 4 | var a = array 5 | for x in 1.. 0 && isOrderedBefore(temp, a[y - 1]) { 9 | a[y] = a[y - 1] 10 | y -= 1 11 | } 12 | a[y] = temp 13 | } 14 | return a 15 | } 16 | 17 | let list = [ 10, -1, 3, 9, 2, 27, 8, 5, 1, 3, 0, 26 ] 18 | insertionSort(list, <) 19 | insertionSort(list, >) -------------------------------------------------------------------------------- /Insertion Sort/InsertionSort.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Insertion Sort/InsertionSort.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Insertion Sort/InsertionSort.playground/timeline.xctimeline: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Insertion Sort/InsertionSort.swift: -------------------------------------------------------------------------------- 1 | func insertionSort(_ array: [T], _ isOrderedBefore: (T, T) -> Bool) -> [T] { 2 | guard array.count > 1 else { return array } 3 | 4 | var a = array 5 | for x in 1.. 0 && isOrderedBefore(temp, a[y - 1]) { 9 | a[y] = a[y - 1] 10 | y -= 1 11 | } 12 | a[y] = temp 13 | } 14 | return a 15 | } 16 | -------------------------------------------------------------------------------- /Insertion Sort/Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Insertion Sort/Tests/InsertionSortTests.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | 3 | class InsertionSortTests: XCTestCase { 4 | func testInsertionSort() { 5 | checkSortAlgorithm(insertionSort) 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Insertion Sort/Tests/Tests.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /K-Means/Images/k_means_bad1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/K-Means/Images/k_means_bad1.png -------------------------------------------------------------------------------- /K-Means/Images/k_means_bad2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/K-Means/Images/k_means_bad2.png -------------------------------------------------------------------------------- /K-Means/Images/k_means_good.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/K-Means/Images/k_means_good.png -------------------------------------------------------------------------------- /K-Means/Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /K-Means/Tests/Tests.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Karatsuba Multiplication/KaratsubaMultiplication.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Karatsuba Multiplication/KaratsubaMultiplication.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Knuth-Morris-Pratt/KnuthMorrisPratt.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Knuth-Morris-Pratt/KnuthMorrisPratt.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Kth Largest Element/kthLargest.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Kth Largest Element/kthLargest.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Linear Regression/Images/graph1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Linear Regression/Images/graph1.png -------------------------------------------------------------------------------- /Linear Regression/Images/graph2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Linear Regression/Images/graph2.png -------------------------------------------------------------------------------- /Linear Regression/Images/graph3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Linear Regression/Images/graph3.png -------------------------------------------------------------------------------- /Linear Regression/LinearRegression.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Linear Regression/LinearRegression.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Linear Search/LinearSearch.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | //: Playground - noun: a place where people can play 2 | 3 | func linearSearch(_ array: [T], _ object: T) -> Int? { 4 | for (index, obj) in array.enumerated() where obj == object { 5 | return index 6 | } 7 | return nil 8 | } 9 | 10 | let array = [5, 2, 4, 7] 11 | linearSearch(array, 2) // returns 1 12 | linearSearch(array, 3) // returns nil 13 | -------------------------------------------------------------------------------- /Linear Search/LinearSearch.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Linear Search/LinearSearch.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Linear Search/LinearSearch.playground/timeline.xctimeline: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Linear Search/LinearSearch.swift: -------------------------------------------------------------------------------- 1 | func linearSearch(_ array: [T], _ object: T) -> Int? { 2 | for (index, obj) in array.enumerated() where obj == object { 3 | return index 4 | } 5 | return nil 6 | } 7 | -------------------------------------------------------------------------------- /Linked List/LinkedList.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Linked List/LinkedList.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Linked List/Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Linked List/Tests/Tests.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Longest Common Subsequence/LongestCommonSubsequence.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Longest Common Subsequence/LongestCommonSubsequence.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Longest Common Subsequence/Tests/Tests.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Merge Sort/MergeSort.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Merge Sort/MergeSort.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Merge Sort/MergeSort.playground/timeline.xctimeline: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Miller-Rabin Primality Test/Images/img_pseudo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Miller-Rabin Primality Test/Images/img_pseudo.png -------------------------------------------------------------------------------- /Miller-Rabin Primality Test/MRPrimality.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | //: Playground - noun: a place where people can play 2 | 3 | // Real primes 4 | mrPrimalityTest(5) 5 | mrPrimalityTest(439) 6 | mrPrimalityTest(1201) 7 | mrPrimalityTest(143477) 8 | mrPrimalityTest(1299869) 9 | mrPrimalityTest(15487361) 10 | mrPrimalityTest(179426363) 11 | mrPrimalityTest(32416187747) 12 | 13 | // Fake primes 14 | mrPrimalityTest(15) 15 | mrPrimalityTest(435) 16 | mrPrimalityTest(1207) 17 | mrPrimalityTest(143473) 18 | mrPrimalityTest(1291869) 19 | mrPrimalityTest(15487161) 20 | mrPrimalityTest(178426363) 21 | mrPrimalityTest(32415187747) 22 | 23 | // With iteration 24 | mrPrimalityTest(32416190071, iteration: 10) -------------------------------------------------------------------------------- /Miller-Rabin Primality Test/MRPrimality.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Minimum Edit Distance/MinimumEditDistance.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Minimum Edit Distance/MinimumEditDistance.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Minimum Spanning Tree (Unweighted)/Images/Graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Minimum Spanning Tree (Unweighted)/Images/Graph.png -------------------------------------------------------------------------------- /Minimum Spanning Tree (Unweighted)/Images/Graph.sketch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Minimum Spanning Tree (Unweighted)/Images/Graph.sketch -------------------------------------------------------------------------------- /Minimum Spanning Tree (Unweighted)/Images/MinimumSpanningTree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Minimum Spanning Tree (Unweighted)/Images/MinimumSpanningTree.png -------------------------------------------------------------------------------- /Minimum Spanning Tree (Unweighted)/Images/MinimumSpanningTree.sketch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Minimum Spanning Tree (Unweighted)/Images/MinimumSpanningTree.sketch -------------------------------------------------------------------------------- /Minimum Spanning Tree (Unweighted)/Images/Tree.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Minimum Spanning Tree (Unweighted)/Images/Tree.graffle -------------------------------------------------------------------------------- /Minimum Spanning Tree (Unweighted)/Images/Tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Minimum Spanning Tree (Unweighted)/Images/Tree.png -------------------------------------------------------------------------------- /Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/Resources/Minimum_Spanning_Tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/Resources/Minimum_Spanning_Tree.png -------------------------------------------------------------------------------- /Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/Sources/Edge.swift: -------------------------------------------------------------------------------- 1 | public class Edge: Equatable { 2 | public var neighbor: Node 3 | 4 | public init(neighbor: Node) { 5 | self.neighbor = neighbor 6 | } 7 | } 8 | 9 | public func == (lhs: Edge, rhs: Edge) -> Bool { 10 | return lhs.neighbor == rhs.neighbor 11 | } 12 | -------------------------------------------------------------------------------- /Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/Sources/Queue.swift: -------------------------------------------------------------------------------- 1 | public struct Queue { 2 | private var array: [T] 3 | 4 | public init() { 5 | array = [] 6 | } 7 | 8 | public var isEmpty: Bool { 9 | return array.isEmpty 10 | } 11 | 12 | public var count: Int { 13 | return array.count 14 | } 15 | 16 | public mutating func enqueue(_ element: T) { 17 | array.append(element) 18 | } 19 | 20 | public mutating func dequeue() -> T? { 21 | if isEmpty { 22 | return nil 23 | } else { 24 | return array.removeFirst() 25 | } 26 | } 27 | 28 | public func peek() -> T? { 29 | return array.first 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.swift: -------------------------------------------------------------------------------- 1 | func breadthFirstSearchMinimumSpanningTree(_ graph: Graph, source: Node) -> Graph { 2 | let minimumSpanningTree = graph.duplicate() 3 | 4 | var queue = Queue() 5 | let sourceInMinimumSpanningTree = minimumSpanningTree.findNodeWithLabel(source.label) 6 | queue.enqueue(sourceInMinimumSpanningTree) 7 | sourceInMinimumSpanningTree.visited = true 8 | 9 | while let current = queue.dequeue() { 10 | for edge in current.neighbors { 11 | let neighborNode = edge.neighbor 12 | if !neighborNode.visited { 13 | neighborNode.visited = true 14 | queue.enqueue(neighborNode) 15 | } else { 16 | current.remove(edge) 17 | } 18 | } 19 | } 20 | 21 | return minimumSpanningTree 22 | } 23 | -------------------------------------------------------------------------------- /Minimum Spanning Tree (Unweighted)/Tests/Queue.swift: -------------------------------------------------------------------------------- 1 | public struct Queue { 2 | private var array: [T] 3 | 4 | public init() { 5 | array = [] 6 | } 7 | 8 | public var isEmpty: Bool { 9 | return array.isEmpty 10 | } 11 | 12 | public var count: Int { 13 | return array.count 14 | } 15 | 16 | public mutating func enqueue(_ element: T) { 17 | array.append(element) 18 | } 19 | 20 | public mutating func dequeue() -> T? { 21 | if isEmpty { 22 | return nil 23 | } else { 24 | return array.removeFirst() 25 | } 26 | } 27 | 28 | public func peek() -> T? { 29 | return array.first 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Minimum Spanning Tree (Unweighted)/Tests/Tests.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Monty Hall Problem/MontyHall.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Monty Hall Problem/MontyHall.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Ordered Array/OrderedArray.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Ordered Array/OrderedArray.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Ordered Array/OrderedArray.playground/timeline.xctimeline: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Ordered Set/OrderedSet.playground/Pages/Example 1.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: # Example 1 with type Int 2 | 3 | var mySet = OrderedSet() 4 | 5 | // Insert random numbers into the set 6 | for _ in 0..<50 { 7 | mySet.insert(random(min: 50, max: 500)) 8 | } 9 | 10 | print(mySet) 11 | 12 | print("\nMaximum:") 13 | print(mySet.max()) 14 | 15 | print("\nMinimum:") 16 | print(mySet.min()) 17 | 18 | // Print the 5 largest values 19 | print("\n5 Largest:") 20 | for k in 1...5 { 21 | print(mySet.kLargest(k)) 22 | } 23 | 24 | // Print the 5 lowest values 25 | print("\n5 Smallest:") 26 | for k in 1...5 { 27 | print(mySet.kSmallest(k)) 28 | } 29 | 30 | //: [Next](@next) 31 | -------------------------------------------------------------------------------- /Ordered Set/OrderedSet.playground/Pages/Example 3.xcplaygroundpage/timeline.xctimeline: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Ordered Set/OrderedSet.playground/Sources/Random.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | // Returns a random number between the given range. 4 | public func random(min: Int, max: Int) -> Int { 5 | return min + Int(arc4random_uniform(UInt32(max - min + 1))) 6 | } 7 | 8 | // Generates a random alphanumeric string of a given length. 9 | extension String { 10 | public static func random(length: Int = 8) -> String { 11 | let base = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" 12 | var randomString: String = "" 13 | 14 | for _ in 0.. 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Ordered Set/OrderedSet.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Palindromes/Palindromes.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Palindromes/Palindromes.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Palindromes/Palindromes.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | func isPalindrome(_ str: String) -> Bool { 4 | let strippedString = str.replacingOccurrences(of: "\\W", with: "", options: .regularExpression, range: nil) 5 | let length = strippedString.characters.count 6 | 7 | if length > 1 { 8 | return palindrome(strippedString.lowercased(), left: 0, right: length - 1) 9 | } 10 | return false 11 | } 12 | 13 | private func palindrome(_ str: String, left: Int, right: Int) -> Bool { 14 | if left >= right { 15 | return true 16 | } 17 | 18 | let lhs = str[str.index(str.startIndex, offsetBy: left)] 19 | let rhs = str[str.index(str.startIndex, offsetBy: right)] 20 | 21 | if lhs != rhs { 22 | return false 23 | } 24 | 25 | return palindrome(str, left: left + 1, right: right - 1) 26 | } 27 | -------------------------------------------------------------------------------- /Palindromes/Test/Test.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Palindromes/Test/Test/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /Priority Queue/Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Priority Queue/Tests/Tests.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Queue/Queue.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Queue/Queue.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Queue/Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Queue/Tests/Tests.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Quicksort/Images/Example.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Quicksort/Images/Example.graffle -------------------------------------------------------------------------------- /Quicksort/Images/Example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Quicksort/Images/Example.png -------------------------------------------------------------------------------- /Quicksort/Quicksort.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Quicksort/Quicksort.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Quicksort/Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Quicksort/Tests/Tests.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Rabin-Karp/Rabin-Karp.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Rabin-Karp/Rabin-Karp.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Radix Sort/RadixSort.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | //: Playground - noun: a place where people can play 2 | 3 | import Cocoa 4 | 5 | // Test Radix Sort with small array of ten values 6 | var array: [Int] = [19, 4242, 2, 9, 912, 101, 55, 67, 89, 32] 7 | radixSort(&array) 8 | 9 | // Test Radix Sort with large array of 1000 random values 10 | var bigArray = [Int](repeating: 0, count: 1000) 11 | var i = 0 12 | while i < 1000 { 13 | bigArray[i] = Int(arc4random_uniform(1000) + 1) 14 | i += 1 15 | } 16 | radixSort(&bigArray) 17 | -------------------------------------------------------------------------------- /Radix Sort/RadixSort.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Radix Sort/RadixSort.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Radix Sort/Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /Radix Sort/Tests/RadixSortTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // RadixSortTests.swift 3 | // Tests 4 | // 5 | // Created by theng on 2017-01-10. 6 | // Copyright © 2017 Swift Algorithm Club. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | 11 | class RadixSortTests: XCTestCase { 12 | func testCombSort() { 13 | let expectedSequence: [Int] = [2, 9, 19, 32, 55, 67, 89, 101, 912, 4242] 14 | var sequence = [19, 4242, 2, 9, 912, 101, 55, 67, 89, 32] 15 | radixSort(&sequence) 16 | XCTAssertEqual(sequence, expectedSequence) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Radix Sort/Tests/Tests.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Radix Tree/Images/radixtree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Radix Tree/Images/radixtree.png -------------------------------------------------------------------------------- /Radix Tree/RadixTree.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Radix Tree/RadixTree.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Red-Black Tree/Red-Black Tree 2.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | //: Playground - noun: a place where people can play 2 | import Foundation 3 | 4 | let tree = RBTree() 5 | let randomMax = Double(0x100000000) 6 | var values = [Double]() 7 | for _ in 0..<1000 { 8 | let value = Double(arc4random()) / randomMax 9 | values.append(value) 10 | tree.insert(value) 11 | } 12 | tree.verify() 13 | 14 | for _ in 0..<1000 { 15 | let rand = arc4random_uniform(UInt32(values.count)) 16 | let index = Int(rand) 17 | let value = values.remove(at: index) 18 | tree.delete(value) 19 | } 20 | tree.verify() 21 | -------------------------------------------------------------------------------- /Red-Black Tree/Red-Black Tree 2.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Red-Black Tree/Red-Black Tree 2.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Ring Buffer/RingBuffer.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Ring Buffer/RingBuffer.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Rootish Array Stack/RootishArrayStack.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Rootish Array Stack/RootishArrayStack.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Rootish Array Stack/Tests/Tests.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Rootish Array Stack/images/RootishArrayStackExample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Rootish Array Stack/images/RootishArrayStackExample.png -------------------------------------------------------------------------------- /Rootish Array Stack/images/RootishArrayStackExample2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Rootish Array Stack/images/RootishArrayStackExample2.png -------------------------------------------------------------------------------- /Rootish Array Stack/images/RootishArrayStackIntro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Rootish Array Stack/images/RootishArrayStackIntro.png -------------------------------------------------------------------------------- /Run-Length Encoding/RLE.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Run-Length Encoding/RLE.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Run-Length Encoding/RLE.playground/timeline.xctimeline: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Segment Tree/Images/EqualSegments.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Segment Tree/Images/EqualSegments.png -------------------------------------------------------------------------------- /Segment Tree/Images/LeftSegment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Segment Tree/Images/LeftSegment.png -------------------------------------------------------------------------------- /Segment Tree/Images/MixedSegment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Segment Tree/Images/MixedSegment.png -------------------------------------------------------------------------------- /Segment Tree/Images/RightSegment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Segment Tree/Images/RightSegment.png -------------------------------------------------------------------------------- /Segment Tree/Images/Structure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Segment Tree/Images/Structure.png -------------------------------------------------------------------------------- /Segment Tree/SegmentTree.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Segment Tree/SegmentTree.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Select Minimum Maximum/Maximum.swift: -------------------------------------------------------------------------------- 1 | /* 2 | Finds the maximum value in an array in O(n) time. 3 | */ 4 | 5 | func maximum(_ array: [T]) -> T? { 6 | var array = array 7 | guard !array.isEmpty else { 8 | return nil 9 | } 10 | 11 | var maximum = array.removeFirst() 12 | for element in array { 13 | maximum = element > maximum ? element : maximum 14 | } 15 | return maximum 16 | } 17 | -------------------------------------------------------------------------------- /Select Minimum Maximum/Minimum.swift: -------------------------------------------------------------------------------- 1 | /* 2 | Finds the minimum value in an array in O(n) time. 3 | */ 4 | 5 | func minimum(_ array: [T]) -> T? { 6 | var array = array 7 | guard !array.isEmpty else { 8 | return nil 9 | } 10 | 11 | var minimum = array.removeFirst() 12 | for element in array { 13 | minimum = element < minimum ? element : minimum 14 | } 15 | return minimum 16 | } 17 | -------------------------------------------------------------------------------- /Select Minimum Maximum/SelectMinimumMaximum.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Select Minimum Maximum/SelectMinimumMaximum.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Select Minimum Maximum/Tests/TestHelper.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | func createRandomList(numberOfElements: Int) -> [UInt32] { 4 | return (1...numberOfElements).map {_ in arc4random()} 5 | } 6 | -------------------------------------------------------------------------------- /Select Minimum Maximum/Tests/Tests.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Selection Sampling/SelectionSampling.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Selection Sampling/SelectionSampling.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Selection Sort/SelectionSort.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | //: Playground - noun: a place where people can play 2 | 3 | func selectionSort(_ array: [T], _ isOrderedBefore: (T, T) -> Bool) -> [T] { 4 | guard array.count > 1 else { return array } 5 | var a = array 6 | for x in 0 ..< a.count - 1 { 7 | var lowest = x 8 | for y in x + 1 ..< a.count { 9 | if isOrderedBefore(a[y], a[lowest]) { 10 | lowest = y 11 | } 12 | } 13 | if x != lowest { 14 | swap(&a[x], &a[lowest]) 15 | } 16 | } 17 | return a 18 | } 19 | 20 | let list = [ 10, -1, 3, 9, 2, 27, 8, 5, 1, 3, 0, 26 ] 21 | selectionSort(list, <) 22 | selectionSort(list, >) 23 | -------------------------------------------------------------------------------- /Selection Sort/SelectionSort.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Selection Sort/SelectionSort.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Selection Sort/SelectionSort.playground/timeline.xctimeline: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Selection Sort/SelectionSort.swift: -------------------------------------------------------------------------------- 1 | func selectionSort(_ array: [T], _ isOrderedBefore: (T, T) -> Bool) -> [T] { 2 | guard array.count > 1 else { return array } 3 | 4 | var a = array 5 | for x in 0 ..< a.count - 1 { 6 | 7 | // Find the lowest value in the rest of the array. 8 | var lowest = x 9 | for y in x + 1 ..< a.count { 10 | if isOrderedBefore(a[y], a[lowest]) { 11 | lowest = y 12 | } 13 | } 14 | 15 | // Swap the lowest value with the current array index. 16 | if x != lowest { 17 | swap(&a[x], &a[lowest]) 18 | } 19 | } 20 | return a 21 | } 22 | -------------------------------------------------------------------------------- /Selection Sort/Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Selection Sort/Tests/SelectionSortTests.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | 3 | class SelectionSortTests: XCTestCase { 4 | func testSelectionSort() { 5 | checkSortAlgorithm(selectionSort) 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Selection Sort/Tests/Tests.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Set Cover (Unweighted)/SetCover.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Set Cover (Unweighted)/SetCover.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Shell Sort/Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Shell Sort/Tests/ShellSortTests.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | 3 | class ShellSortTests: XCTestCase { 4 | func testShellSort() { 5 | checkSortAlgorithm { (a: [Int]) -> [Int] in 6 | var b = a 7 | shellSort(&b) 8 | return b 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Shell Sort/Tests/Tests.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Shortest Path (Unweighted)/Images/Graph.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Shortest Path (Unweighted)/Images/Graph.graffle -------------------------------------------------------------------------------- /Shortest Path (Unweighted)/Images/Graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Shortest Path (Unweighted)/Images/Graph.png -------------------------------------------------------------------------------- /Shortest Path (Unweighted)/ShortestPath.playground/Sources/Edge.swift: -------------------------------------------------------------------------------- 1 | public class Edge: Equatable { 2 | public var neighbor: Node 3 | 4 | public init(neighbor: Node) { 5 | self.neighbor = neighbor 6 | } 7 | } 8 | 9 | public func == (lhs: Edge, rhs: Edge) -> Bool { 10 | return lhs.neighbor == rhs.neighbor 11 | } 12 | -------------------------------------------------------------------------------- /Shortest Path (Unweighted)/ShortestPath.playground/Sources/Queue.swift: -------------------------------------------------------------------------------- 1 | public struct Queue { 2 | private var array: [T] 3 | 4 | public init() { 5 | array = [] 6 | } 7 | 8 | public var isEmpty: Bool { 9 | return array.isEmpty 10 | } 11 | 12 | public var count: Int { 13 | return array.count 14 | } 15 | 16 | public mutating func enqueue(element: T) { 17 | array.append(element) 18 | } 19 | 20 | public mutating func dequeue() -> T? { 21 | if isEmpty { 22 | return nil 23 | } else { 24 | return array.removeFirst() 25 | } 26 | } 27 | 28 | public func peek() -> T? { 29 | return array.first 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Shortest Path (Unweighted)/ShortestPath.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Shortest Path (Unweighted)/ShortestPath.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Shortest Path (Unweighted)/ShortestPath.swift: -------------------------------------------------------------------------------- 1 | func breadthFirstSearchShortestPath(graph: Graph, source: Node) -> Graph { 2 | let shortestPathGraph = graph.duplicate() 3 | 4 | var queue = Queue() 5 | let sourceInShortestPathsGraph = shortestPathGraph.findNodeWithLabel(label: source.label) 6 | queue.enqueue(element: sourceInShortestPathsGraph) 7 | sourceInShortestPathsGraph.distance = 0 8 | 9 | while let current = queue.dequeue() { 10 | for edge in current.neighbors { 11 | let neighborNode = edge.neighbor 12 | if !neighborNode.hasDistance { 13 | queue.enqueue(element: neighborNode) 14 | neighborNode.distance = current.distance! + 1 15 | } 16 | } 17 | } 18 | 19 | return shortestPathGraph 20 | } 21 | -------------------------------------------------------------------------------- /Shortest Path (Unweighted)/Tests/Queue.swift: -------------------------------------------------------------------------------- 1 | public struct Queue { 2 | fileprivate var array: [T] 3 | 4 | public init() { 5 | array = [] 6 | } 7 | 8 | public var isEmpty: Bool { 9 | return array.isEmpty 10 | } 11 | 12 | public var count: Int { 13 | return array.count 14 | } 15 | 16 | public mutating func enqueue(element: T) { 17 | array.append(element) 18 | } 19 | 20 | public mutating func dequeue() -> T? { 21 | if isEmpty { 22 | return nil 23 | } else { 24 | return array.removeFirst() 25 | } 26 | } 27 | 28 | public func peek() -> T? { 29 | return array.first 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Shortest Path (Unweighted)/Tests/Tests.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Shuffle/Shuffle.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Shuffle/Shuffle.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Shuffle/Shuffle.playground/timeline.xctimeline: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Shuffle/Shuffle.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | extension Array { 4 | /* 5 | Randomly shuffles the array in-place 6 | This is the Fisher-Yates algorithm, also known as the Knuth shuffle. 7 | Time complexity: O(n) 8 | */ 9 | public mutating func shuffle() { 10 | for i in (count - 1).stride(through: 1, by: -1) { 11 | let j = random(i + 1) 12 | if i != j { 13 | swap(&self[i], &self[j]) 14 | } 15 | } 16 | } 17 | } 18 | 19 | /* 20 | Simultaneously initializes an array with the values 0...n-1 and shuffles it. 21 | */ 22 | public func shuffledArray(n: Int) -> [Int] { 23 | var a = [Int](count: n, repeatedValue: 0) 24 | for i in 0.. 2 | 3 | 4 | -------------------------------------------------------------------------------- /Shunting Yard/ShuntingYard.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Single-Source Shortest Paths (Weighted)/SSSP.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Single-Source Shortest Paths (Weighted)/SSSP.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Single-Source Shortest Paths (Weighted)/SSSP.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Single-Source Shortest Paths (Weighted)/SSSP.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Single-Source Shortest Paths (Weighted)/SSSP/SSSP.h: -------------------------------------------------------------------------------- 1 | // 2 | // SSSP.h 3 | // SSSP 4 | // 5 | // Created by Andrew McKnight on 5/8/16. 6 | // 7 | 8 | #import 9 | 10 | //! Project version number for SSSP. 11 | FOUNDATION_EXPORT double SSSPVersionNumber; 12 | 13 | //! Project version string for SSSP. 14 | FOUNDATION_EXPORT const unsigned char SSSPVersionString[]; 15 | 16 | // In this header, you should import all the public headers of your framework using statements like #import 17 | 18 | 19 | -------------------------------------------------------------------------------- /Single-Source Shortest Paths (Weighted)/img/example_graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Single-Source Shortest Paths (Weighted)/img/example_graph.png -------------------------------------------------------------------------------- /Single-Source Shortest Paths (Weighted)/img/negative_cycle_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Single-Source Shortest Paths (Weighted)/img/negative_cycle_example.png -------------------------------------------------------------------------------- /Skip-List/Images/Insert1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Skip-List/Images/Insert1.png -------------------------------------------------------------------------------- /Skip-List/Images/Insert10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Skip-List/Images/Insert10.png -------------------------------------------------------------------------------- /Skip-List/Images/Insert11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Skip-List/Images/Insert11.png -------------------------------------------------------------------------------- /Skip-List/Images/Insert12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Skip-List/Images/Insert12.png -------------------------------------------------------------------------------- /Skip-List/Images/Insert2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Skip-List/Images/Insert2.png -------------------------------------------------------------------------------- /Skip-List/Images/Insert3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Skip-List/Images/Insert3.png -------------------------------------------------------------------------------- /Skip-List/Images/Insert4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Skip-List/Images/Insert4.png -------------------------------------------------------------------------------- /Skip-List/Images/Insert5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Skip-List/Images/Insert5.png -------------------------------------------------------------------------------- /Skip-List/Images/Insert6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Skip-List/Images/Insert6.png -------------------------------------------------------------------------------- /Skip-List/Images/Insert8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Skip-List/Images/Insert8.png -------------------------------------------------------------------------------- /Skip-List/Images/Insert9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Skip-List/Images/Insert9.png -------------------------------------------------------------------------------- /Skip-List/Images/Intro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Skip-List/Images/Intro.png -------------------------------------------------------------------------------- /Skip-List/Images/Search1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Skip-List/Images/Search1.png -------------------------------------------------------------------------------- /Skip-List/Images/insert7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Skip-List/Images/insert7.png -------------------------------------------------------------------------------- /Slow Sort/SlowSort.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SlowSort.swift 3 | // 4 | // 5 | // Created by Pope Lukas Schramm (Dabendorf Orthodox Religion) on 16-07-16. 6 | // 7 | // 8 | 9 | var numberList = [1,12,9,17,13,12] 10 | 11 | public func slowsort(_ i: Int, _ j: Int) { 12 | if i>=j { 13 | return 14 | } 15 | let m = (i+j)/2 16 | slowsort(i,m) 17 | slowsort(m+1,j) 18 | if numberList[j] < numberList[m] { 19 | let temp = numberList[j] 20 | numberList[j] = numberList[m] 21 | numberList[m] = temp 22 | } 23 | slowsort(i,j-1) 24 | } 25 | 26 | 27 | slowsort(0,numberList.count-1) 28 | print(numberList) 29 | -------------------------------------------------------------------------------- /Stack/Stack.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Stack/Stack.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Stack/Stack.swift: -------------------------------------------------------------------------------- 1 | /* 2 | Last-in first-out stack (LIFO) 3 | 4 | Push and pop are O(1) operations. 5 | */ 6 | public struct Stack { 7 | fileprivate var array = [T]() 8 | 9 | public var isEmpty: Bool { 10 | return array.isEmpty 11 | } 12 | 13 | public var count: Int { 14 | return array.count 15 | } 16 | 17 | public mutating func push(_ element: T) { 18 | array.append(element) 19 | } 20 | 21 | public mutating func pop() -> T? { 22 | return array.popLast() 23 | } 24 | 25 | public var top: T? { 26 | return array.last 27 | } 28 | } 29 | 30 | extension Stack: Sequence { 31 | public func makeIterator() -> AnyIterator { 32 | var curr = self 33 | return AnyIterator { 34 | _ -> T? in 35 | return curr.pop() 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Stack/Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Stack/Tests/Tests.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Ternary Search Tree/README.markdown: -------------------------------------------------------------------------------- 1 | # Ternary Search Tree (三元搜尋樹) 2 | 3 | Data structure and simple test in playground has been implemented. 4 | Documentation and examples coming soon!! :) 5 | -------------------------------------------------------------------------------- /Ternary Search Tree/TST.playground/Sources/TSTNode.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TSTNode.swift 3 | // 4 | // 5 | // Created by Siddharth Atre on 3/15/16. 6 | // 7 | // 8 | 9 | import Foundation 10 | 11 | class TSTNode { 12 | //Member properties of a particular node. 13 | var key: Character 14 | var data: Element? 15 | var hasData: Bool 16 | 17 | //Children 18 | var left: TSTNode?, right: TSTNode?, middle: TSTNode? 19 | 20 | 21 | init(key: Character, data: Element?) { 22 | self.key = key 23 | self.data = data 24 | self.hasData = (data != nil) 25 | } 26 | 27 | init(key: Character) { 28 | self.key = key 29 | self.data = nil 30 | self.hasData = false 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Ternary Search Tree/TST.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Ternary Search Tree/TST.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Ternary Search Tree/Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /Threaded Binary Tree/Images/Base.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Threaded Binary Tree/Images/Base.png -------------------------------------------------------------------------------- /Threaded Binary Tree/Images/Full.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Threaded Binary Tree/Images/Full.png -------------------------------------------------------------------------------- /Threaded Binary Tree/Images/Insert1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Threaded Binary Tree/Images/Insert1.png -------------------------------------------------------------------------------- /Threaded Binary Tree/Images/Insert2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Threaded Binary Tree/Images/Insert2.png -------------------------------------------------------------------------------- /Threaded Binary Tree/Images/Insert3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Threaded Binary Tree/Images/Insert3.png -------------------------------------------------------------------------------- /Threaded Binary Tree/Images/Partial.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Threaded Binary Tree/Images/Partial.png -------------------------------------------------------------------------------- /Threaded Binary Tree/Images/Remove1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Threaded Binary Tree/Images/Remove1.png -------------------------------------------------------------------------------- /Threaded Binary Tree/Images/Remove2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Threaded Binary Tree/Images/Remove2.png -------------------------------------------------------------------------------- /Threaded Binary Tree/Images/Remove3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Threaded Binary Tree/Images/Remove3.png -------------------------------------------------------------------------------- /Threaded Binary Tree/Images/Remove4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Threaded Binary Tree/Images/Remove4.png -------------------------------------------------------------------------------- /Threaded Binary Tree/ThreadedBinaryTree.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Threaded Binary Tree/ThreadedBinaryTree.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Topological Sort/Images/Algorithms.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Topological Sort/Images/Algorithms.graffle -------------------------------------------------------------------------------- /Topological Sort/Images/Algorithms.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Topological Sort/Images/Algorithms.png -------------------------------------------------------------------------------- /Topological Sort/Images/Example.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Topological Sort/Images/Example.graffle -------------------------------------------------------------------------------- /Topological Sort/Images/Example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Topological Sort/Images/Example.png -------------------------------------------------------------------------------- /Topological Sort/Images/Graph.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Topological Sort/Images/Graph.graffle -------------------------------------------------------------------------------- /Topological Sort/Images/Graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Topological Sort/Images/Graph.png -------------------------------------------------------------------------------- /Topological Sort/Images/GraphResult.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Topological Sort/Images/GraphResult.graffle -------------------------------------------------------------------------------- /Topological Sort/Images/GraphResult.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Topological Sort/Images/GraphResult.png -------------------------------------------------------------------------------- /Topological Sort/Images/InvalidSort.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Topological Sort/Images/InvalidSort.graffle -------------------------------------------------------------------------------- /Topological Sort/Images/InvalidSort.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Topological Sort/Images/InvalidSort.png -------------------------------------------------------------------------------- /Topological Sort/Images/TopologicalSort.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Topological Sort/Images/TopologicalSort.graffle -------------------------------------------------------------------------------- /Topological Sort/Images/TopologicalSort.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Topological Sort/Images/TopologicalSort.png -------------------------------------------------------------------------------- /Topological Sort/Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Topological Sort/Tests/Tests.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Topological Sort/Topological Sort.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Topological Sort/Topological Sort.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Topological Sort/Topological Sort.playground/timeline.xctimeline: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Treap/Treap/Treap.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Treap/Treap/Treap.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Treap/Treap/TreapTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Tree/Images/Cycles.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Tree/Images/Cycles.graffle -------------------------------------------------------------------------------- /Tree/Images/Cycles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Tree/Images/Cycles.png -------------------------------------------------------------------------------- /Tree/Images/Example.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Tree/Images/Example.graffle -------------------------------------------------------------------------------- /Tree/Images/Example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Tree/Images/Example.png -------------------------------------------------------------------------------- /Tree/Images/ParentChildren.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Tree/Images/ParentChildren.graffle -------------------------------------------------------------------------------- /Tree/Images/ParentChildren.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Tree/Images/ParentChildren.png -------------------------------------------------------------------------------- /Tree/Images/Tree.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Tree/Images/Tree.graffle -------------------------------------------------------------------------------- /Tree/Images/Tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Tree/Images/Tree.png -------------------------------------------------------------------------------- /Tree/Tree.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Tree/Tree.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Tree/Tree.playground/timeline.xctimeline: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Trie/Trie.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | let trie = Trie() 2 | 3 | trie.insert(word: "apple") 4 | trie.insert(word: "ap") 5 | trie.insert(word: "a") 6 | 7 | trie.contains(word: "apple") 8 | trie.contains(word: "ap") 9 | trie.contains(word: "a") 10 | 11 | trie.remove(word: "apple") 12 | trie.contains(word: "a") 13 | trie.contains(word: "apple") 14 | 15 | trie.insert(word: "apple") 16 | trie.contains(word: "apple") -------------------------------------------------------------------------------- /Trie/Trie.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | -------------------------------------------------------------------------------- /Trie/Trie/Trie.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Trie/Trie/Trie.xcodeproj/xcshareddata/xcbaselines/EB798E0A1DFEF79900F0628D.xcbaseline/6ABF2F62-9363-4450-8DE1-D20F57026950.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | classNames 6 | 7 | TrieTests 8 | 9 | testInsertPerformance() 10 | 11 | com.apple.XCTPerformanceMetric_WallClockTime 12 | 13 | baselineAverage 14 | 3.407 15 | baselineIntegrationDisplayName 16 | Local Baseline 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Trie/Trie/Trie/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // Trie 4 | // 5 | // Created by Rick Zaccone on 2016-12-12. 6 | // Copyright © 2016 Rick Zaccone. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | @NSApplicationMain 12 | class AppDelegate: NSObject, NSApplicationDelegate { 13 | 14 | 15 | 16 | func applicationDidFinishLaunching(_ aNotification: Notification) { 17 | // Insert code here to initialize your application 18 | } 19 | 20 | func applicationWillTerminate(_ aNotification: Notification) { 21 | // Insert code here to tear down your application 22 | } 23 | 24 | 25 | } 26 | 27 | -------------------------------------------------------------------------------- /Trie/Trie/Trie/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // Trie 4 | // 5 | // Created by Rick Zaccone on 2016-12-12. 6 | // Copyright © 2016 Rick Zaccone. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | class ViewController: NSViewController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | 16 | // Do any additional setup after loading the view. 17 | } 18 | 19 | override var representedObject: Any? { 20 | didSet { 21 | // Update the view, if already loaded. 22 | } 23 | } 24 | 25 | 26 | } 27 | 28 | -------------------------------------------------------------------------------- /Trie/Trie/TrieTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /Trie/Trie/TrieUITests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /Trie/images/trie.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Trie/images/trie.png -------------------------------------------------------------------------------- /Two-Sum Problem/Solution 1/2Sum.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | //: Playground - noun: a place where people can play 2 | 3 | func twoSumProblem(_ a: [Int], k: Int) -> ((Int, Int))? { 4 | var map = [Int: Int]() 5 | 6 | for i in 0 ..< a.count { 7 | if let newK = map[a[i]] { 8 | return (newK, i) 9 | } else { 10 | map[k - a[i]] = i 11 | } 12 | } 13 | return nil 14 | } 15 | 16 | let a = [7, 100, 2, 21, 12, 10, 22, 14, 3, 4, 8, 4, 9] 17 | if let (i, j) = twoSumProblem(a, k: 33) { 18 | i // 3 19 | a[i] // 21 20 | j // 4 21 | a[j] // 12 22 | a[i] + a[j] // 33 23 | } 24 | 25 | twoSumProblem(a, k: 37) // nil 26 | -------------------------------------------------------------------------------- /Two-Sum Problem/Solution 1/2Sum.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Two-Sum Problem/Solution 1/2Sum.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Two-Sum Problem/Solution 2/2Sum.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | //: Playground - noun: a place where people can play 2 | 3 | func twoSumProblem(_ a: [Int], k: Int) -> ((Int, Int))? { 4 | var i = 0 5 | var j = a.count - 1 6 | 7 | while i < j { 8 | let sum = a[i] + a[j] 9 | if sum == k { 10 | return (i, j) 11 | } else if sum < k { 12 | i += 1 13 | } else { 14 | j -= 1 15 | } 16 | } 17 | return nil 18 | } 19 | 20 | let a = [2, 3, 4, 4, 7, 8, 9, 10, 12, 14, 21, 22, 100] 21 | if let (i, j) = twoSumProblem(a, k: 33) { 22 | i // 8 23 | a[i] // 12 24 | j // 10 25 | a[j] // 21 26 | a[i] + a[j] // 33 27 | } 28 | 29 | twoSumProblem(a, k: 37) // nil 30 | -------------------------------------------------------------------------------- /Two-Sum Problem/Solution 2/2Sum.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Two-Sum Problem/Solution 2/2Sum.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Two-Sum Problem/Solution 2/2Sum.playground/timeline.xctimeline: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Union-Find/Images/AfterFind.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Union-Find/Images/AfterFind.png -------------------------------------------------------------------------------- /Union-Find/Images/AfterUnion.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Union-Find/Images/AfterUnion.png -------------------------------------------------------------------------------- /Union-Find/Images/BeforeFind.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Union-Find/Images/BeforeFind.png -------------------------------------------------------------------------------- /Union-Find/Images/BeforeUnion.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vulcanshen/swift-algorithm-club-zhTW/1f39ae336f9814795b7689ac4cf7799226dbc516/Union-Find/Images/BeforeUnion.png -------------------------------------------------------------------------------- /Union-Find/UnionFind.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Union-Find/UnionFind.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Union-Find/UnionFind.playground/timeline.xctimeline: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Z-Algorithm/ZetaAlgorithm.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Z-Algorithm/ZetaAlgorithm.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /install_swiftlint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Installs the SwiftLint package. 4 | # Tries to get the precompiled .pkg file from Github, but if that 5 | # fails just recompiles from source. 6 | 7 | set -e 8 | 9 | SWIFTLINT_PKG_PATH="/tmp/SwiftLint.pkg" 10 | SWIFTLINT_PKG_URL="https://github.com/realm/SwiftLint/releases/download/0.10.0/SwiftLint.pkg" 11 | 12 | wget --output-document=$SWIFTLINT_PKG_PATH $SWIFTLINT_PKG_URL 13 | 14 | if [ -f $SWIFTLINT_PKG_PATH ]; then 15 | echo "SwiftLint package exists! Installing it..." 16 | sudo installer -pkg $SWIFTLINT_PKG_PATH -target / 17 | else 18 | echo "SwiftLint package doesn't exist. Compiling from source..." && 19 | git clone https://github.com/realm/SwiftLint.git /tmp/SwiftLint && 20 | cd /tmp/SwiftLint && 21 | git submodule update --init --recursive && 22 | sudo make install 23 | fi 24 | --------------------------------------------------------------------------------