├── 2014 ├── 0-Memory vs Disk access time │ └── MemoryVersusDisk.java ├── 1-array │ ├── Array Examples.pdf │ ├── c │ │ ├── common-elements │ │ │ ├── solution1.c │ │ │ ├── solution2.c │ │ │ ├── solution3.c │ │ │ ├── time measure -clock.c │ │ │ └── time measure-time.c │ │ └── find non-repeated │ │ │ ├── solution1.c │ │ │ ├── solution2.c │ │ │ ├── solution3.c │ │ │ └── solution4.c │ └── java │ │ ├── BinarySearch.java │ │ ├── FindAtleastOneDup.java │ │ ├── FindNonrepeatedNum.java │ │ └── RowColumnSorted.java ├── 2-list │ ├── c++ │ │ └── implementations │ │ │ ├── doublyinkedlist.cpp │ │ │ ├── myvector.cpp │ │ │ └── sinlglylinkedlist.cpp │ └── java │ │ ├── List.java │ │ ├── implementations │ │ └── linkedlist │ │ │ ├── SLLApp.java │ │ │ └── SinglyLinkedList.java │ │ └── problems-solutions │ │ ├── DetectLoop.java │ │ ├── FindFirstCommonNode.java │ │ ├── FindFirstCommonNode1.java │ │ ├── KthNodeFromEnd.java │ │ ├── LinkedListNode.java │ │ ├── LinkedListReversal.java │ │ ├── MiddleNode.java │ │ └── RecursiveReverse.java ├── 3-set │ └── java │ │ └── implementations │ │ └── treeset │ │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── treeset │ │ ├── MyTreeSet.java │ │ └── TestMyTreeSet.java ├── 4-map │ └── java │ │ └── implementations │ │ ├── hashmap │ │ └── src │ │ │ └── com │ │ │ └── alg │ │ │ └── top20 │ │ │ └── hashmap │ │ │ ├── MyHashMap.java │ │ │ ├── MyLinkedList.java │ │ │ └── TestMyHashMap.java │ │ └── treemap │ │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── treemap │ │ ├── MyTreeMap.java │ │ └── TestMyTreeMap.java ├── assignments │ ├── assignment1 │ │ ├── assignment1.pdf │ │ ├── solutions1-c++ │ │ │ ├── 1.c │ │ │ ├── 2.c │ │ │ ├── 3.c │ │ │ ├── 3_2.c │ │ │ └── 4.c │ │ ├── solutions1-c │ │ │ ├── q1.c │ │ │ ├── q2.c │ │ │ ├── q3.c │ │ │ └── q4.c │ │ └── solutions1-java │ │ │ ├── CountZeros.java │ │ │ ├── CupsAndSaucers.java │ │ │ ├── FindMissing.java │ │ │ └── PrintSpiral.java │ ├── assignment2 │ │ ├── assignment2.pdf │ │ ├── solutions2-c++ │ │ │ ├── 1.cpp │ │ │ ├── 2.cpp │ │ │ ├── 3.c │ │ │ └── 4.cpp │ │ ├── solutions2-c │ │ │ ├── p1.c │ │ │ ├── p2.c │ │ │ ├── p3.c │ │ │ └── p4.c │ │ └── solutions2-java │ │ │ ├── DuplicateList.java │ │ │ ├── MaxSeqeuence.java │ │ │ ├── SortLinkedList.java │ │ │ ├── SortLinkedList1.java │ │ │ └── SplitList.java │ ├── assignment3 │ │ └── Assignment3-hashset, map.pdf │ ├── assignment4 │ │ └── Assignment4-binrarytree.pdf │ └── assignment5 │ │ └── Assignment5-treeset, map.pdf └── c++ tutorial │ ├── list │ ├── STLlist1.cpp │ ├── STLlist2.cpp │ └── STLlist3.cpp │ ├── map-multimap │ ├── STLmap1.cpp │ ├── STLmap2.cpp │ ├── STLmap3.cpp │ ├── STLmap4.cpp │ ├── STLmaptmp.cpp │ ├── STLmulitmap.cpp │ └── STLpair.cpp │ ├── priorityqueue │ └── STLpriorityqueue.cpp │ ├── queue │ └── STLqueue.cpp │ ├── set-multiset │ ├── STLmultiset.cpp │ ├── STLset1.cpp │ ├── STLset2.cpp │ └── STLset3.cpp │ ├── stack │ └── STLstack.cpp │ └── vector │ ├── STLvector1.cpp │ ├── STLvector2.cpp │ └── STLvector3.cpp ├── 2015 ├── 1-basic thinking │ ├── BasicThinking-java │ │ ├── .classpath │ │ ├── .project │ │ ├── .settings │ │ │ └── org.eclipse.jdt.core.prefs │ │ └── src │ │ │ └── com │ │ │ └── alg │ │ │ └── basic │ │ │ ├── BinarySearch.java │ │ │ ├── FindNonRepeatednumber.java │ │ │ └── RowColumnSorted.java │ └── In-Class Problems.pdf ├── 2-recursive thinking │ └── RecursiveThinking-java │ │ ├── .classpath │ │ ├── .project │ │ ├── .settings │ │ └── org.eclipse.jdt.core.prefs │ │ └── src │ │ └── com │ │ └── alg │ │ └── rec │ │ ├── BinarySequence.java │ │ ├── Honai.java │ │ └── Power.java ├── 4-list data structure design(oo style) │ ├── List.java │ └── SinglyLinkedList.java ├── 5-linked list problems │ ├── DetectLoop.java │ ├── FindFirstCommonNode.java │ ├── FindFirstCommonNode1.java │ ├── LinkedListNode.java │ ├── LinkedListReversal.java │ └── MiddleNode.java ├── 6-map data structure design(oo style) │ ├── hashmap │ │ ├── .classpath │ │ ├── .project │ │ ├── bin │ │ │ └── com │ │ │ │ └── alg │ │ │ │ └── top20 │ │ │ │ └── hashmap │ │ │ │ ├── MyHashMap.class │ │ │ │ ├── MyLinkedList$Node.class │ │ │ │ ├── MyLinkedList.class │ │ │ │ └── TestMyHashMap.class │ │ └── src │ │ │ └── com │ │ │ └── alg │ │ │ └── top20 │ │ │ └── hashmap │ │ │ ├── MyHashMap.java │ │ │ ├── MyLinkedList.java │ │ │ └── TestMyHashMap.java │ └── treemap │ │ ├── .classpath │ │ ├── .project │ │ ├── .settings │ │ └── org.eclipse.jdt.core.prefs │ │ ├── bin │ │ └── com │ │ │ └── alg │ │ │ └── top20 │ │ │ └── treemap │ │ │ ├── MyTreeMap$Node.class │ │ │ ├── MyTreeMap.class │ │ │ └── TestMyTreeMap.class │ │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── treemap │ │ ├── MyTreeMap.java │ │ └── TestMyTreeMap.java └── assignments │ ├── Assignment1-basic thinking.pdf │ ├── Assignment10-dp thinking.pdf │ ├── Assignment11-stack-queue problems.pdf │ ├── Assignment12-trie and bloofilters.pdf │ ├── Assignment13-backtracking thinking.pdf │ ├── Assignment2-basic thinking.pdf │ ├── Assignment3-recursive thinking.pdf │ ├── Assignment4-linked list problems.pdf │ ├── Assignment5-tree problems.pdf │ ├── Assignment6-tree problems.pdf │ ├── Assignment7-set, map.pdf │ ├── Assignment8-greedy thinking.pdf │ ├── Assignment9-dp thinking.pdf │ └── dictionary.txt ├── 2016-jan ├── BitSet │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── bitset │ │ ├── BitSet.java │ │ ├── RemoveCharacters.java │ │ └── TestBitSet.java ├── Graph │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── graphs │ │ ├── AdjMatrixGraph.java │ │ ├── IGraph.java │ │ └── TestGraph.java ├── MultiThreading │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── mt │ │ ├── SharedData.java │ │ ├── Sorting.java │ │ ├── ThreadTest1.java │ │ └── ThreadTest2.java ├── Tries │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ ├── kwaytrie │ │ └── KWayTrie.java │ │ └── tst │ │ ├── TernarySearchTree.java │ │ ├── TestTrie.java │ │ └── Trie.java ├── assignments │ ├── Assignment1-basic thinking.pdf │ ├── Assignment10-dp thinking.pdf │ ├── Assignment11-backtracking thinking.pdf │ ├── Assignment2-basic thinking.pdf │ ├── Assignment3-recursive thinking.pdf │ ├── Assignment4-linked list problems.pdf │ ├── Assignment5-tree problems.pdf │ ├── Assignment6-tree problems.pdf │ ├── Assignment7-set, map.pdf │ ├── Assignment8-greedy thinking.pdf │ ├── Assignment9-dp thinking.pdf │ └── dictionary.txt ├── backtracking │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── bt │ │ ├── DisplayBS.java │ │ ├── Nqueens.java │ │ ├── Permutations.java │ │ └── SudokuSolver.java ├── basic-thinking │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── basic │ │ ├── FindCommon.java │ │ └── GridSearch.java ├── bloom-filter │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── bloomfilter │ │ ├── BloomFilter.java │ │ └── TestBloomFilter.java ├── dp-thinking │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── dp │ │ ├── Fib.java │ │ ├── GridOptimization.java │ │ └── MaxContgSum.java ├── file-problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── file │ │ ├── FindKthLinefromEnd.java │ │ └── RandAccessFile.java ├── greedy-thinking │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── greedy │ │ ├── FileMerging.java │ │ ├── FractionalKnapsack.java │ │ └── HuffmanCode.java ├── oothinking │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── list │ │ ├── ArrayList.java │ │ ├── LinkedList.java │ │ └── List.java ├── prqueue │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── pqueue │ │ ├── HeapPrqueue.java │ │ ├── IPriorityQueue.java │ │ └── TestPriorityQueue.java ├── randomgenerator │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── random │ │ ├── RandomTest.java │ │ └── Simulation.java ├── recursive-thinking │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── recursion │ │ ├── Honai.java │ │ └── Power.java ├── sorting │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── sorting │ │ └── Sorting.java └── trees │ └── src │ └── com │ └── alg │ └── top20 │ └── trees │ ├── AVLTree.java │ ├── BinarySearchTree.java │ └── BinaryTree.java ├── 2016-may ├── FileProblems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── file │ │ ├── FileReadWrite.java │ │ ├── FileSearch.java │ │ ├── FileSorting.java │ │ ├── NthLineFromEnd.java │ │ ├── PerformanceTest.java │ │ ├── RandomAccessFileTest.java │ │ └── UrlFilter.java ├── MultiThreads │ └── src │ │ ├── ParallelSort.java │ │ ├── Sorting.java │ │ └── SubSortThread.java ├── ProcessImage │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── memory │ │ └── MemorySegments.java ├── assignments │ ├── Assignment1-basic thinking.pdf │ ├── Assignment2-basic thinking.pdf │ ├── Assignment3-linked list problems.pdf │ ├── Assignment4-set, map.pdf │ ├── Assignment5-recursive thinking.pdf │ ├── Assignment6-tree problems.pdf │ └── Assignment7-bst problems.pdf ├── backtracking │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── bt │ │ ├── DisplayAllSeq.java │ │ ├── DisplayBinarySeq.java │ │ ├── DisplayPermutations.java │ │ ├── Nqueens.java │ │ └── SudokuSolver.java ├── balanced-bst │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── balbst │ │ ├── TestBBST.java │ │ └── TreeNode.java ├── basic-thinking │ └── src │ │ ├── CommonElements.java │ │ ├── GridSearch.java │ │ └── RandomGenerator.java ├── binary-tree-problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── trees │ │ ├── RecNonRecTranf.java │ │ ├── TestBinaryTree.java │ │ ├── TreeNode.java │ │ ├── TreeSearch.java │ │ └── TreeSize.java ├── bloom-filter │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── bitset │ │ ├── BitSet.java │ │ └── BloomFilter.java ├── bst-problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── bst │ │ ├── ISBST.java │ │ ├── SelectK.java │ │ ├── TestBST.java │ │ └── TreeNode.java ├── dynamic-programming │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── dp │ │ ├── Fibonacci.java │ │ └── FindMaxItemsInGrid.java ├── graph-problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── graph │ │ ├── Igraph.java │ │ ├── TestGraph.java │ │ └── UndirectedGraph.java ├── greedy-thinking │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── greedy │ │ └── FileMerge.java ├── linked-list-problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── linkedlist │ │ ├── FindMiddle.java │ │ ├── ListNode.java │ │ ├── LoopDetection.java │ │ ├── LoopRemoval.java │ │ └── RandomNode.java ├── oothinking │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ ├── cache │ │ ├── ICache.java │ │ ├── LinkedMapCache.java │ │ └── TestCache.java │ │ ├── genericlist │ │ ├── ArrayList.java │ │ ├── IList.java │ │ ├── LinkedList.java │ │ └── TestList.java │ │ ├── list │ │ ├── ArrayList.java │ │ ├── IList.java │ │ ├── LinkedList.java │ │ └── TestList.java │ │ ├── map │ │ ├── HashMap.java │ │ ├── IMap.java │ │ ├── ISortedMap.java │ │ └── TestMap.java │ │ ├── pqueue │ │ ├── HeapPQueue.java │ │ ├── IPQueue.java │ │ └── TestPrQueue.java │ │ └── set │ │ ├── HashSet.java │ │ ├── ISet.java │ │ ├── ISortedSet.java │ │ └── TestSet.java ├── recursive-thinking │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── recursion │ │ ├── Power.java │ │ └── TowersOfHonai.java ├── sorting │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── sorting │ │ └── Sorting.java ├── stringproblems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── strings │ │ ├── EditDistance.java │ │ ├── LCS.java │ │ └── LongestRepSubString.java └── trie │ └── src │ └── com │ └── alg │ └── top20 │ └── trie │ ├── ITrie.java │ ├── KwayTrie.java │ ├── TernarySearchTree.java │ └── TestTrie.java ├── 2016-september ├── 1.basic-thinking │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── basic │ │ ├── Finduplicate.java │ │ └── Intersection.java ├── 10.sorted-table │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── sortedtable │ │ ├── DLinkedList.java │ │ ├── DListNode.java │ │ ├── Driver.java │ │ ├── Employee.java │ │ ├── ISortedTable.java │ │ └── SortedTable.java ├── 11.trie │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── trie │ │ ├── Driver.java │ │ ├── ITrie.java │ │ ├── RWayTrie.java │ │ └── TernarySearchTree.java ├── 12.dynamic-programming │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── dp │ │ ├── editdistance │ │ └── EditDistance.java │ │ ├── fib │ │ └── NthFibonacci.java │ │ ├── maxcoins │ │ └── FindMaxCoins.java │ │ └── receq │ │ └── RecEquation.java ├── 13.greedy-thinking │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── greedy │ │ └── FileMerging.java ├── 14.backtracking │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── bt │ │ ├── AllSequences.java │ │ ├── NQueens.java │ │ ├── Permutations.java │ │ ├── SudokuSolver.java │ │ └── TernarySequence.java ├── 15.queue │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ ├── pqueue │ │ ├── Driver.java │ │ ├── HeapPQueue.java │ │ └── IPQueue.java │ │ └── queue │ │ ├── Driver.java │ │ ├── IQueue.java │ │ └── LinkedQueue.java ├── 16.sorting │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── sorting │ │ ├── Driver.java │ │ └── Sorting.java ├── 17.file-problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── file │ │ ├── BloomFilter.java │ │ ├── BoundedBuffer.java │ │ ├── FileSearch.java │ │ ├── FileSorting.java │ │ ├── IFilter.java │ │ ├── NthLineFromEnd.java │ │ ├── RandomAccessFileTest.java │ │ └── UrlFiltering.java ├── 18.string-problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── strings │ │ └── LongRepSubString.java ├── 19.multcore-programming │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── mc │ │ └── sorting │ │ ├── Driver.java │ │ ├── ParallelDriver.java │ │ ├── SortThread.java │ │ ├── Sorting.java │ │ ├── ThreadDemo1.java │ │ ├── ThreadDemo2.java │ │ └── ThreadResourceSharing.java ├── 2.oop │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── oop │ │ ├── encapsulation │ │ ├── ArrayList.java │ │ └── ListDriver.java │ │ ├── extensibility │ │ ├── ArrayList.java │ │ ├── IList.java │ │ ├── LinkedList.java │ │ └── ListDriver.java │ │ └── reuse │ │ ├── AbstractList.java │ │ ├── ArrayList.java │ │ ├── IList.java │ │ ├── LinkedList.java │ │ └── ListDriver.java ├── 20.bitwise-problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── bits │ │ ├── BitwiseOperators.java │ │ ├── CountOnes.java │ │ ├── ExtractHostFromIP.java │ │ ├── IsEvenOdd.java │ │ └── Powerof2.java ├── 21.graph-problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── graphs │ │ ├── Driver.java │ │ ├── IUnweightedGraph.java │ │ └── SequentialUnweightedGraph.java ├── 3.list │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── list │ │ ├── AbstractList.java │ │ ├── ArrayList.java │ │ ├── IList.java │ │ ├── LinkedList.java │ │ └── ListDriver.java ├── 4.linkedlist-problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── ll │ │ ├── FindFirstCommonNode.java │ │ ├── ListNode.java │ │ ├── ListRandomNode.java │ │ ├── LoopDetection.java │ │ ├── LoopRemoval.java │ │ ├── MyRandom.java │ │ └── RandomTest.java ├── 5.set │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── set │ │ ├── BSTNode.java │ │ ├── Driver.java │ │ ├── HashSet.java │ │ ├── ISet.java │ │ ├── ISortedSet.java │ │ ├── ListNode.java │ │ └── TreeSet.java ├── 6.map │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── map │ │ ├── Driver.java │ │ ├── HashMap.java │ │ ├── IMap.java │ │ └── ListNode.java ├── 7.cache │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── cache │ │ ├── DLinkedList.java │ │ ├── DListNode.java │ │ ├── Driver.java │ │ ├── ICache.java │ │ └── LinkedHashCache.java ├── 8.recursive-thinking │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── recursion │ │ ├── Honai.java │ │ └── Power.java ├── 9.tree-problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── trees │ │ ├── depth │ │ ├── Driver.java │ │ └── TreeDepth.java │ │ ├── max │ │ └── TreeMax.java │ │ ├── maxPath │ │ ├── Driver.java │ │ └── MaxPathSum.java │ │ └── size │ │ ├── Driver.java │ │ ├── TreeNode.java │ │ └── TreeSize.java └── assignments │ ├── Assignment1-basic thinking.pdf │ ├── Assignment10-greedy thinking.pdf │ ├── Assignment11-dp thinking.pdf │ ├── Assignment12-dp thinking.pdf │ ├── Assignment13-backtracking thinking.pdf │ ├── Assignment2-basic thinking.pdf │ ├── Assignment3-linked list problems.pdf │ ├── Assignment4-set, map.pdf │ ├── Assignment5-recursive thinking.pdf │ ├── Assignment6-tree problems.pdf │ ├── Assignment7-bst problems.pdf │ ├── Assignment8-trie and bloofilters.pdf │ ├── Assignment9-stack-queue problems.pdf │ └── dictionary.txt ├── 2017-january ├── 1.basic-thinking │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── basic │ │ ├── FindCommonElements.java │ │ └── RemoveDuplicates.java ├── 10.tree-problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── trees │ │ ├── BTreeNode.java │ │ ├── MaxPathSum.java │ │ ├── RBinaryTree.java │ │ ├── RecToNonRecConversion.java │ │ └── TreeDepth.java ├── 11.sorted-table │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── sortedtable │ │ ├── Dummy.java │ │ ├── ISortedTable.java │ │ ├── MapTable.java │ │ ├── TestSortedTable.java │ │ └── TravelsInfo.java ├── 12.greedy │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ ├── MinCostMerging.java │ │ └── TestMultiSet.java ├── 13.backtracking │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── backtracking │ │ ├── Nqueens.java │ │ ├── PermutationSequence.java │ │ └── SudokuSolver.java ├── 14.file-problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── file │ │ ├── CircularBuffer.java │ │ ├── FileSearch.java │ │ ├── NthLineFromEnd.java │ │ └── TestFileAccess.java ├── 15.priority-queue │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── pqueue │ │ ├── HeapTreePQ.java │ │ ├── IPQueue.java │ │ └── TestPQ.java ├── 16.sorting │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── sorting │ │ └── Sorting.java ├── 17.radixtree │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── autocmpletion │ │ ├── GeneralRadixTree.java │ │ ├── ITrie.java │ │ ├── TernarySearchTree.java │ │ └── Test.java ├── 18.string-problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── strings │ │ ├── EditDistance.java │ │ ├── Exploration.java │ │ └── LongestRepSubString.java ├── 19.graph-problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── graph │ │ ├── Test.java │ │ └── UndirectedGraph.java ├── 2.oo-thinking │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── oop │ │ ├── ClassvsObject.java │ │ ├── Encapsulation.java │ │ └── Encapsulation2.java ├── 20.bitwise-problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── bitwise │ │ ├── BitwiseOperators.java │ │ ├── CountOnes.java │ │ ├── IPAdress.java │ │ ├── ModuloDivision.java │ │ ├── NextHighestMultiple.java │ │ ├── PowerOf2.java │ │ └── Utils.java ├── 21.parallelism │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── parallelism │ │ └── mt │ │ ├── sorting │ │ └── ParallelSorter.java │ │ └── threads │ │ └── ThreadDemo.java ├── 3.list │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── list │ │ ├── ArrayList.java │ │ ├── IList.java │ │ ├── LinkedList.java │ │ └── TestList.java ├── 4.linked-list problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── linkedlist │ │ ├── FindKthfromEnd.java │ │ ├── ListNode.java │ │ ├── LoopDetection.java │ │ ├── RandomNode.java │ │ └── TestLinkedList.java ├── 5.simulation │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── random │ │ └── RandomGenerator.java ├── 6.cache │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── cache │ │ ├── DListNode.java │ │ ├── DoublyLinkedList.java │ │ ├── ICache.java │ │ ├── LinkedHashMapCache.java │ │ └── TestCache.java ├── 7.set │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── set │ │ ├── BTreeNode.java │ │ ├── HashSet.java │ │ ├── ISet.java │ │ ├── ISortedSet.java │ │ ├── ListNode.java │ │ ├── TestSet.java │ │ └── TreeSet.java ├── 8.recursive-thinking │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── recursion │ │ ├── Honai.java │ │ └── Power.java ├── 9.dynamic-programming │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── dp │ │ ├── CountSteps.java │ │ ├── MaxCoinsFromGrid.java │ │ └── NthFibonacci.java └── assignments │ ├── Assignment1-basic thinking.pdf │ ├── Assignment10-greedy thinking.pdf │ ├── Assignment11-backtracking thinking.pdf │ ├── Assignment2-basic thinking.pdf │ ├── Assignment3-linked list problems.pdf │ ├── Assignment4-set, map.pdf │ ├── Assignment5-recursive thinking.pdf │ ├── Assignment6-tree problems.pdf │ ├── Assignment7-bst problems.pdf │ ├── Assignment8-dp thinking.pdf │ ├── Assignment9-dp thinking.pdf │ └── dictionary.txt ├── 2017-may ├── 1.basic-thinking │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── basic │ │ ├── New Text Document.txt │ │ ├── removeduplicates │ │ ├── RemoveDuplicates.java │ │ └── RemoveDuplicates1.java │ │ └── twosum │ │ ├── TwoSum.java │ │ └── TwoSum1.java ├── 10.tree-problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── trees │ │ ├── BinaryTreeUtils.java │ │ ├── ExploreAllPaths.java │ │ ├── LongestLeaftToLeafPath.java │ │ ├── LongestRootLeafPath.java │ │ ├── LongestRootLeafPathSum.java │ │ ├── MyInteger.java │ │ ├── RecToNonRecur.java │ │ ├── SerializeDeserializeBT1.java │ │ └── TreeNode.java ├── 11.backtracking │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── bt │ │ ├── Combinations.java │ │ ├── DisplayAllBinary.java │ │ ├── DisplayAllSeq.java │ │ ├── DisplayNarySeq.java │ │ └── Permutations.java ├── 12.trie │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── trie │ │ ├── ITrieSet.java │ │ ├── MyBoolean.java │ │ ├── RwayTrieSet.java │ │ └── TSTTrie.java ├── 13.range-query-problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── rangequery │ │ ├── RangeSum1.java │ │ └── RangeSum2.java ├── 14.selection │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── selection │ │ ├── KthSmallest.java │ │ └── Shuffle.java ├── 15.greedy-thinking │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── greedy │ │ ├── MinCostBinaryMerging.java │ │ └── MinResourcesForActivities.java ├── 16.file-problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── file │ │ ├── CircularBuffer.java │ │ └── NthLineFromEnd.java ├── 17.disjoint-set │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── dset │ │ ├── IDisjointSet.java │ │ ├── TestDisjointSet.java │ │ └── WeightedUnionCompressionSet.java ├── 18.graph-problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── graphs │ │ ├── BiColorable.java │ │ ├── CycleCheck.java │ │ ├── ExploreAllPaths.java │ │ ├── FriendCircles.java │ │ ├── GraphUtils.java │ │ ├── HamiltonianPath.java │ │ └── SimplePath.java ├── 19.tournament-tree │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── tt │ │ └── SecondSmallest.java ├── 2.programming-styles │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ ├── oostyle │ │ ├── ArrayList.java │ │ ├── Driver.java │ │ └── LinkedList.java │ │ ├── oostyle1 │ │ ├── ArrayList.java │ │ ├── Driver.java │ │ └── LinkedList.java │ │ ├── oostyle2 │ │ ├── ArrayList.java │ │ ├── Driver.java │ │ └── LinkedList.java │ │ ├── oostyle3 │ │ ├── ArrayList.java │ │ ├── Driver.java │ │ ├── LinkedList.java │ │ └── List.java │ │ ├── oostyle4 │ │ ├── ArrayList.java │ │ ├── Driver.java │ │ ├── LinkedList.java │ │ └── List.java │ │ └── procedural │ │ ├── ArrayList.java │ │ ├── Driver.java │ │ └── LinkedList.java ├── 3.list-oostyle │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── list │ │ ├── ArrayList.java │ │ ├── Driver.java │ │ ├── LinkedList.java │ │ └── List.java ├── 4.linkedlist-problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── linkedlist │ │ ├── LCA.java │ │ ├── LinkedListUtils.java │ │ ├── ListNode.java │ │ ├── LoopDetection.java │ │ ├── RandomNode.java │ │ ├── ReverseList.java │ │ └── TestLoop.java ├── 5.set-oostyle │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── set │ │ ├── HashSet.java │ │ ├── ISet.java │ │ └── TestSet.java ├── 6.cache-oostyle │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── cache │ │ ├── DoublyLinkedList.java │ │ ├── ICache.java │ │ ├── LinkedHashCache.java │ │ └── TestCache.java ├── 7.recursive-thinking │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── recursion │ │ ├── Power.java │ │ └── TowersOfHonai.java ├── 8.dynamic-programming │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── dp │ │ ├── ClimbNSteps.java │ │ ├── DistinctPathsInGrid.java │ │ ├── MaxPathSumInGrid.java │ │ ├── MaxSumNoConsecutive.java │ │ ├── MyInteger.java │ │ └── NthFibonacci.java ├── 9.random-generator │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── random │ │ ├── Random1.java │ │ └── Random2.java ├── assignments │ ├── Assignment1-basic thinking.pdf │ ├── Assignment2-basic thinking.pdf │ ├── Assignment3-linked list problems.pdf │ ├── Assignment4-set, map.pdf │ └── dictionary.txt └── c++ tutorial │ ├── list │ ├── STLlist1.cpp │ ├── STLlist2.cpp │ └── STLlist3.cpp │ ├── map-multimap │ ├── STLmap1.cpp │ ├── STLmap2.cpp │ ├── STLmap3.cpp │ ├── STLmap4.cpp │ ├── STLmaptmp.cpp │ ├── STLmulitmap.cpp │ └── STLpair.cpp │ ├── priorityqueue │ └── STLpriorityqueue.cpp │ ├── queue │ └── STLqueue.cpp │ ├── set-multiset │ ├── STLmultiset.cpp │ ├── STLset1.cpp │ ├── STLset2.cpp │ └── STLset3.cpp │ ├── stack │ └── STLstack.cpp │ └── vector │ ├── STLvector1.cpp │ ├── STLvector2.cpp │ └── STLvector3.cpp ├── 2017-september ├── 0.basic problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── basic │ │ ├── duplicate │ │ └── DuplicateNumber.java │ │ ├── maxvolume │ │ └── MaxVolume.java │ │ ├── mindiff │ │ └── MinDifference.java │ │ └── twosum │ │ └── TwoSum.java ├── 1.binary search problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── basic │ │ └── binarysearch │ │ ├── BinarySearch.java │ │ ├── GridSearch.java │ │ └── Successor.java ├── 10.combinatorial problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── combinatorial │ │ ├── AllPartitions.java │ │ ├── AllSequences.java │ │ ├── AllSubSequences.java │ │ ├── ExprEval.java │ │ ├── ExprEval1.java │ │ ├── MyInteger.java │ │ └── TernarySequences.java ├── 11.backtracking │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── bt │ │ ├── nqueens │ │ └── Nqueens.java │ │ ├── permutations │ │ └── Permutations.java │ │ └── sudoku │ │ └── SudokuSolver.java ├── 12.string problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ ├── editdistance │ │ └── EditDistance.java │ │ ├── lcs │ │ └── LCS.java │ │ ├── palpartition │ │ └── AllPalindromicPartitions.java │ │ ├── palsubseq │ │ └── LongPalSubSeq.java │ │ ├── palsubstr │ │ └── LongPalSubString.java │ │ └── repsubstr │ │ └── LongestRepeatedSubstr.java ├── 13.sorting │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── sorting │ │ └── Sorting.java ├── 14.selection │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── selection │ │ └── Selection.java ├── 15.bitwise tricks │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── bittricks │ │ ├── AllSubsets.java │ │ ├── BitWiseUtilities.java │ │ ├── CountOnes.java │ │ ├── EvenOddCheck.java │ │ ├── HigherLowerMultiples.java │ │ ├── IPAddress.java │ │ ├── IsPowerOf2.java │ │ └── Operators.java ├── 2.datastructure design1 │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ ├── heap │ │ ├── MaxHeap.java │ │ └── MinHeap.java │ │ └── set │ │ ├── HashSet.java │ │ ├── ISet.java │ │ └── TestSet.java ├── 3.datastructure design2 │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── dsdesign │ │ ├── cache │ │ ├── DListNode.java │ │ ├── DoublyLinkedList.java │ │ ├── ICache.java │ │ ├── LinkedHashCache.java │ │ └── TestCache.java │ │ ├── queue │ │ ├── Queue.java │ │ └── TestQueue.java │ │ ├── superqueue │ │ ├── SuperQueue.java │ │ └── TestSuperQueue.java │ │ └── superstack │ │ ├── SuperStack.java │ │ └── TestSuperStack.java ├── 4.linked list problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── ll │ │ ├── LinkedListUtils.java │ │ ├── ListNode.java │ │ ├── detectcycle │ │ ├── DetectCycle.java │ │ └── ListNode.java │ │ ├── kthnodefromend │ │ ├── KthNodeEnd.java │ │ └── ListNode.java │ │ ├── lca │ │ ├── LCA.java │ │ └── ListNode.java │ │ ├── loopnode │ │ ├── ListNode.java │ │ └── LoopNode.java │ │ ├── random │ │ ├── ListNode.java │ │ └── RandomNode.java │ │ └── reversal │ │ ├── ListNode.java │ │ └── ReverseList.java ├── 5.binary tree problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── trees │ │ ├── BinaryTreeUtils.java │ │ ├── MyInteger.java │ │ ├── TreeNode.java │ │ ├── depth │ │ └── LongestRootToLeafPath.java │ │ ├── diameter │ │ └── TreeDiameter.java │ │ ├── explore │ │ └── ExplorePaths.java │ │ ├── serde │ │ └── SerDe.java │ │ └── treesize │ │ └── TreeSize.java ├── 6.bst problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── bst │ │ ├── BSTUtils.java │ │ ├── MyInteger.java │ │ ├── TreeNode.java │ │ ├── balancecheck │ │ └── IsBalancedBST.java │ │ ├── bstmin │ │ └── BSTMin.java │ │ ├── kthsmallest │ │ └── KthSmallest.java │ │ └── serde │ │ └── SerDe.java ├── 7.datastructure design3 │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── trie │ │ ├── ITrie.java │ │ ├── RwayTrie.java │ │ ├── TST.java │ │ └── TestTrie.java ├── 8.dynamic programming │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── dp │ │ ├── MaximumSum.java │ │ ├── NthFibonacci.java │ │ ├── oned │ │ ├── MaximumSum.java │ │ └── NthFibonacci.java │ │ └── twod │ │ ├── GridPaths.java │ │ ├── MaxSumInGrid.java │ │ ├── MyInteger.java │ │ └── PathCount.java ├── 9.greedy │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── greedy │ │ ├── activities │ │ └── MinResourcesForActivities.java │ │ └── filemerge │ │ └── MinMergeCost.java └── assignments │ ├── 1.basic problems.pdf │ ├── 10.backtracking.pdf │ ├── 2.basic problems.pdf │ ├── 3.basic problems.pdf │ ├── 4.binary search problems.pdf │ ├── 5.linked list problems.pdf │ ├── 6.datastructure design problems.pdf │ ├── 7.binary tree problems.pdf │ ├── 8.bst problems.pdf │ └── 9.dp problems-1.pdf ├── 2018-feb ├── 1.adhoc-thinking │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── adhoc │ │ ├── FindDuplicate.java │ │ ├── IncreasingTriplet.java │ │ └── TwoSum.java ├── 10-dp thinking(2d) │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── recursion │ │ ├── BinomicalCoeff.java │ │ ├── CountPaths.java │ │ └── MyInteger.java ├── 11.complete search │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── cs │ │ ├── AllPartitions.java │ │ ├── AllSequences.java │ │ ├── AllSubsets.java │ │ └── TernarySequences.java ├── 12.backtracking │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── bt │ │ ├── Nquueens.java │ │ ├── Permutations.java │ │ └── SudokuSolver.java ├── 13.ds-based-thinking2 │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── ds │ │ └── trie │ │ ├── ITrie.java │ │ ├── TSTNode.java │ │ ├── TSTTrie.java │ │ └── TestTrie.java ├── 14.string-problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── string │ │ ├── EditDistance.java │ │ ├── LCS.java │ │ └── LCSubstr.java ├── 15.sorting-selection │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── sorting │ │ ├── Selection.java │ │ └── Sorting.java ├── 2.divide-and-prune │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── divideprune │ │ ├── CountOnes.java │ │ ├── MatrixSearch.java │ │ └── MinInRotatedSortedArray.java ├── 3.ds-based-thinking1 │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── ds │ │ ├── map │ │ ├── GroupAnagrams.java │ │ └── IdenticalArrays.java │ │ ├── set │ │ ├── DuplicateCheck.java │ │ └── HashSet.java │ │ └── stack │ │ ├── Calculator.java │ │ ├── EvaluatePostfix.java │ │ ├── InfixToPostfix.java │ │ ├── SuperStack.java │ │ └── Test.java ├── 4.recursive-thinking │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── recursion │ │ └── Honai.java ├── 5.dp-thinking │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── dp │ │ ├── CountPaths.java │ │ ├── Fibonacci.java │ │ └── MaximumSum.java ├── 6.linked-list problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── ll │ │ ├── DetectLoop.java │ │ ├── FindKthNodeFromEnd.java │ │ ├── FirstNodeOfLoop.java │ │ ├── ListIntersection.java │ │ ├── ListNode.java │ │ ├── RandomNode.java │ │ ├── ReverseList.java │ │ ├── cache │ │ ├── DListNode.java │ │ ├── DoublyLinkedList.java │ │ ├── ICache.java │ │ ├── LinkedHashMapCache.java │ │ └── TestCache.java │ │ └── random │ │ ├── RandomNode1.java │ │ ├── RandomNode2.java │ │ ├── RandomNode3.java │ │ └── TestRandomNode.java ├── 7.binary-tree problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── bt │ │ ├── BinaryTreeUtils.java │ │ ├── ExploreRootToLeafPaths.java │ │ ├── MyInteger.java │ │ ├── TreeDiameter.java │ │ ├── TreeHeight.java │ │ ├── TreeNode.java │ │ ├── TreeSize.java │ │ └── codec │ │ ├── Codec1.java │ │ ├── Codec2.java │ │ └── Codec3.java ├── 8.bst problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── bbst │ │ ├── BSTNode.java │ │ ├── BSTUtils.java │ │ ├── BalanceCheck.java │ │ ├── MyInteger.java │ │ ├── SearchBBST.java │ │ ├── Selection.java │ │ └── TreeNode.java ├── 9.greedy-thinking │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── greedy │ │ ├── MaxProfit.java │ │ └── MinMergeCost.java └── assignments │ ├── 1.adhoc thinking.pdf │ ├── 2.divide and prune thinking.pdf │ ├── 3.complete search and backtracking.pdf │ ├── 4.dp problems.pdf │ ├── 5.string problems.pdf │ ├── 6.trie problems.pdf │ └── 7.binary tree problems.pdf ├── 2018-may ├── 1.adhoc thinking │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── duplicate │ │ └── FindDuplicate.java ├── 10.optimization problems-dp │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── optimization │ │ ├── LIS.java │ │ ├── MaxSubArraySum.java │ │ ├── MaximumNonConsecutiveSum.java │ │ ├── MaximumSum.java │ │ └── MaximumSumInGrid.java ├── 11.sorted ds │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── ds │ │ ├── KEmptySlots.java │ │ ├── MyCalender.java │ │ ├── Selection.java │ │ └── WordsByFrequency.java ├── 12.optimization problems-greedy │ └── src │ │ ├── MaxProfit.java │ │ └── MinCostMerging.java ├── 13.complete search │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── cs │ │ ├── AllPartitions.java │ │ ├── AllPathsInGrid.java │ │ ├── AllSequences.java │ │ ├── AllSubsets.java │ │ ├── Partitions.java │ │ └── TernarySeq.java ├── 14.backtracking │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── bt │ │ ├── Nqueens.java │ │ ├── PalPartitions.java │ │ ├── Permutations.java │ │ └── SudokuSolver.java ├── 15.trie problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── trie │ │ ├── maxor │ │ └── MaxXor.java │ │ └── t9 │ │ ├── approach1 │ │ └── T9Impl1.java │ │ └── approach2 │ │ └── T9Impl2.java ├── 16.string problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── string │ │ ├── EditDistance.java │ │ ├── LongestCommonSubsequence.java │ │ ├── LongestCommonSubstring.java │ │ └── LongestRepSubstr.java ├── 17.sorting │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── sorting │ │ └── Sorting.java ├── 18.bitwise thinking │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── bit │ │ ├── AllSubsets.java │ │ ├── BitUtils.java │ │ ├── BitwiseOperators.java │ │ ├── HigherLowerMultiplesof8.java │ │ ├── ModuloPowerof2.java │ │ ├── PowerOf2.java │ │ └── ReverseBits.java ├── 19.stack-queue-deque │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── stackqueue │ │ ├── Calculator.java │ │ ├── QueueWithStacks1.java │ │ ├── QueueWithStacks2.java │ │ └── StackwithQueues.java ├── 2.divide prune │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── divideprune │ │ ├── CountZeores.java │ │ ├── GridSearch.java │ │ └── MinInRotatedSortedArray.java ├── 3.set map │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── setmap │ │ ├── GroupAnagrams.java │ │ ├── Intersection.java │ │ └── TwoSum.java ├── 4.basic ds │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ ├── map │ │ └── HashMap.java │ │ ├── orderedset │ │ ├── BTreeNode.java │ │ ├── ISortedSet.java │ │ ├── TestSet.java │ │ └── TreeSet.java │ │ ├── pq │ │ └── src │ │ │ └── com │ │ │ └── alg │ │ │ └── top20 │ │ │ └── pqueue │ │ │ ├── HeapTreePQ.java │ │ │ ├── IPQueue.java │ │ │ └── TestPQ.java │ │ ├── set │ │ └── HashSet.java │ │ └── trie │ │ └── TST.java ├── 5.composite ds │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ ├── cache │ │ ├── DListNode.java │ │ ├── DoublyLinkedList.java │ │ ├── LinkedHashCache.java │ │ └── TestCache.java │ │ └── superstack │ │ └── SuperStack.java ├── 6.recursion │ └── src │ │ ├── Honai.java │ │ └── NthFibonacci.java ├── 7.linked list problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── ll │ │ ├── DetectCycle.java │ │ ├── LinkedListUtils.java │ │ ├── ListLCA.java │ │ ├── ListNode.java │ │ ├── RandomNode.java │ │ ├── RandomTest.java │ │ └── ReverseList.java ├── 8.tree problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── bt │ │ ├── BinaryTreeUtils.java │ │ ├── LongestLeafToLeafPath.java │ │ ├── LongestRootToLeafPath.java │ │ ├── MyInteger.java │ │ ├── SerDe.java │ │ ├── TreeNode.java │ │ └── TreeSize.java ├── 9.search tree problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── bbst │ │ ├── BSTNode.java │ │ ├── LCA.java │ │ ├── MyInteger.java │ │ ├── SearchBBST.java │ │ └── Selection.java └── assignments │ ├── 1.adhoc-thinking.pdf │ ├── 10.greedy problems.pdf │ ├── 11.complete search and backtracking.pdf │ ├── 12.trie-problems.pdf │ ├── 13.suffix array and suffix tree problems.pdf │ ├── 14.string-problems.pdf │ ├── 15.stack-queue-deque problems.pdf │ ├── 16.datastructure design problems.pdf │ ├── 17.bitwise problems.pdf │ ├── 18.sorting.pdf │ ├── 2.adhoc-thinking.pdf │ ├── 3.divide and prune thinking.pdf │ ├── 4.set-map.pdf │ ├── 5.linked list problems.pdf │ ├── 6.binary tree problems.pdf │ ├── 7.bst problems.pdf │ ├── 8.optimization-dp.pdf │ └── 9.sorted ds.pdf ├── 2018-october ├── 0-process internals │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── process │ │ └── StackOverflow.java ├── 1.adhoc-thinking │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── adhoc │ │ ├── FindDuplicate.java │ │ └── FindMissing.java ├── 10.optimization-problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── opt │ │ ├── LIS.java │ │ ├── MaxGridSum.java │ │ ├── MaxNonConsecutiveSum.java │ │ ├── MaxSubArraySum.java │ │ └── MyInteger.java ├── 11.sorted datastructures │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── sortedds │ │ ├── KEmptySlots.java │ │ ├── MyCalender.java │ │ ├── Selection.java │ │ └── SortByFrequency.java ├── 12.greedy-pattern │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── greedy │ │ ├── FileMerging.java │ │ ├── FractionalKnapsack.java │ │ └── LIS.java ├── 13.complete-search │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── cs │ │ ├── AllBaseSequences.java │ │ ├── AllCharSequences.java │ │ ├── AllPartitions.java │ │ ├── AllPathsInGrid.java │ │ ├── AllPermutations.java │ │ └── AllSubsets.java ├── 14.backtracking │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── bt │ │ ├── Nqueens.java │ │ └── SudokuSolver.java ├── 15.sorting │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── sorting │ │ └── Sorting.java ├── 16.string-problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── strings │ │ └── LongestRepeatedSubstring.java ├── 2.divide-and-prune │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── divideprune │ │ ├── CountZeroes.java │ │ ├── MatrixSearch.java │ │ └── MinInRotatedSortedArray.java ├── 3.list-stack-queue-deque │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── list │ │ └── EvaluatePostFix.java ├── 4.set-map │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── setmap │ │ ├── GroupAnagrams.java │ │ ├── IdenticalArrays.java │ │ └── TwoSum.java ├── 5.ds-design │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ ├── basic │ │ └── trie │ │ │ ├── ITrie.java │ │ │ ├── RadixMultiWayTree.java │ │ │ ├── RadixTernarySearchTree.java │ │ │ └── TestTrie.java │ │ └── compositeds │ │ ├── Cache.java │ │ ├── HashMap.java │ │ └── SuperStack.java ├── 6.linked-list problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── ll │ │ ├── CycleDetection.java │ │ ├── FirstCommonNode.java │ │ ├── LinkedListUtils.java │ │ ├── ListNode.java │ │ ├── RandomNode.java │ │ └── ReverseList.java ├── 7.binary-tree-problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── bt │ │ ├── BinaryTreeUtils.java │ │ ├── Codec1.java │ │ ├── Codec2.java │ │ ├── Codec3.java │ │ ├── MaxRootLeafPathSum.java │ │ ├── MyInteger.java │ │ ├── TreeNode.java │ │ └── TreeSize.java ├── 8.search-tree problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── bst │ │ ├── BSTUtils.java │ │ ├── IsBST.java │ │ ├── MyInteger.java │ │ ├── SearchBST.java │ │ ├── Selection.java │ │ └── TreeNode.java ├── 9.dynamic-programming │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── dp │ │ └── NthFibonacci.java └── assignments │ ├── 1.adhoc-thinking.pdf │ ├── 10.greedy problems.pdf │ ├── 11.trie-problems.pdf │ ├── 12.suffix array and suffix tree problems.pdf │ ├── 13.string-problems.pdf │ ├── 2.divide and prune thinking.pdf │ ├── 3.stack-queue-deque problems.pdf │ ├── 4.set-map.pdf │ ├── 5.binary tree problems.pdf │ ├── 6.bst problems.pdf │ ├── 7.optimization-dp.pdf │ ├── 8.sorted datastructures.pdf │ └── 9.complete search and backtracking.pdf ├── 2019-jan ├── 1.array based problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── array │ │ ├── CountZeroes.java │ │ ├── FindDuplicate.java │ │ ├── MatrixSearch.java │ │ ├── MinInRotSortedArray.java │ │ └── MissingNumber.java ├── 10.optimization problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── opt │ │ ├── CoinChange.java │ │ ├── EditDistance.java │ │ ├── MaxSumInGrid.java │ │ ├── MaxSumNoConsecutive.java │ │ ├── MinCostMerging.java │ │ └── MyInteger.java ├── 11.sorted datastructures │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── sortedds │ │ ├── KEmptySlots.java │ │ ├── MyCalender.java │ │ ├── Selection.java │ │ └── SortByFrequency.java ├── 12.combinatorial problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── combinatorics │ │ ├── AllCharSequences.java │ │ ├── AllPartitions.java │ │ ├── AllPermutations.java │ │ ├── AllSequencesInBase.java │ │ └── AllSubsets.java ├── 13.puzzle problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── puzzles │ │ ├── Nqueens.java │ │ └── SudokuSolver.java ├── 14.randomness and problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── random │ │ ├── MyRandom.java │ │ ├── RandomGenerator.java │ │ ├── RandomMapper.java │ │ └── Shuffling.java ├── 15.string-problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── string │ │ ├── ITrie.java │ │ ├── LCS.java │ │ ├── LongestRepeatedSubstring.java │ │ ├── MyInteger.java │ │ ├── RadixTree.java │ │ ├── TernarySearchTree.java │ │ └── TestTrie.java ├── 16.sorting │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── sorting │ │ └── Sorting.java ├── 17.bit-wise problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── bit │ │ ├── AllSubsets.java │ │ ├── BitwiseUtils.java │ │ ├── CountOnes.java │ │ ├── HighestLowestMultiples.java │ │ └── ReverseBytes.java ├── 2.list-stack-queue │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── list │ │ ├── BackSpace.java │ │ ├── ExpressionEvaluator.java │ │ └── PostfixEval.java ├── 3.basic ds design │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ ├── map │ │ └── HashMap.java │ │ └── set │ │ └── HashSet.java ├── 4.set-map │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── setmap │ │ ├── AnagramCheck.java │ │ ├── GroupAnagrams.java │ │ └── TwoSum.java ├── 5.linked-list problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── ll │ │ ├── Cache.java │ │ ├── CycleDetection.java │ │ ├── DListNode.java │ │ ├── DoublyLinkedList.java │ │ ├── FindCommonNode.java │ │ ├── LinkedListUtils.java │ │ ├── ListNode.java │ │ ├── RandomNode.java │ │ └── ReverseList.java ├── 6.recursion-thinking │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── recursion │ │ ├── Honai.java │ │ └── Power.java ├── 7.binary tree problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── bt │ │ ├── BTNode.java │ │ ├── BinaryTreeUtils.java │ │ ├── LongestRootLeafPath.java │ │ ├── MyInteger.java │ │ ├── SerDe.java │ │ └── TreeSize.java ├── 8.bst problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── bst │ │ ├── BSTNode.java │ │ ├── BSTUtils.java │ │ ├── MyInteger.java │ │ ├── Search.java │ │ ├── Selection.java │ │ └── SerDe.java ├── 9.dynamic programming │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── dp │ │ └── NthFibonacci.java └── assignments │ ├── 1.adhoc-thinking.pdf │ ├── 2.divide and prune thinking.pdf │ ├── 3.stack-queue-deque problems.pdf │ ├── 4.set-map.pdf │ ├── 5.linked list problems.pdf │ ├── 6.binary tree problems.pdf │ ├── 7.bst problems.pdf │ ├── 8.optimization-dp.pdf │ └── 9.sorted set-sorted map.pdf ├── 2019-may ├── 1.adhoc thinking │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── basic │ │ ├── CountZeroes.java │ │ ├── FindDuplicate.java │ │ └── GridSearch.java ├── 10.string-problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── string │ │ ├── LongestCommonSubseq.java │ │ ├── LongestRepeatedSubstring.java │ │ └── trie │ │ ├── ITrie.java │ │ ├── MultiWayTrie.java │ │ ├── TernarySearchTrie.java │ │ └── TestTrie.java ├── 11.sorting │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── sorting │ │ └── Sorting.java ├── 12.recursion-to-nonrecursion │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── rec │ │ ├── Template1.java │ │ ├── Template2.java │ │ ├── Template3.java │ │ └── Template4.java ├── 13.list-stack-queue problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── list │ │ └── Calculator.java ├── 14.random generators │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── random │ │ ├── Random1.java │ │ ├── Random2.java │ │ └── Random3.java ├── 15.bitwise problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── bit │ │ ├── BitWiseUtils.java │ │ ├── BoundaryAlignment.java │ │ ├── CountOnes.java │ │ ├── IPAddress.java │ │ └── Reverse.java ├── 2.set-map │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── setmap │ │ ├── Anagrams.java │ │ ├── GroupAnagrams.java │ │ └── TwoSum.java ├── 3.linked list problems │ └── linked list problems │ │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── ll │ │ ├── Cache.java │ │ ├── CommonNode.java │ │ ├── CycleDetection.java │ │ ├── DListNode.java │ │ ├── DoublyLinkedList.java │ │ ├── ListNode.java │ │ ├── ListReversal.java │ │ └── RandomNode.java ├── 4.binary tree problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── bt │ │ ├── BTNode.java │ │ ├── BinaryTreeUtils.java │ │ ├── LeftLeafSum.java │ │ ├── LongestRootToLeafPath.java │ │ ├── MyInteger.java │ │ ├── PerLevelSum.java │ │ ├── SerDePreIn.java │ │ ├── SerDeSingleTraversal.java │ │ ├── TreeSearch.java │ │ └── TreeSize.java ├── 5.bst problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── bst │ │ ├── BSTNode.java │ │ ├── BSTSearch.java │ │ ├── BSTUtils.java │ │ ├── Ceil.java │ │ ├── KthSmallest.java │ │ └── MyInteger.java ├── 6.sorted ds │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── sorted │ │ ├── KEmptySlots.java │ │ ├── MyCalender.java │ │ └── Selection.java ├── 7.dynamic programming │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── dp │ │ ├── EditDistance.java │ │ ├── MaxNonConsSum.java │ │ ├── MaxSumGrid.java │ │ ├── MinCoinChange.java │ │ ├── MyInteger.java │ │ └── NthFibonacci.java ├── 8.greedy thinking │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── greedy │ │ └── FileMerging.java ├── 9.combinatorial problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── combinatorics │ │ ├── AllPartitions.java │ │ ├── AllPermutations.java │ │ ├── AllSequences.java │ │ ├── AllSequencesInBase.java │ │ ├── AllSubsets.java │ │ ├── NQueens.java │ │ └── SudokuSolver.java └── assignments │ ├── 1.adhoc-thinking.pdf │ ├── 2.divide and prune thinking.pdf │ ├── 3.set-map.pdf │ ├── 4.linked list problems.pdf │ ├── 5.binary tree problems.pdf │ ├── 7.bst problems.pdf │ └── 8.sorted data structures.pdf ├── 2019-october ├── 0.primitive ds design │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ ├── map │ │ └── HashMap.java │ │ └── set │ │ └── HashSet.java ├── 1.array based problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── array │ │ ├── CountZeros.java │ │ ├── FindDuplicate.java │ │ └── GridSearch.java ├── 10.combinatorial problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── combinatorics │ │ ├── AllPartitions.java │ │ ├── AllPermutations.java │ │ ├── AllSequences.java │ │ ├── AllSubsets.java │ │ └── TernarySequences.java ├── 11.puzzles │ └── src │ │ └── puzzles │ │ ├── Nqueens.java │ │ └── SudokuSolver.java ├── 12.sorting │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── sorting │ │ └── Sorting.java ├── 13.string problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ ├── string │ │ ├── LongCommonSubString.java │ │ ├── LongestCommonSubsequence.java │ │ ├── MyInteger.java │ │ └── trie │ │ │ ├── ITrie.java │ │ │ ├── RadixTrie.java │ │ │ ├── TSTTrie.java │ │ │ └── TestTrie.java │ │ └── trie │ │ ├── ITrie.java │ │ ├── RadixTrie.java │ │ ├── TSTTrie.java │ │ └── TestTrie.java ├── 2.set-map porblems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── setmap │ │ ├── GroupAnagrams.java │ │ ├── LinkedHashCache.java │ │ └── TwoSum.java ├── 3.linked list problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── linkedlist │ │ ├── DetectCycle.java │ │ ├── FindCommonNode.java │ │ ├── LinkedListUtils.java │ │ ├── ListNode.java │ │ ├── RandomNode.java │ │ └── ReverseList.java ├── 4.randomized problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── random │ │ ├── RandomInteger1.java │ │ ├── RandomInteger2.java │ │ ├── RandomInteger3.java │ │ └── RandomInteger4.java ├── 5.recursion pattern │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── recursion │ │ └── Power.java ├── 6.binary tree problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── bt │ │ ├── AvgValuePerLevel.java │ │ ├── BinaryTreeUtils.java │ │ ├── LeftLeafSum.java │ │ ├── MaxRootToLeafPathLength.java │ │ ├── MyInteger.java │ │ ├── SerDe.java │ │ ├── TreeNode.java │ │ ├── TreeSearch.java │ │ └── TreeSize.java ├── 7.bst problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── bst │ │ ├── BSTSearch.java │ │ ├── BSTUtils.java │ │ ├── Floor.java │ │ ├── KthSmaallest.java │ │ ├── MyInteger.java │ │ ├── SerDe.java │ │ └── TreeNode.java ├── 8.sorted ds │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── sortedds │ │ ├── KEmptySlots.java │ │ ├── KthSmallest.java │ │ ├── MyCalender1.java │ │ └── MyCalender2.java ├── 9.dynamic programming │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── dp │ │ ├── MaxNonConsSum.java │ │ ├── MaxNonConsSum1.java │ │ ├── MaxNonConsSum2.java │ │ ├── MaxSumInGrid1.java │ │ ├── MaxSumInGrid2.java │ │ ├── MinCostMerging.java │ │ ├── MyInteger.java │ │ └── NthFibonacci.java └── assignments │ ├── 1.adhoc-thinking.pdf │ ├── 2.divide and prune thinking.pdf │ ├── 3.set-map.pdf │ ├── 4.linked list problems.pdf │ ├── 5.binary tree problems.pdf │ ├── 6.bst problems.pdf │ └── 7.sorted data structures.pdf ├── 2020-jan ├── 1.array based problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── array │ │ ├── Ceil.java │ │ ├── CountZeroes.java │ │ ├── FindDuplicate.java │ │ └── MatrixSearch.java ├── 2.set-map problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── setmap │ │ └── TwoSum.java ├── 3.data structure design │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── dsdesign │ │ └── HashSet.java ├── 4.linkedlist problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── ll │ │ ├── DetectLoop.java │ │ ├── KthNodeFromEnd.java │ │ ├── LinkedListUtils.java │ │ ├── ListNode.java │ │ ├── LoopNode.java │ │ ├── MyRandom.java │ │ ├── RandomInteger0.java │ │ ├── RandomInteger1.java │ │ ├── RandomInteger2.java │ │ ├── RandomInteger3.java │ │ ├── RandomNode.java │ │ └── ReverseList.java ├── 5.binary tree problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── bt │ │ ├── BinaryTreeUtils.java │ │ ├── LeftLeafSum.java │ │ ├── LeftMostAtLastLevel.java │ │ ├── LongRootToLeafPath.java │ │ ├── MyInteger.java │ │ ├── SerDe.java │ │ ├── TreeNode.java │ │ ├── TreeSearch.java │ │ └── TreeSize.java ├── 6.bst problems │ └── src │ │ └── com │ │ └── alg │ │ └── top20 │ │ └── bst │ │ ├── BSTSearch.java │ │ ├── BSTUtils.java │ │ ├── Ceil.java │ │ ├── Floor.java │ │ ├── KthSmaallest.java │ │ ├── MyInteger.java │ │ ├── SerDe.java │ │ └── TreeNode.java └── assignments │ ├── 1.adhoc-thinking.pdf │ ├── 2.divide and prune thinking.pdf │ ├── 3.set-map.pdf │ └── 4.linked list problems.pdf └── README.md /2014/1-array/Array Examples.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2014/1-array/Array Examples.pdf -------------------------------------------------------------------------------- /2014/1-array/c/common-elements/solution1.c: -------------------------------------------------------------------------------- 1 | 2 | void FindCommon(int a[], int b[], int n) 3 | { 4 | int i, j; 5 | for(i=0; i 2 | int cmp(const void* a, const void *b) { return *(int*)a - *(int*)b; } 3 | void sort(int a[], int n) { 4 | qsort(a, n, sizeof(int), cmp); 5 | } 6 | void FindCommon(int a[], int b[], int n) 7 | { 8 | int i, count = 0; 9 | sort(b,n); 10 | for(i=0; i { 9 | 10 | public int addElement(Type data, int pos); 11 | 12 | public int addElement(Type data); 13 | 14 | public boolean removeElement(int pos); 15 | 16 | public void clear(); 17 | } 18 | -------------------------------------------------------------------------------- /2014/2-list/java/problems-solutions/MiddleNode.java: -------------------------------------------------------------------------------- 1 | /*Find the middle node of a linked list 2 | * */ 3 | package com.algorithmica.linkedlists; 4 | import com.algorithmica.linkedlists.LinkedListNode; 5 | public class MiddleNode { 6 | public static void main(String args[]) { 7 | LinkedListNode head = LinkedListNode.createList(); 8 | LinkedListNode.printList(head); 9 | LinkedListNode slow, fast; 10 | slow = fast = head; 11 | while (fast != null && fast.next != null) { 12 | slow = slow.next; 13 | fast = fast.next.next; 14 | 15 | } 16 | System.out.println("Middle is " + slow.data); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /2014/assignments/assignment1/assignment1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2014/assignments/assignment1/assignment1.pdf -------------------------------------------------------------------------------- /2014/assignments/assignment1/solutions1-c++/2.c: -------------------------------------------------------------------------------- 1 | //gievn array containing 0 to n except 1 2 | //fid the missing element 3 | 4 | #include 5 | 6 | int findMissing(int a[], int n) 7 | { 8 | int ans=0,i; 9 | for(i=1;i<=n;i++) 10 | ans^=i; 11 | 12 | for(i=0;i 2 | #include 3 | void main() 4 | { 5 | int a[15]; 6 | int l,r,i,m=0; 7 | printf("enter the elements in a: "); 8 | for(i=0;i<15;i++) 9 | scanf("%d",&a[i]); 10 | if(a[14]==0) 11 | { 12 | printf("\n%d",14); 13 | exit(1); 14 | } 15 | l=0;r=14; 16 | while(a[l]==0 && a[r]>0) 17 | { 18 | m=l+(r-l)/2; 19 | if(a[m]>=0) 20 | r=m-1; 21 | else 22 | l=m+1; 23 | } 24 | if(a[m]==0) 25 | printf("\n%d",m+1); 26 | else 27 | printf("\n%d",m); 28 | } 29 | -------------------------------------------------------------------------------- /2014/assignments/assignment1/solutions1-c/q2.c: -------------------------------------------------------------------------------- 1 | #include 2 | void main() 3 | { 4 | int a[20],i,n,res=0; 5 | printf("enter the value on n:"); 6 | scanf("%d",&n); 7 | for(i=1;i<=n;i++) 8 | res=res^i; 9 | printf("\nenter the elements: "); 10 | for(i=0;i 2 | void main() 3 | { 4 | int t[]={15,20,22,25,30},s[]={10,19,20,23,24,30}; 5 | int p=4,q=5; 6 | while(p>=0 && q>=0) 7 | { 8 | if(t[p]<=s[q]) 9 | { 10 | printf("[%d,%d] ",t[p],s[q]); 11 | p--; 12 | q--; 13 | } 14 | else 15 | q++; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /2014/assignments/assignment1/solutions1-java/FindMissing.java: -------------------------------------------------------------------------------- 1 | public class FindMissing { 2 | 3 | public static void main(String[] args) { 4 | int a[] = { 0, 1, 2, 4, 5, 6 }; 5 | System.out.println("missing element in the given array is: " 6 | + findMissing(a, 6)); 7 | } 8 | 9 | static int findMissing(int a[], int n) { 10 | int res = 0; 11 | int i = 0; 12 | for (i = 0; i < n; i++) 13 | res = res ^ a[i] ^ i; 14 | res = res ^ i; 15 | return res; 16 | 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /2014/assignments/assignment2/assignment2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2014/assignments/assignment2/assignment2.pdf -------------------------------------------------------------------------------- /2014/assignments/assignment2/solutions2-java/MaxSeqeuence.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2014/assignments/assignment2/solutions2-java/MaxSeqeuence.java -------------------------------------------------------------------------------- /2014/assignments/assignment3/Assignment3-hashset, map.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2014/assignments/assignment3/Assignment3-hashset, map.pdf -------------------------------------------------------------------------------- /2014/assignments/assignment4/Assignment4-binrarytree.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2014/assignments/assignment4/Assignment4-binrarytree.pdf -------------------------------------------------------------------------------- /2014/assignments/assignment5/Assignment5-treeset, map.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2014/assignments/assignment5/Assignment5-treeset, map.pdf -------------------------------------------------------------------------------- /2014/c++ tutorial/list/STLlist1.cpp: -------------------------------------------------------------------------------- 1 | //Illustration of STL list operations 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main() { 7 | list l; 8 | l.push_back(30); 9 | l.push_back(20); 10 | l.push_back(10); 11 | l.push_back(40); 12 | l.push_front(15); 13 | l.pop_back(); 14 | l.insert(l.begin(),60); 15 | list::iterator i; 16 | for(i = l.begin(); i != l.end(); i++) 17 | cout<<*i< 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main() { 8 | map m; 9 | m.insert(make_pair(10,"abc")); 10 | m.insert(make_pair(20,"xyz")); 11 | m.insert(make_pair(20,"pqr")); 12 | m.insert(make_pair(25,"def")); 13 | map::iterator i; 14 | for(i = m.begin();i!=m.end();i++) 15 | cout<first<<" "<second< 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main() { 7 | map m; 8 | m.insert(make_pair(10,"abc")); 9 | m.insert(make_pair(20,"xyz")); 10 | m.insert(make_pair(15,"pqr")); 11 | m.insert(make_pair(25,"def")); 12 | map::iterator res = m.find(20); 13 | if(res==m.end()) cout<<"Element mapping not found"<second< 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | void display(map m) { 8 | map::iterator i = m.begin(); 9 | for(;i!=m.end();i++) 10 | cout<first<<" "<second< m; 15 | m.insert(make_pair(10,"abc")); 16 | m.insert(make_pair(20,"xyz")); 17 | m.insert(make_pair(15,"pqr")); 18 | m.insert(make_pair(25,"def")); 19 | display(m); 20 | m.erase(20); 21 | display(m); 22 | getchar(); 23 | } 24 | 25 | 26 | -------------------------------------------------------------------------------- /2014/c++ tutorial/map-multimap/STLmap4.cpp: -------------------------------------------------------------------------------- 1 | //Illustration of map operations 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | void display(map m) { 8 | map::iterator i = m.begin(); 9 | for(;i!=m.end();i++) 10 | cout<first<<" "<second< m; 15 | m[10]="abc"; 16 | m[25]="xyz"; 17 | m[20]="def"; 18 | m[10]="pqr"; 19 | m[11]="abc"; 20 | display(m); 21 | m.erase(20); 22 | display(m); 23 | getchar(); 24 | } 25 | 26 | 27 | -------------------------------------------------------------------------------- /2014/c++ tutorial/map-multimap/STLmaptmp.cpp: -------------------------------------------------------------------------------- 1 | //Illustration of map operations 2 | #include 3 | #include //it contains both map and multimap 4 | #include 5 | using namespace std; 6 | 7 | int main() { 8 | multimap m; 9 | m.insert(make_pair(10,"abc")); 10 | m.insert(make_pair(20,"xyz")); 11 | m.insert(make_pair(20,"pqr")); 12 | m.insert(make_pair(25,"def")); 13 | multimap::iterator i; 14 | for(i = m.begin();i!=m.end();i++) 15 | cout<first<<" "<second< 2 | using namespace std; 3 | 4 | int main() { 5 | pair p1(10,20); 6 | cout< p2 = make_pair(100, 200); 8 | cout< 2 | #include 3 | using namespace std; 4 | int main() { 5 | priority_queue pq1; 6 | pq1.push(10); 7 | pq1.push(20); 8 | pq1.push(15); 9 | pq1.push(25); 10 | while(!pq1.empty()) { 11 | cout< 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | queue q; 7 | for(long i = 1; i<=10; i++) 8 | q.push(i); 9 | cout<<"queue size:"< 3 | #include 4 | using namespace std; 5 | 6 | int main() { 7 | multiset s; 8 | s.insert(10); 9 | s.insert(20); 10 | s.insert(30); 11 | s.insert(10); 12 | s.insert(20); 13 | s.insert(17); 14 | multiset::iterator i; 15 | for(i=s.begin(); i!=s.end(); ++i) 16 | cout<<*i< 3 | #include 4 | using namespace std; 5 | 6 | int main() { 7 | multiset s; 8 | s.insert(10); 9 | s.insert(20); 10 | s.insert(25); 11 | s.insert(20); 12 | s.insert(15); 13 | s.insert(18); 14 | s.insert(10); 15 | s.insert(15); 16 | s.insert(17); 17 | multiset::iterator start = s.lower_bound(10); 18 | multiset::iterator end = s.upper_bound(20); 19 | for(; start!=end; ++start) 20 | cout<<*start< 3 | #include 4 | using namespace std; 5 | int main() { 6 | stack s; 7 | for(int i = 1; i<=10; i++) 8 | s.push(i); 9 | cout<<"stack size:"< 3 | #include 4 | using namespace std; 5 | int main() { 6 | vector v1; 7 | v1.push_back(30); 8 | v1.push_back(20); 9 | v1.push_back(10); 10 | v1.push_back(40); 11 | cout<<"vector size:"<::iterator i; 15 | for(i=v1.begin(); i!=v1.end(); i++) 16 | cout<<*i<<" "; 17 | cout< 3 | #include 4 | using namespace std; 5 | 6 | int main() { 7 | vector v1; 8 | v1.push_back(30); 9 | v1.push_back(20); 10 | v1.push_back(10); 11 | v1.push_back(40); 12 | vector::iterator i; 13 | for(i = v1.begin(); i!=v1.end();i++) 14 | cout<<*i< 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /2015/1-basic thinking/BasicThinking-java/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | BasicThinking-java 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /2015/1-basic thinking/BasicThinking-java/src/com/alg/basic/BinarySearch.java: -------------------------------------------------------------------------------- 1 | package com.alg.basic; 2 | 3 | public class BinarySearch { 4 | 5 | public static int binarysearch(int a[], int n) { 6 | int l = 0; 7 | int r = a.length; 8 | int m; 9 | while (l <= r) { 10 | m = l + (r - l) / 2; 11 | if (a[m] == n) 12 | return m; 13 | if (a[m] > n) 14 | r = m - 1; 15 | else 16 | l = m + 1; 17 | } 18 | return -1; 19 | } 20 | 21 | public static void main(String args[]) { 22 | int a[] = { 10, 20, 30, 40, 50 }; 23 | int n = 30; 24 | System.out.println(BinarySearch.binarysearch(a, n)); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /2015/1-basic thinking/In-Class Problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2015/1-basic thinking/In-Class Problems.pdf -------------------------------------------------------------------------------- /2015/2-recursive thinking/RecursiveThinking-java/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /2015/2-recursive thinking/RecursiveThinking-java/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | RecursiveThinking-java 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /2015/2-recursive thinking/RecursiveThinking-java/src/com/alg/rec/Power.java: -------------------------------------------------------------------------------- 1 | package com.alg.rec; 2 | 3 | public class Power { 4 | 5 | public static long doPower1(int x, int n) { 6 | long res = 1; 7 | for(int i = 1; i <= n; ++i) 8 | res = res * x; 9 | return res; 10 | } 11 | 12 | public static long doPower2(int x, int n) { 13 | if(n == 0) return 1; 14 | if(n == 1) return x; 15 | long res = doPower2(x, n/2); 16 | if(n%2 == 0) return res * res; 17 | else return res * res * x; 18 | } 19 | 20 | public static void main(String[] args) { 21 | System.out.println(doPower1(2,10)); 22 | System.out.println(doPower2(2,10)); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /2015/4-list data structure design(oo style)/List.java: -------------------------------------------------------------------------------- 1 | package com.collections; 2 | 3 | /** 4 | * @author Srinivas Reddy 5 | * @Email srinivas96alluri@gmail.com 6 | */ 7 | 8 | interface List { 9 | 10 | public int addElement(Type data, int pos); 11 | 12 | public int addElement(Type data); 13 | 14 | public boolean removeElement(int pos); 15 | 16 | public void clear(); 17 | } 18 | -------------------------------------------------------------------------------- /2015/5-linked list problems/MiddleNode.java: -------------------------------------------------------------------------------- 1 | /*Find the middle node of a linked list 2 | * */ 3 | package com.algorithmica.linkedlists; 4 | import com.algorithmica.linkedlists.LinkedListNode; 5 | public class MiddleNode { 6 | public static void main(String args[]) { 7 | LinkedListNode head = LinkedListNode.createList(); 8 | LinkedListNode.printList(head); 9 | LinkedListNode slow, fast; 10 | slow = fast = head; 11 | while (fast != null && fast.next != null) { 12 | slow = slow.next; 13 | fast = fast.next.next; 14 | 15 | } 16 | System.out.println("Middle is " + slow.data); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /2015/6-map data structure design(oo style)/hashmap/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /2015/6-map data structure design(oo style)/hashmap/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | hashmap 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /2015/6-map data structure design(oo style)/hashmap/bin/com/alg/top20/hashmap/MyHashMap.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2015/6-map data structure design(oo style)/hashmap/bin/com/alg/top20/hashmap/MyHashMap.class -------------------------------------------------------------------------------- /2015/6-map data structure design(oo style)/hashmap/bin/com/alg/top20/hashmap/MyLinkedList$Node.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2015/6-map data structure design(oo style)/hashmap/bin/com/alg/top20/hashmap/MyLinkedList$Node.class -------------------------------------------------------------------------------- /2015/6-map data structure design(oo style)/hashmap/bin/com/alg/top20/hashmap/MyLinkedList.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2015/6-map data structure design(oo style)/hashmap/bin/com/alg/top20/hashmap/MyLinkedList.class -------------------------------------------------------------------------------- /2015/6-map data structure design(oo style)/hashmap/bin/com/alg/top20/hashmap/TestMyHashMap.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2015/6-map data structure design(oo style)/hashmap/bin/com/alg/top20/hashmap/TestMyHashMap.class -------------------------------------------------------------------------------- /2015/6-map data structure design(oo style)/treemap/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /2015/6-map data structure design(oo style)/treemap/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | treemap1 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /2015/6-map data structure design(oo style)/treemap/bin/com/alg/top20/treemap/MyTreeMap$Node.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2015/6-map data structure design(oo style)/treemap/bin/com/alg/top20/treemap/MyTreeMap$Node.class -------------------------------------------------------------------------------- /2015/6-map data structure design(oo style)/treemap/bin/com/alg/top20/treemap/MyTreeMap.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2015/6-map data structure design(oo style)/treemap/bin/com/alg/top20/treemap/MyTreeMap.class -------------------------------------------------------------------------------- /2015/6-map data structure design(oo style)/treemap/bin/com/alg/top20/treemap/TestMyTreeMap.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2015/6-map data structure design(oo style)/treemap/bin/com/alg/top20/treemap/TestMyTreeMap.class -------------------------------------------------------------------------------- /2015/assignments/Assignment1-basic thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2015/assignments/Assignment1-basic thinking.pdf -------------------------------------------------------------------------------- /2015/assignments/Assignment10-dp thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2015/assignments/Assignment10-dp thinking.pdf -------------------------------------------------------------------------------- /2015/assignments/Assignment11-stack-queue problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2015/assignments/Assignment11-stack-queue problems.pdf -------------------------------------------------------------------------------- /2015/assignments/Assignment12-trie and bloofilters.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2015/assignments/Assignment12-trie and bloofilters.pdf -------------------------------------------------------------------------------- /2015/assignments/Assignment13-backtracking thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2015/assignments/Assignment13-backtracking thinking.pdf -------------------------------------------------------------------------------- /2015/assignments/Assignment2-basic thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2015/assignments/Assignment2-basic thinking.pdf -------------------------------------------------------------------------------- /2015/assignments/Assignment3-recursive thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2015/assignments/Assignment3-recursive thinking.pdf -------------------------------------------------------------------------------- /2015/assignments/Assignment4-linked list problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2015/assignments/Assignment4-linked list problems.pdf -------------------------------------------------------------------------------- /2015/assignments/Assignment5-tree problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2015/assignments/Assignment5-tree problems.pdf -------------------------------------------------------------------------------- /2015/assignments/Assignment6-tree problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2015/assignments/Assignment6-tree problems.pdf -------------------------------------------------------------------------------- /2015/assignments/Assignment7-set, map.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2015/assignments/Assignment7-set, map.pdf -------------------------------------------------------------------------------- /2015/assignments/Assignment8-greedy thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2015/assignments/Assignment8-greedy thinking.pdf -------------------------------------------------------------------------------- /2015/assignments/Assignment9-dp thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2015/assignments/Assignment9-dp thinking.pdf -------------------------------------------------------------------------------- /2016-jan/BitSet/src/com/alg/top20/bitset/TestBitSet.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bitset; 2 | 3 | public class TestBitSet { 4 | 5 | public static void main(String[] args) { 6 | BitSet bs = new BitSet(16); 7 | bs.display(); 8 | bs.set(2); 9 | bs.display(); 10 | bs.set(7); 11 | bs.display(); 12 | bs.set(8); 13 | bs.display(); 14 | System.out.println(bs.get(8)); 15 | System.out.println(bs.get(7)); 16 | System.out.println(bs.get(15)); 17 | bs.clear(8); 18 | bs.display(); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /2016-jan/Graph/src/com/alg/top20/graphs/IGraph.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.graphs; 2 | 3 | public interface IGraph { 4 | void addEdge(int u, int v); 5 | void traverse(); 6 | void display(); 7 | boolean hasCycle(); 8 | } 9 | -------------------------------------------------------------------------------- /2016-jan/Tries/src/com/alg/top20/tst/Trie.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.tst; 2 | 3 | import java.util.List; 4 | 5 | public interface Trie { 6 | void add(String key); 7 | boolean remove(String key); 8 | boolean contains(String key); 9 | List autocomplete(String prefix); 10 | int size(); 11 | void display(); 12 | } 13 | -------------------------------------------------------------------------------- /2016-jan/assignments/Assignment1-basic thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2016-jan/assignments/Assignment1-basic thinking.pdf -------------------------------------------------------------------------------- /2016-jan/assignments/Assignment10-dp thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2016-jan/assignments/Assignment10-dp thinking.pdf -------------------------------------------------------------------------------- /2016-jan/assignments/Assignment11-backtracking thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2016-jan/assignments/Assignment11-backtracking thinking.pdf -------------------------------------------------------------------------------- /2016-jan/assignments/Assignment2-basic thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2016-jan/assignments/Assignment2-basic thinking.pdf -------------------------------------------------------------------------------- /2016-jan/assignments/Assignment3-recursive thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2016-jan/assignments/Assignment3-recursive thinking.pdf -------------------------------------------------------------------------------- /2016-jan/assignments/Assignment4-linked list problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2016-jan/assignments/Assignment4-linked list problems.pdf -------------------------------------------------------------------------------- /2016-jan/assignments/Assignment5-tree problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2016-jan/assignments/Assignment5-tree problems.pdf -------------------------------------------------------------------------------- /2016-jan/assignments/Assignment6-tree problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2016-jan/assignments/Assignment6-tree problems.pdf -------------------------------------------------------------------------------- /2016-jan/assignments/Assignment7-set, map.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2016-jan/assignments/Assignment7-set, map.pdf -------------------------------------------------------------------------------- /2016-jan/assignments/Assignment8-greedy thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2016-jan/assignments/Assignment8-greedy thinking.pdf -------------------------------------------------------------------------------- /2016-jan/assignments/Assignment9-dp thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2016-jan/assignments/Assignment9-dp thinking.pdf -------------------------------------------------------------------------------- /2016-jan/backtracking/src/com/alg/top20/bt/DisplayBS.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bt; 2 | 3 | import java.util.Arrays; 4 | 5 | public class DisplayBS { 6 | 7 | private static void auxBS(int d, int n, int[] out) { 8 | if(d == n) { 9 | System.out.println(Arrays.toString(out)); 10 | return; 11 | } 12 | for(int i = 0; i <= 9; ++i) { 13 | out[d] = i; 14 | auxBS(d+1, n, out); 15 | } 16 | } 17 | public static void displayBS(int n) { 18 | int[] out = new int[n]; 19 | auxBS(0, n, out); 20 | } 21 | public static void main(String[] args) { 22 | int n = Integer.parseInt(args[0]); 23 | displayBS(n); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /2016-jan/oothinking/src/com/alg/top20/list/ArrayList.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.list; 2 | 3 | public class ArrayList implements List { 4 | 5 | @Override 6 | public void add(T e) { 7 | // TODO Auto-generated method stub 8 | 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /2016-jan/oothinking/src/com/alg/top20/list/LinkedList.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.list; 2 | 3 | public class LinkedList implements List { 4 | 5 | @Override 6 | public void add(T e) { 7 | // TODO Auto-generated method stub 8 | 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /2016-jan/oothinking/src/com/alg/top20/list/List.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.list; 2 | 3 | public interface List { 4 | void add(T e); 5 | } 6 | -------------------------------------------------------------------------------- /2016-jan/prqueue/src/com/alg/top20/pqueue/IPriorityQueue.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.pqueue; 2 | 3 | public interface IPriorityQueue { 4 | int size(); 5 | void display(); 6 | void add(Integer e); 7 | Integer findMin(); 8 | Integer removeMin(); 9 | } 10 | -------------------------------------------------------------------------------- /2016-jan/recursive-thinking/src/com/alg/top20/recursion/Honai.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.recursion; 2 | 3 | public class Honai { 4 | 5 | public static void honai(int n, char src, char aux, char target) { 6 | if(n == 1) { 7 | System.out.println(src + "->" + target); 8 | return; 9 | } 10 | honai(n-1, src, target, aux); 11 | System.out.println(src + "->" + target); 12 | honai(n-1,aux, src, target); 13 | } 14 | public static void main(String[] args) { 15 | honai(40,'A','B','C'); 16 | 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /2016-jan/recursive-thinking/src/com/alg/top20/recursion/Power.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.recursion; 2 | 3 | public class Power { 4 | 5 | public static long pow(int x, int n) { 6 | if(0 == n) return 1; 7 | if(1 == n) return x; 8 | long tmp = pow(x,n/2); 9 | if(n%2 == 0) 10 | return tmp * tmp; 11 | else 12 | return tmp * tmp * x; 13 | } 14 | public static void main(String[] args) { 15 | System.out.println(pow(2,16)); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /2016-may/MultiThreads/src/SubSortThread.java: -------------------------------------------------------------------------------- 1 | 2 | public class SubSortThread extends Thread { 3 | private int[] in; 4 | private int l; 5 | private int r; 6 | 7 | public SubSortThread(int[] in, int l, int r) { 8 | this.in = in; 9 | this.l = l; 10 | this.r = r; 11 | } 12 | 13 | private static void swap(int[] in, int i, int j) { 14 | int tmp = in[i]; 15 | in[i] = in[j]; 16 | in[j] = tmp; 17 | } 18 | @Override 19 | public void run() { 20 | for(int i = l; i < r; ++i) { 21 | int min = i; 22 | for(int j = i+1; j <= r; ++j) { 23 | if(in[j] < in[min]) 24 | min = j; 25 | } 26 | swap(in, i, min); 27 | } 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /2016-may/assignments/Assignment1-basic thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2016-may/assignments/Assignment1-basic thinking.pdf -------------------------------------------------------------------------------- /2016-may/assignments/Assignment2-basic thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2016-may/assignments/Assignment2-basic thinking.pdf -------------------------------------------------------------------------------- /2016-may/assignments/Assignment3-linked list problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2016-may/assignments/Assignment3-linked list problems.pdf -------------------------------------------------------------------------------- /2016-may/assignments/Assignment4-set, map.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2016-may/assignments/Assignment4-set, map.pdf -------------------------------------------------------------------------------- /2016-may/assignments/Assignment5-recursive thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2016-may/assignments/Assignment5-recursive thinking.pdf -------------------------------------------------------------------------------- /2016-may/assignments/Assignment6-tree problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2016-may/assignments/Assignment6-tree problems.pdf -------------------------------------------------------------------------------- /2016-may/assignments/Assignment7-bst problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2016-may/assignments/Assignment7-bst problems.pdf -------------------------------------------------------------------------------- /2016-may/balanced-bst/src/com/alg/top20/balbst/TreeNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.balbst; 2 | 3 | public class TreeNode { 4 | Integer data; 5 | TreeNode left; 6 | TreeNode right; 7 | int height; 8 | int lss; 9 | 10 | public TreeNode(Integer data) { 11 | this.data = data; 12 | height = 1; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /2016-may/binary-tree-problems/src/com/alg/top20/trees/TreeNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.trees; 2 | 3 | public class TreeNode { 4 | Integer data; 5 | TreeNode left; 6 | TreeNode right; 7 | 8 | public TreeNode(Integer data) { 9 | this.data = data; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /2016-may/bst-problems/src/com/alg/top20/bst/TreeNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bst; 2 | 3 | public class TreeNode { 4 | Integer data; 5 | TreeNode left; 6 | TreeNode right; 7 | int lss; 8 | 9 | public TreeNode(Integer data) { 10 | this.data = data; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /2016-may/graph-problems/src/com/alg/top20/graph/Igraph.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.graph; 2 | 3 | public interface Igraph { 4 | void addEdge(int u, int v); 5 | void addEdge(int u, int v, int w); 6 | void traverse(); 7 | int size(); 8 | boolean hasCycle(); 9 | void display(); 10 | boolean hasOddCycle(); 11 | boolean hasHamiltonianCycle(); 12 | int findMinCostST(); 13 | } 14 | -------------------------------------------------------------------------------- /2016-may/linked-list-problems/src/com/alg/top20/linkedlist/FindMiddle.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.linkedlist; 2 | 3 | public class FindMiddle { 4 | 5 | public static ListNode findMiddle(ListNode head) { 6 | ListNode slow, fast; 7 | slow = fast = head; 8 | while (fast != null && fast.next != null) { 9 | slow = slow.next; 10 | fast = fast.next.next; 11 | } 12 | return slow; 13 | } 14 | 15 | public static void main(String[] args) { 16 | // TODO Auto-generated method stub 17 | 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /2016-may/linked-list-problems/src/com/alg/top20/linkedlist/ListNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.linkedlist; 2 | 3 | public class ListNode { 4 | Integer data; 5 | ListNode next; 6 | 7 | } 8 | -------------------------------------------------------------------------------- /2016-may/oothinking/src/com/alg/top20/cache/ICache.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.cache; 2 | 3 | public interface ICache { 4 | void add(Integer key, String value); 5 | String get(Integer key); 6 | void display(); 7 | } 8 | -------------------------------------------------------------------------------- /2016-may/oothinking/src/com/alg/top20/genericlist/ArrayList.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.genericlist; 2 | 3 | public class ArrayList implements IList { 4 | private T[] array; 5 | private int size; 6 | 7 | @Override 8 | public void add(T e) { 9 | // TODO Auto-generated method stub 10 | 11 | } 12 | @Override 13 | public void add(int ind, T e) { 14 | // TODO Auto-generated method stub 15 | 16 | } 17 | @Override 18 | public T get(int ind) { 19 | // TODO Auto-generated method stub 20 | return null; 21 | } 22 | @Override 23 | public void display() { 24 | // TODO Auto-generated method stub 25 | 26 | } 27 | 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /2016-may/oothinking/src/com/alg/top20/genericlist/IList.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.genericlist; 2 | 3 | public interface IList { 4 | void add(T e); 5 | void add(int ind, T e); 6 | T get(int ind); 7 | void display(); 8 | } 9 | -------------------------------------------------------------------------------- /2016-may/oothinking/src/com/alg/top20/genericlist/TestList.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.genericlist; 2 | 3 | public class TestList { 4 | 5 | public static void test1(IList list) { 6 | list.add(10); 7 | list.add(20); 8 | list.display(); 9 | } 10 | 11 | public static void main(String[] args) { 12 | ArrayList al = new ArrayList(); 13 | /* al.add(10); 14 | al.add(20); 15 | al.display(); */ 16 | 17 | LinkedList ll = new LinkedList(); 18 | /*ll.add(40); 19 | ll.add(50); 20 | ll.display();*/ 21 | test1(al); 22 | test1(ll); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /2016-may/oothinking/src/com/alg/top20/list/IList.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.list; 2 | 3 | public interface IList { 4 | void add(Integer e); 5 | void add(int ind, Integer e); 6 | Integer get(int ind); 7 | void display(); 8 | void serialize(); 9 | void deserialize(); 10 | } 11 | -------------------------------------------------------------------------------- /2016-may/oothinking/src/com/alg/top20/map/IMap.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.map; 2 | 3 | public interface IMap { 4 | boolean add(Integer k, String v); 5 | boolean containsKey(Integer k); 6 | boolean containsValue(String v); 7 | boolean remove(Integer k); 8 | String get(Integer k); 9 | boolean set(Integer k, String v); 10 | int size(); 11 | void display(); 12 | } 13 | -------------------------------------------------------------------------------- /2016-may/oothinking/src/com/alg/top20/map/ISortedMap.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.map; 2 | 3 | public interface ISortedMap extends IMap { 4 | Integer findMin(); 5 | Integer findMax(); 6 | Integer select(int k); 7 | void findElementsInRange(Integer x, Integer y); 8 | } 9 | -------------------------------------------------------------------------------- /2016-may/oothinking/src/com/alg/top20/map/TestMap.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.map; 2 | 3 | import java.util.Random; 4 | 5 | public class TestMap { 6 | 7 | public static void testSet(IMap map, int n) { 8 | Random r = new Random(100); 9 | for (int i = 0; i < n; ++i) { 10 | map.add(r.nextInt(100000) + 1, "abc"); 11 | } 12 | map.display(); 13 | } 14 | 15 | public static void main(String[] args) { 16 | int n = Integer.parseInt(args[0]); 17 | testSet(new HashMap(), n); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /2016-may/oothinking/src/com/alg/top20/pqueue/IPQueue.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.pqueue; 2 | 3 | public interface IPQueue { 4 | void add(Integer key); 5 | Integer removeMin(); 6 | Integer findMin(); 7 | int size(); 8 | void display(); 9 | } 10 | -------------------------------------------------------------------------------- /2016-may/oothinking/src/com/alg/top20/pqueue/TestPrQueue.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.pqueue; 2 | 3 | import java.util.Random; 4 | 5 | public class TestPrQueue { 6 | 7 | public static void test1(IPQueue pq, int size) { 8 | Random r= new Random(100); 9 | for(int i = 0; i < size; ++i){ 10 | int re = r.nextInt(10) + 1; 11 | System.out.println(re); 12 | pq.add(re); 13 | pq.display(); 14 | } 15 | //pq.display(); 16 | } 17 | 18 | public static void main(String[] args) { 19 | int size = Integer.parseInt(args[0]); 20 | IPQueue pq = new HeapPQueue(); 21 | test1(pq, size); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /2016-may/oothinking/src/com/alg/top20/set/ISet.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.set; 2 | 3 | public interface ISet { 4 | boolean add(Integer e); 5 | boolean contains(Integer e); 6 | boolean remove(Integer e); 7 | int size(); 8 | void display(); 9 | void serialize(); 10 | void deserialize(); 11 | } 12 | -------------------------------------------------------------------------------- /2016-may/oothinking/src/com/alg/top20/set/ISortedSet.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.set; 2 | 3 | public interface ISortedSet extends ISet { 4 | Integer findMin(); 5 | Integer findMax(); 6 | Integer select(int k); 7 | void findElementsInRange(Integer x, Integer y); 8 | } 9 | -------------------------------------------------------------------------------- /2016-may/oothinking/src/com/alg/top20/set/TestSet.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.set; 2 | 3 | import java.util.Random; 4 | 5 | public class TestSet { 6 | 7 | public static void testSet(ISet set, int n) { 8 | Random r = new Random(100); 9 | for (int i = 0; i < n; ++i) { 10 | set.add(r.nextInt(100000) + 1); 11 | } 12 | set.display(); 13 | } 14 | 15 | public static void main(String[] args) { 16 | int n = Integer.parseInt(args[0]); 17 | testSet(new HashSet(), n); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /2016-may/recursive-thinking/src/com/alg/top20/recursion/Power.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.recursion; 2 | 3 | public class Power { 4 | 5 | public static long pow(int x, int n) { 6 | if(n == 0) return 1; 7 | if(n == 1) return x; 8 | long tmp = pow(x,n/2); 9 | if(n % 2 == 0) 10 | return tmp * tmp; 11 | else 12 | return tmp * tmp * x; 13 | } 14 | public static void main(String[] args) { 15 | System.out.println(pow(2,19)); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /2016-may/recursive-thinking/src/com/alg/top20/recursion/TowersOfHonai.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.recursion; 2 | 3 | public class TowersOfHonai { 4 | 5 | public static void honai(int n, char src, char aux, char target) { 6 | if(n==1) { 7 | System.out.println(src + "->" + target); 8 | return; 9 | } 10 | honai(n-1,src,target,aux); 11 | System.out.println(src + "->" + target); 12 | honai(n-1,aux,src,target); 13 | } 14 | 15 | public static void main(String[] args) { 16 | honai(4, 'A', 'B', 'C'); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /2016-may/trie/src/com/alg/top20/trie/ITrie.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.trie; 2 | 3 | import java.util.Queue; 4 | 5 | public interface ITrie { 6 | public void add(String word); 7 | public boolean contains(String word); 8 | public boolean remove(String word); 9 | public Queue autocomplete(String prefix); 10 | public int size(); 11 | public void display(); 12 | public String findLongestCommonPrefix(String word); 13 | } 14 | -------------------------------------------------------------------------------- /2016-september/10.sorted-table/src/com/alg/top20/sortedtable/DListNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.sortedtable; 2 | 3 | public class DListNode { 4 | Employee value; 5 | DListNode prev; 6 | DListNode next; 7 | 8 | public DListNode() { 9 | prev = next = this; 10 | } 11 | public DListNode(Employee value) { 12 | super(); 13 | this.value = value; 14 | } 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /2016-september/10.sorted-table/src/com/alg/top20/sortedtable/ISortedTable.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.sortedtable; 2 | 3 | import java.util.List; 4 | 5 | public interface ISortedTable { 6 | void addRow(Employee e); 7 | List retrieveInOrder(String column); 8 | void display(); 9 | boolean removeRow(); 10 | } 11 | -------------------------------------------------------------------------------- /2016-september/11.trie/src/com/alg/top20/trie/Driver.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.trie; 2 | 3 | public class Driver { 4 | 5 | public static void testTrie(ITrie trie) { 6 | trie.add("lmn"); 7 | trie.add("abc"); 8 | trie.add("ab"); 9 | trie.add("aaaaa"); 10 | trie.add("aab"); 11 | trie.add("xyz"); 12 | trie.add("bcd"); 13 | trie.display(); 14 | System.out.println(); 15 | System.out.println(trie.autocomplete("a")); 16 | System.out.println(); 17 | System.out.println(trie.autocomplete("ab")); 18 | } 19 | public static void main(String[] args) { 20 | testTrie(new TernarySearchTree()); 21 | 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /2016-september/11.trie/src/com/alg/top20/trie/ITrie.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.trie; 2 | 3 | import java.util.Queue; 4 | 5 | public interface ITrie { 6 | void add(String word); 7 | boolean remove(String word); 8 | boolean contains(String word); 9 | boolean containsWildCard(String word); 10 | Queue autocomplete(String prefix); 11 | void display(); 12 | int size(); 13 | } 14 | -------------------------------------------------------------------------------- /2016-september/15.queue/src/com/alg/top20/pqueue/IPQueue.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.pqueue; 2 | 3 | public interface IPQueue { 4 | void add(Integer e); 5 | Integer findMax(); 6 | Integer removeMax(); 7 | int size(); 8 | void display(); 9 | } 10 | -------------------------------------------------------------------------------- /2016-september/15.queue/src/com/alg/top20/queue/Driver.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.queue; 2 | 3 | import java.util.Random; 4 | 5 | public class Driver { 6 | 7 | public static void testQueue(IQueue queue, int size) { 8 | Random r = new Random(100); 9 | for(int i = 0; i < size; ++i) { 10 | queue.add(r.nextInt(100) + 1); 11 | } 12 | queue.display(); 13 | System.out.println(); 14 | System.out.println(queue.size()); 15 | System.out.println(queue.remove()); 16 | queue.display(); 17 | } 18 | public static void main(String[] args) { 19 | testQueue(new LinkedQueue(), Integer.parseInt(args[0])); 20 | 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /2016-september/15.queue/src/com/alg/top20/queue/IQueue.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.queue; 2 | 3 | public interface IQueue { 4 | void add(Integer e); 5 | Integer remove(); 6 | int size(); 7 | void display(); 8 | } 9 | -------------------------------------------------------------------------------- /2016-september/17.file-problems/src/com/alg/top20/file/BoundedBuffer.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.file; 2 | 3 | import java.util.LinkedList; 4 | 5 | public class BoundedBuffer { 6 | private LinkedList buffer; 7 | private int capacity; 8 | 9 | public BoundedBuffer(int n) { 10 | buffer = new LinkedList(); 11 | capacity = n; 12 | } 13 | 14 | public void add(String line) { 15 | if(buffer.size() >= capacity) 16 | buffer.removeFirst(); 17 | buffer.add(line); 18 | } 19 | 20 | public String get(int ind) { 21 | return buffer.get(ind); 22 | } 23 | 24 | public int size() { 25 | return buffer.size(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /2016-september/17.file-problems/src/com/alg/top20/file/IFilter.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.file; 2 | 3 | public interface IFilter { 4 | void add(String key); 5 | boolean contains(String key); 6 | } 7 | -------------------------------------------------------------------------------- /2016-september/19.multcore-programming/src/com/alg/top20/mc/sorting/Sorting.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.mc.sorting; 2 | 3 | import java.util.Arrays; 4 | 5 | public class Sorting { 6 | private static void swap(int[] in, int i, int j) { 7 | int tmp = in[i]; 8 | in[i] = in[j]; 9 | in[j] = tmp; 10 | } 11 | 12 | public static void selection_sort_seq(int[] in) { 13 | for(int i = 0; i < in.length-1; ++i) { 14 | int min_index = i; 15 | for(int j = i+1; j < in.length; ++j) { 16 | if(in[j] < in[min_index]) { 17 | min_index = j; 18 | } 19 | } 20 | swap(in, i, min_index); 21 | //System.out.println(Arrays.toString(in)); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /2016-september/19.multcore-programming/src/com/alg/top20/mc/sorting/ThreadDemo2.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.mc.sorting; 2 | 3 | public class ThreadDemo2 { 4 | 5 | static class MyThread extends Thread { 6 | private int id; 7 | 8 | MyThread(int id) { 9 | this.id = id; 10 | } 11 | public void run() { 12 | while (true) { 13 | System.out.println("Thread" + id); 14 | } 15 | } 16 | } 17 | 18 | public static void main(String[] args) { 19 | MyThread[] threads = new MyThread[100]; 20 | for(int i = 0; i < 100; ++i) { 21 | threads[i] = new MyThread(i); 22 | threads[i].start(); 23 | } 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /2016-september/2.oop/src/com/alg/top20/oop/encapsulation/ArrayList.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.oop.encapsulation; 2 | 3 | public class ArrayList { 4 | 5 | /*struct arryalist { 6 | int[] array; 7 | int size; 8 | }*/ 9 | private int[] array; 10 | private int size; 11 | 12 | /* void init(struct arraylist* list) { 13 | 14 | }*/ 15 | public ArrayList() { 16 | array = new int[10]; 17 | size = 0; 18 | } 19 | /* int get(struct arraylist* list, int ind) { 20 | * } 21 | */ 22 | public int get(int ind) { 23 | return array[ind]; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /2016-september/2.oop/src/com/alg/top20/oop/encapsulation/ListDriver.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.oop.encapsulation; 2 | 3 | public class ListDriver { 4 | 5 | /** 6 | * @param args 7 | */ 8 | public static void main(String[] args) { 9 | ArrayList al = new ArrayList(); 10 | System.out.println(al.get(0)); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /2016-september/2.oop/src/com/alg/top20/oop/extensibility/ArrayList.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.oop.extensibility; 2 | 3 | public class ArrayList implements IList{ 4 | 5 | /*struct arryalist { 6 | int[] array; 7 | int size; 8 | }*/ 9 | private int[] array; 10 | private int size; 11 | 12 | /* void init(struct arraylist* list) { 13 | 14 | }*/ 15 | public ArrayList() { 16 | array = new int[10]; 17 | size = 0; 18 | } 19 | /* int get(struct arraylist* list, int ind) { 20 | * } 21 | */ 22 | public int get(int ind) { 23 | return array[ind]; 24 | } 25 | 26 | public int size() { 27 | return size; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /2016-september/2.oop/src/com/alg/top20/oop/extensibility/IList.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.oop.extensibility; 2 | 3 | public interface IList { 4 | int get(int ind); 5 | int size(); 6 | } 7 | -------------------------------------------------------------------------------- /2016-september/2.oop/src/com/alg/top20/oop/extensibility/LinkedList.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.oop.extensibility; 2 | 3 | public class LinkedList implements IList { 4 | 5 | private class ListNode { 6 | Integer data; 7 | ListNode next; 8 | public ListNode() { 9 | 10 | } 11 | } 12 | 13 | private ListNode first; 14 | private int size; 15 | 16 | public LinkedList() { 17 | 18 | } 19 | 20 | @Override 21 | public int get(int ind) { 22 | // TODO Auto-generated method stub 23 | return 0; 24 | } 25 | 26 | @Override 27 | public int size() { 28 | // TODO Auto-generated method stub 29 | return 0; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /2016-september/2.oop/src/com/alg/top20/oop/extensibility/ListDriver.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.oop.extensibility; 2 | 3 | public class ListDriver { 4 | 5 | public static void testList(IList list) { 6 | System.out.println(list.get(0)); 7 | } 8 | public static void main(String[] args) { 9 | testList(new ArrayList()); 10 | testList(new LinkedList()); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /2016-september/2.oop/src/com/alg/top20/oop/reuse/AbstractList.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.oop.reuse; 2 | 3 | public abstract class AbstractList implements IList{ 4 | 5 | protected int size; 6 | 7 | public int size() { 8 | return size; 9 | } 10 | 11 | 12 | } 13 | -------------------------------------------------------------------------------- /2016-september/2.oop/src/com/alg/top20/oop/reuse/ArrayList.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.oop.reuse; 2 | 3 | public class ArrayList extends AbstractList { 4 | 5 | /*struct arryalist { 6 | int[] array; 7 | int size; 8 | }*/ 9 | private int[] array; 10 | 11 | /* void init(struct arraylist* list) { 12 | 13 | }*/ 14 | public ArrayList() { 15 | array = new int[10]; 16 | size = 0; 17 | } 18 | /* int get(struct arraylist* list, int ind) { 19 | * } 20 | */ 21 | public int get(int ind) { 22 | return array[ind]; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /2016-september/2.oop/src/com/alg/top20/oop/reuse/IList.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.oop.reuse; 2 | 3 | public interface IList { 4 | int get(int ind); 5 | int size(); 6 | } 7 | -------------------------------------------------------------------------------- /2016-september/2.oop/src/com/alg/top20/oop/reuse/LinkedList.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.oop.reuse; 2 | 3 | public class LinkedList extends AbstractList { 4 | 5 | private class ListNode { 6 | Integer data; 7 | ListNode next; 8 | public ListNode() { 9 | 10 | } 11 | } 12 | 13 | private ListNode first; 14 | 15 | public LinkedList() { 16 | 17 | } 18 | 19 | @Override 20 | public int get(int ind) { 21 | // TODO Auto-generated method stub 22 | return 0; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /2016-september/2.oop/src/com/alg/top20/oop/reuse/ListDriver.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.oop.reuse; 2 | 3 | public class ListDriver { 4 | 5 | public static void testList(IList list) { 6 | System.out.println(list.get(0)); 7 | } 8 | public static void main(String[] args) { 9 | testList(new ArrayList()); 10 | testList(new LinkedList()); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /2016-september/20.bitwise-problems/src/com/alg/top20/bits/ExtractHostFromIP.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bits; 2 | 3 | public class ExtractHostFromIP { 4 | 5 | public static int getHostIdClassA(int ip) { 6 | return ip & 0x00FFFFFF; 7 | } 8 | public static int getNetworkIdClassA(int ip) { 9 | return (ip >>> 24)& 0x000000FF; 10 | } 11 | public static void main(String[] args) { 12 | int n = 240 + (1 << 30) + (1 << 29) + (1<<31); 13 | BitwiseOperators.show_bits(n); 14 | System.out.println(getHostIdClassA(n)); 15 | System.out.println(getNetworkIdClassA(n)); 16 | 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /2016-september/20.bitwise-problems/src/com/alg/top20/bits/IsEvenOdd.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bits; 2 | 3 | public class IsEvenOdd { 4 | 5 | public static boolean isEven1(int n) { 6 | return n % 2 ==0; 7 | } 8 | 9 | public static boolean isEven2(int n) { 10 | return (n & 1) == 0; 11 | } 12 | public static void main(String[] args) { 13 | System.out.println(isEven1(20)); 14 | System.out.println(isEven2(20)); 15 | System.out.println(isEven1(31)); 16 | System.out.println(isEven2(31)); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /2016-september/21.graph-problems/src/com/alg/top20/graphs/IUnweightedGraph.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.graphs; 2 | 3 | public interface IUnweightedGraph { 4 | void addEdge(int u, int v); 5 | void traverse_depth(); 6 | void traverse_breadth(); 7 | boolean hasCycle(); 8 | void display(); 9 | } 10 | -------------------------------------------------------------------------------- /2016-september/3.list/src/com/alg/top20/list/AbstractList.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.list; 2 | 3 | public abstract class AbstractList implements IList{ 4 | 5 | protected int size; 6 | 7 | public int size() { 8 | return size; 9 | } 10 | public void reverse() { } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /2016-september/3.list/src/com/alg/top20/list/IList.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.list; 2 | 3 | public interface IList { 4 | int get(int ind); 5 | int size(); 6 | void add(int e); 7 | void add(int ind, int e); 8 | void remove(int ind); 9 | void set(int ind, int e); 10 | void display(); 11 | boolean contains(int e); 12 | void reverse(); 13 | } 14 | -------------------------------------------------------------------------------- /2016-september/4.linkedlist-problems/src/com/alg/top20/ll/ListNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.ll; 2 | 3 | public class ListNode { 4 | Integer data; 5 | ListNode next; 6 | 7 | public ListNode() { 8 | 9 | } 10 | public ListNode(int i) { 11 | data = i; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /2016-september/4.linkedlist-problems/src/com/alg/top20/ll/RandomTest.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.ll; 2 | 3 | import java.util.Random; 4 | 5 | public class RandomTest { 6 | 7 | /** 8 | * @param args 9 | */ 10 | public static void main(String[] args) { 11 | Random r = new Random(); 12 | System.out.println(r.nextInt(4)); 13 | 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /2016-september/5.set/src/com/alg/top20/set/BSTNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.set; 2 | 3 | public class BSTNode { 4 | Integer data; 5 | BSTNode left; 6 | BSTNode right; 7 | int lst_size; 8 | 9 | public BSTNode(Integer data) { 10 | super(); 11 | this.data = data; 12 | } 13 | 14 | @Override 15 | public String toString() { 16 | return "BSTNode [data=" + data + ", lst_size=" + lst_size + "]"; 17 | } 18 | 19 | 20 | 21 | } 22 | -------------------------------------------------------------------------------- /2016-september/5.set/src/com/alg/top20/set/ISet.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.set; 2 | 3 | public interface ISet { 4 | boolean add(Integer e); 5 | boolean contains(Integer e); 6 | boolean remove(Integer e); 7 | int size(); 8 | void display(); 9 | } 10 | -------------------------------------------------------------------------------- /2016-september/5.set/src/com/alg/top20/set/ISortedSet.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.set; 2 | 3 | import java.util.List; 4 | 5 | public interface ISortedSet extends ISet { 6 | int findMin(); 7 | int select(int k); 8 | List findRange(Integer s, Integer e); 9 | } 10 | -------------------------------------------------------------------------------- /2016-september/5.set/src/com/alg/top20/set/ListNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.set; 2 | 3 | public class ListNode { 4 | Integer data; 5 | ListNode next; 6 | 7 | public ListNode() { 8 | 9 | } 10 | public ListNode(int i) { 11 | data = i; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /2016-september/6.map/src/com/alg/top20/map/Driver.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.map; 2 | 3 | import java.util.Random; 4 | import java.util.UUID; 5 | 6 | public class Driver { 7 | 8 | public static void main(String[] args) { 9 | HashMap hmap = new HashMap(); 10 | 11 | int limit = Integer.parseInt(args[0]); 12 | Random r = new Random(100); 13 | 14 | for(int i = 1; i <= limit; ++i) { 15 | hmap.put(UUID.randomUUID().toString(),r.nextInt(1000)); 16 | } 17 | System.out.println(hmap.size()); 18 | hmap.display(); 19 | 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /2016-september/6.map/src/com/alg/top20/map/IMap.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.map; 2 | 3 | 4 | interface IMap { 5 | boolean put(String key, Integer value); 6 | Integer get(String key); 7 | boolean remove(String key); 8 | int size(); 9 | void display(); 10 | boolean containsKey(String key); 11 | boolean containsValue(Integer value); 12 | } -------------------------------------------------------------------------------- /2016-september/6.map/src/com/alg/top20/map/ListNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.map; 2 | 3 | public class ListNode { 4 | String key; 5 | Integer value; 6 | ListNode next; 7 | 8 | public ListNode() { 9 | 10 | } 11 | 12 | public ListNode(String key, Integer value) { 13 | super(); 14 | this.key = key; 15 | this.value = value; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /2016-september/7.cache/src/com/alg/top20/cache/DListNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.cache; 2 | 3 | public class DListNode { 4 | String key; 5 | Integer value; 6 | DListNode prev; 7 | DListNode next; 8 | 9 | public DListNode() { 10 | prev = next = this; 11 | } 12 | public DListNode(String key, Integer value) { 13 | super(); 14 | this.key = key; 15 | this.value = value; 16 | } 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /2016-september/7.cache/src/com/alg/top20/cache/ICache.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.cache; 2 | 3 | public interface ICache { 4 | void put(String key, Integer value); 5 | Integer get(String key); 6 | int size(); 7 | int capacity(); 8 | void display(); 9 | } 10 | -------------------------------------------------------------------------------- /2016-september/8.recursive-thinking/src/com/alg/top20/recursion/Honai.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.recursion; 2 | 3 | public class Honai { 4 | 5 | public static void honai(int n, char src, char aux, char target) { 6 | if(n == 1) { 7 | System.out.println(src + "->" + target); 8 | return; 9 | } 10 | honai(n-1, src, target, aux); 11 | System.out.println(src + "->" + target); 12 | honai(n-1,aux, src, target); 13 | } 14 | public static void main(String[] args) { 15 | honai(40,'A','B','C'); 16 | 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /2016-september/8.recursive-thinking/src/com/alg/top20/recursion/Power.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.recursion; 2 | 3 | public class Power { 4 | 5 | public static long pow(int x, int n) { 6 | if(0 == n) return 1; 7 | if(1 == n) return x; 8 | long tmp = pow(x,n/2); 9 | if(n%2 == 0) 10 | return tmp * tmp; 11 | else 12 | return tmp * tmp * x; 13 | } 14 | public static void main(String[] args) { 15 | System.out.println(pow(2,16)); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /2016-september/9.tree-problems/src/com/alg/top20/trees/size/TreeNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.trees.size; 2 | 3 | public class TreeNode { 4 | public int data; 5 | public TreeNode left; 6 | public TreeNode right; 7 | 8 | public TreeNode(int data) { 9 | super(); 10 | this.data = data; 11 | } 12 | 13 | 14 | 15 | } 16 | -------------------------------------------------------------------------------- /2016-september/assignments/Assignment1-basic thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2016-september/assignments/Assignment1-basic thinking.pdf -------------------------------------------------------------------------------- /2016-september/assignments/Assignment10-greedy thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2016-september/assignments/Assignment10-greedy thinking.pdf -------------------------------------------------------------------------------- /2016-september/assignments/Assignment11-dp thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2016-september/assignments/Assignment11-dp thinking.pdf -------------------------------------------------------------------------------- /2016-september/assignments/Assignment12-dp thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2016-september/assignments/Assignment12-dp thinking.pdf -------------------------------------------------------------------------------- /2016-september/assignments/Assignment13-backtracking thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2016-september/assignments/Assignment13-backtracking thinking.pdf -------------------------------------------------------------------------------- /2016-september/assignments/Assignment2-basic thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2016-september/assignments/Assignment2-basic thinking.pdf -------------------------------------------------------------------------------- /2016-september/assignments/Assignment3-linked list problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2016-september/assignments/Assignment3-linked list problems.pdf -------------------------------------------------------------------------------- /2016-september/assignments/Assignment4-set, map.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2016-september/assignments/Assignment4-set, map.pdf -------------------------------------------------------------------------------- /2016-september/assignments/Assignment5-recursive thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2016-september/assignments/Assignment5-recursive thinking.pdf -------------------------------------------------------------------------------- /2016-september/assignments/Assignment6-tree problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2016-september/assignments/Assignment6-tree problems.pdf -------------------------------------------------------------------------------- /2016-september/assignments/Assignment7-bst problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2016-september/assignments/Assignment7-bst problems.pdf -------------------------------------------------------------------------------- /2016-september/assignments/Assignment8-trie and bloofilters.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2016-september/assignments/Assignment8-trie and bloofilters.pdf -------------------------------------------------------------------------------- /2016-september/assignments/Assignment9-stack-queue problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2016-september/assignments/Assignment9-stack-queue problems.pdf -------------------------------------------------------------------------------- /2017-january/10.tree-problems/src/com/alg/top20/trees/BTreeNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.trees; 2 | 3 | public class BTreeNode { 4 | Integer data; 5 | BTreeNode left; 6 | BTreeNode right; 7 | 8 | public BTreeNode(Integer data) { 9 | this.data = data; 10 | } 11 | public BTreeNode(Integer data, BTreeNode left, BTreeNode right) { 12 | super(); 13 | this.data = data; 14 | this.left = left; 15 | this.right = right; 16 | } 17 | public BTreeNode() { 18 | } 19 | 20 | 21 | } 22 | -------------------------------------------------------------------------------- /2017-january/11.sorted-table/src/com/alg/top20/sortedtable/ISortedTable.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.sortedtable; 2 | 3 | import java.util.List; 4 | 5 | public interface ISortedTable { 6 | void add(TravelsInfo tinfo) throws Exception; 7 | void addSortedFields(List fields); 8 | void display(String field); 9 | } 10 | -------------------------------------------------------------------------------- /2017-january/12.greedy/src/com/alg/top20/TestMultiSet.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20; 2 | 3 | import com.google.common.collect.TreeMultiset; 4 | 5 | public class TestMultiSet { 6 | 7 | /** 8 | * @param args 9 | */ 10 | public static void main(String[] args) { 11 | TreeMultiset bag = TreeMultiset.create(); 12 | bag.add(10); 13 | bag.add(10); 14 | bag.add(20); 15 | bag.add(25); 16 | bag.add(20); 17 | System.out.println(bag.size()); 18 | System.out.println(bag.firstEntry()); 19 | System.out.println(bag.firstEntry()); 20 | System.out.println(bag.size()); 21 | /*for(int e:bag) 22 | System.out.println(e);*/ 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /2017-january/14.file-problems/src/com/alg/top20/file/CircularBuffer.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.file; 2 | 3 | import java.util.LinkedList; 4 | 5 | public class CircularBuffer { 6 | private LinkedList buffer; 7 | private int capacity; 8 | private int size; 9 | 10 | public CircularBuffer(int n) { 11 | buffer = new LinkedList(); 12 | size = 0; 13 | capacity = n; 14 | } 15 | 16 | public void add(String e) { 17 | if(size == capacity) 18 | buffer.removeFirst(); 19 | else 20 | ++size; 21 | buffer.addLast(e); 22 | } 23 | 24 | public String readFirst() { 25 | return buffer.getFirst(); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /2017-january/15.priority-queue/src/com/alg/top20/pqueue/IPQueue.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.pqueue; 2 | 3 | public interface IPQueue { 4 | Integer findMin(); 5 | Integer removeMin(); 6 | void display(); 7 | int size(); 8 | boolean isEmpty(); 9 | void add(Integer e); 10 | } 11 | -------------------------------------------------------------------------------- /2017-january/17.radixtree/src/com/alg/top20/autocmpletion/ITrie.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.autocmpletion; 2 | 3 | import java.util.List; 4 | 5 | public interface ITrie { 6 | void add(String key); 7 | boolean contains(String key); 8 | void remove(String key); 9 | void display(); 10 | int size(); 11 | List autocomplete(String prefix); 12 | int findCommonPrefixLength(String key); 13 | } 14 | -------------------------------------------------------------------------------- /2017-january/2.oo-thinking/src/com/alg/top20/oop/Encapsulation.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.oop; 2 | 3 | class Dummy1 { 4 | private int a; 5 | private int b; 6 | 7 | public Dummy1(int a, int b) { 8 | this.a = a ; 9 | this.b = b; 10 | } 11 | 12 | public int sum() { 13 | return a +b; 14 | } 15 | 16 | public int mul() { 17 | return a * b; 18 | } 19 | } 20 | public class Encapsulation { 21 | 22 | public static void main(String[] args) { 23 | Dummy1 d1 = new Dummy1(10,20); 24 | d1.sum(); 25 | d1.mul(); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /2017-january/20.bitwise-problems/src/com/alg/top20/bitwise/IPAdress.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bitwise; 2 | 3 | public class IPAdress { 4 | 5 | public static int getNetworkId(int ip) { 6 | return (ip >>> 24) & 0xFF; 7 | } 8 | 9 | public static int getHostId(int ip) { 10 | return ip & 0xFFFFFF; 11 | } 12 | 13 | public static void main(String[] args) { 14 | int ip = 0x10100000; 15 | System.out.println(getHostId(ip)); 16 | System.out.println(getNetworkId(ip)); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /2017-january/20.bitwise-problems/src/com/alg/top20/bitwise/ModuloDivision.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bitwise; 2 | 3 | public class ModuloDivision { 4 | 5 | public static int moduloDivision8Sol1(int n) { 6 | return n % 8; 7 | } 8 | public static int moduloDivision8Sol2(int n) { 9 | return n & 7; 10 | } 11 | public static void main(String[] args) { 12 | int n = Integer.parseInt(args[0]); 13 | System.out.println(moduloDivision8Sol1(n)); 14 | System.out.println(moduloDivision8Sol2(n)); 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /2017-january/20.bitwise-problems/src/com/alg/top20/bitwise/NextHighestMultiple.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bitwise; 2 | 3 | public class NextHighestMultiple { 4 | 5 | public static int nextHighestMultiple8Sol1(int n) { 6 | return ((n-1) / 8 + 1) * 8; 7 | } 8 | 9 | public static int nextHighestMultiple8Sol2(int n) { 10 | return (n + 7) & ~7; 11 | } 12 | public static void main(String[] args) { 13 | int n = Integer.parseInt(args[0]); 14 | System.out.println(nextHighestMultiple8Sol1(n)); 15 | System.out.println(nextHighestMultiple8Sol2(n)); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /2017-january/20.bitwise-problems/src/com/alg/top20/bitwise/Utils.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bitwise; 2 | 3 | public class Utils { 4 | 5 | public static void showBits(int n) { 6 | int mask = 1 << 31; 7 | for(int i = 0; i < 32;++i) { 8 | if( (n & mask) != 0) 9 | System.out.print("1"); 10 | else 11 | System.out.print("0"); 12 | mask >>>= 1; 13 | } 14 | System.out.println(); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /2017-january/3.list/src/com/alg/top20/list/IList.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.list; 2 | 3 | //Apply abstraction: usage perspective of an object 4 | public interface IList { 5 | Integer get(int index); 6 | void add(Integer e); 7 | void display(); 8 | int size(); 9 | } 10 | -------------------------------------------------------------------------------- /2017-january/4.linked-list problems/src/com/alg/top20/linkedlist/ListNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.linkedlist; 2 | 3 | public class ListNode { 4 | Integer data; 5 | ListNode next; 6 | ListNode(Integer data) { 7 | this.data = data; 8 | this.next = null; 9 | } 10 | ListNode() { 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /2017-january/6.cache/src/com/alg/top20/cache/DListNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.cache; 2 | 3 | public class DListNode { 4 | String key; 5 | Integer value; 6 | DListNode prev; 7 | DListNode next; 8 | 9 | public DListNode() { 10 | prev = next = this; 11 | } 12 | 13 | public DListNode(String key, Integer value) { 14 | this.key = key; 15 | this.value = value; 16 | prev = next = this; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /2017-january/6.cache/src/com/alg/top20/cache/ICache.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.cache; 2 | 3 | public interface ICache { 4 | Integer get(String key); 5 | void add(String key, Integer value); 6 | void display(); 7 | int capacity(); 8 | int size(); 9 | } 10 | 11 | //ICache 12 | -------------------------------------------------------------------------------- /2017-january/7.set/src/com/alg/top20/set/BTreeNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.set; 2 | 3 | public class BTreeNode { 4 | Integer data; 5 | int lst_size; 6 | BTreeNode left; 7 | BTreeNode right; 8 | 9 | public BTreeNode(Integer data) { 10 | this.data = data; 11 | } 12 | public BTreeNode(Integer data, BTreeNode left, BTreeNode right) { 13 | super(); 14 | this.data = data; 15 | this.left = left; 16 | this.right = right; 17 | } 18 | public BTreeNode() { 19 | } 20 | 21 | 22 | } 23 | -------------------------------------------------------------------------------- /2017-january/7.set/src/com/alg/top20/set/ISet.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.set; 2 | 3 | public interface ISet { 4 | boolean add(Integer key); 5 | boolean contains(Integer key); 6 | boolean remove(Integer key); 7 | int size(); 8 | void display(); 9 | } 10 | -------------------------------------------------------------------------------- /2017-january/7.set/src/com/alg/top20/set/ISortedSet.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.set; 2 | 3 | public interface ISortedSet extends ISet { 4 | Integer findMin(); 5 | Integer select(int k); 6 | } 7 | -------------------------------------------------------------------------------- /2017-january/7.set/src/com/alg/top20/set/ListNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.set; 2 | 3 | public class ListNode { 4 | Integer data; 5 | ListNode next; 6 | ListNode(Integer data) { 7 | this.data = data; 8 | this.next = null; 9 | } 10 | ListNode() { 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /2017-january/8.recursive-thinking/src/com/alg/top20/recursion/Honai.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.recursion; 2 | 3 | public class Honai { 4 | 5 | private static int counter = 0; 6 | 7 | public static void honai(int n, char src, char aux, char target) { 8 | if(n == 0) return; 9 | honai(n-1, src, target, aux); 10 | ++counter; 11 | System.out.println(src + "->" + target); 12 | honai(n-1, aux, src, target); 13 | } 14 | public static void main(String[] args) { 15 | int n = Integer.parseInt(args[0]); 16 | honai(n, 'A', 'B', 'C'); 17 | System.out.println("total moves:" + counter); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /2017-january/assignments/Assignment1-basic thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2017-january/assignments/Assignment1-basic thinking.pdf -------------------------------------------------------------------------------- /2017-january/assignments/Assignment10-greedy thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2017-january/assignments/Assignment10-greedy thinking.pdf -------------------------------------------------------------------------------- /2017-january/assignments/Assignment11-backtracking thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2017-january/assignments/Assignment11-backtracking thinking.pdf -------------------------------------------------------------------------------- /2017-january/assignments/Assignment2-basic thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2017-january/assignments/Assignment2-basic thinking.pdf -------------------------------------------------------------------------------- /2017-january/assignments/Assignment3-linked list problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2017-january/assignments/Assignment3-linked list problems.pdf -------------------------------------------------------------------------------- /2017-january/assignments/Assignment4-set, map.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2017-january/assignments/Assignment4-set, map.pdf -------------------------------------------------------------------------------- /2017-january/assignments/Assignment5-recursive thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2017-january/assignments/Assignment5-recursive thinking.pdf -------------------------------------------------------------------------------- /2017-january/assignments/Assignment6-tree problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2017-january/assignments/Assignment6-tree problems.pdf -------------------------------------------------------------------------------- /2017-january/assignments/Assignment7-bst problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2017-january/assignments/Assignment7-bst problems.pdf -------------------------------------------------------------------------------- /2017-january/assignments/Assignment8-dp thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2017-january/assignments/Assignment8-dp thinking.pdf -------------------------------------------------------------------------------- /2017-january/assignments/Assignment9-dp thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2017-january/assignments/Assignment9-dp thinking.pdf -------------------------------------------------------------------------------- /2017-may/1.basic-thinking/src/com/alg/top20/basic/New Text Document.txt: -------------------------------------------------------------------------------- 1 | 7995078494 2 | 3 | -------------------------------------------------------------------------------- /2017-may/10.tree-problems/src/com/alg/top20/trees/MyInteger.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.trees; 2 | 3 | class MyInteger { 4 | private int max; 5 | public MyInteger() { 6 | max = Integer.MIN_VALUE; 7 | } 8 | public int get() { 9 | return max; 10 | } 11 | public void set(int val) { 12 | max = val; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /2017-may/10.tree-problems/src/com/alg/top20/trees/TreeNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.trees; 2 | 3 | public class TreeNode { 4 | Integer data; 5 | TreeNode left; 6 | TreeNode right; 7 | 8 | TreeNode(Integer data) { 9 | this.data = data; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /2017-may/12.trie/src/com/alg/top20/trie/ITrieSet.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.trie; 2 | 3 | import java.util.List; 4 | 5 | public interface ITrieSet { 6 | boolean add(String word); 7 | boolean contains(String word); 8 | void display(); 9 | List autocomplete(String prefix); 10 | boolean containsRE(String pattern); 11 | boolean remove(String word); 12 | } 13 | -------------------------------------------------------------------------------- /2017-may/12.trie/src/com/alg/top20/trie/MyBoolean.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.trie; 2 | 3 | public class MyBoolean { 4 | private boolean flag; 5 | 6 | public boolean get() { 7 | return flag; 8 | } 9 | public void set(boolean flag) { 10 | this.flag = flag; 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /2017-may/16.file-problems/src/com/alg/top20/file/CircularBuffer.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.file; 2 | 3 | import java.util.LinkedList; 4 | import java.util.Queue; 5 | 6 | 7 | public class CircularBuffer { 8 | private Queue buffer; 9 | private int capacity; 10 | 11 | public CircularBuffer(int k) { 12 | capacity = k; 13 | buffer = new LinkedList(); 14 | } 15 | 16 | public void add(String line) { 17 | if(buffer.size() == capacity) { 18 | buffer.remove(); 19 | } 20 | buffer.add(line); 21 | } 22 | 23 | public String getFirst() { 24 | return buffer.peek(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /2017-may/17.disjoint-set/src/com/alg/top20/dset/IDisjointSet.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.dset; 2 | 3 | public interface IDisjointSet { 4 | void union(int x, int y); 5 | int find(int x); 6 | int size(); 7 | void display(); 8 | } 9 | -------------------------------------------------------------------------------- /2017-may/2.programming-styles/src/com/alg/top20/oostyle/ArrayList.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.oostyle; 2 | 3 | public class ArrayList { 4 | int[] array; 5 | int size; 6 | 7 | ArrayList() { 8 | 9 | } 10 | void add(int e) { 11 | 12 | } 13 | void display() { 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /2017-may/2.programming-styles/src/com/alg/top20/oostyle/Driver.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.oostyle; 2 | 3 | public class Driver { 4 | 5 | public static void main(String[] args) { 6 | ArrayList al = new ArrayList(); 7 | al.add(10); 8 | al.display(); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /2017-may/2.programming-styles/src/com/alg/top20/oostyle/LinkedList.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.oostyle; 2 | 3 | class ListNode { 4 | int data; 5 | ListNode next; 6 | 7 | ListNode() { 8 | 9 | } 10 | } 11 | public class LinkedList { 12 | ListNode first; 13 | ListNode last; 14 | int size; 15 | 16 | LinkedList() { 17 | 18 | } 19 | 20 | void add(int e) { 21 | 22 | } 23 | void display() { 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /2017-may/2.programming-styles/src/com/alg/top20/oostyle1/ArrayList.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.oostyle1; 2 | 3 | public class ArrayList { 4 | int[] array; 5 | int size; 6 | 7 | //init method 8 | ArrayList() { 9 | 10 | } 11 | //add(ArrayList this, int e) 12 | void add(int e) { 13 | 14 | } 15 | void display() { 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /2017-may/2.programming-styles/src/com/alg/top20/oostyle1/Driver.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.oostyle1; 2 | 3 | public class Driver { 4 | 5 | public static void main(String[] args) { 6 | //al is reference to ArrayList type object 7 | ArrayList al = new ArrayList(); 8 | al.add(10); 9 | al.display(); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /2017-may/2.programming-styles/src/com/alg/top20/oostyle1/LinkedList.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.oostyle1; 2 | 3 | class ListNode { 4 | int data; 5 | ListNode next; 6 | 7 | ListNode() { 8 | 9 | } 10 | } 11 | public class LinkedList { 12 | ListNode first; 13 | ListNode last; 14 | int size; 15 | 16 | LinkedList() { 17 | 18 | } 19 | 20 | void add(int e) { 21 | 22 | } 23 | void display() { 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /2017-may/2.programming-styles/src/com/alg/top20/oostyle2/ArrayList.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.oostyle2; 2 | 3 | public class ArrayList { 4 | private int[] array; 5 | private int size; 6 | 7 | //init method 8 | public ArrayList() { 9 | 10 | } 11 | //add(ArrayList this, int e) 12 | public void add(int e) { 13 | 14 | } 15 | public void display() { 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /2017-may/2.programming-styles/src/com/alg/top20/oostyle2/Driver.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.oostyle2; 2 | 3 | public class Driver { 4 | 5 | public static void main(String[] args) { 6 | //al is reference to ArrayList type object 7 | ArrayList al = new ArrayList(); 8 | al.add(10); 9 | al.display(); 10 | 11 | LinkedList ll = new LinkedList(); 12 | ll.add(20); 13 | ll.display(); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /2017-may/2.programming-styles/src/com/alg/top20/oostyle2/LinkedList.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.oostyle2; 2 | 3 | class ListNode { 4 | int data; 5 | ListNode next; 6 | 7 | ListNode() { 8 | 9 | } 10 | } 11 | public class LinkedList { 12 | private ListNode first; 13 | private ListNode last; 14 | private int size; 15 | 16 | public LinkedList() { 17 | 18 | } 19 | 20 | public void add(int e) { 21 | 22 | } 23 | public void display() { 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /2017-may/2.programming-styles/src/com/alg/top20/oostyle3/ArrayList.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.oostyle3; 2 | 3 | public class ArrayList implements List { 4 | private int[] array; 5 | private int size; 6 | 7 | //init method 8 | public ArrayList() { 9 | 10 | } 11 | //add(ArrayList this, int e) 12 | public void add(int e) { 13 | 14 | } 15 | public void display() { 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /2017-may/2.programming-styles/src/com/alg/top20/oostyle3/Driver.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.oostyle3; 2 | 3 | public class Driver { 4 | 5 | public static void main(String[] args) { 6 | //l is reference to ? type object 7 | //List l = new List(); 8 | 9 | //l refers to arraylist object type 10 | List l = new ArrayList(); 11 | //add method call binds to arraylist add implmentation 12 | l.add(10); 13 | l.display(); 14 | 15 | //l refers to linkedlist object type 16 | l = new LinkedList(); 17 | //add method call binds to linkedlist add implmentation 18 | l.add(20); 19 | l.display(); 20 | 21 | //l = new String(); 22 | 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /2017-may/2.programming-styles/src/com/alg/top20/oostyle3/LinkedList.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.oostyle3; 2 | 3 | class ListNode { 4 | int data; 5 | ListNode next; 6 | 7 | ListNode() { 8 | 9 | } 10 | } 11 | public class LinkedList implements List { 12 | private ListNode first; 13 | private ListNode last; 14 | private int size; 15 | 16 | public LinkedList() { 17 | 18 | } 19 | 20 | public void add(int e) { 21 | 22 | } 23 | public void display() { 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /2017-may/2.programming-styles/src/com/alg/top20/oostyle3/List.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.oostyle3; 2 | 3 | public interface List { 4 | void add(int e); 5 | void display(); 6 | } 7 | -------------------------------------------------------------------------------- /2017-may/2.programming-styles/src/com/alg/top20/oostyle4/ArrayList.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.oostyle4; 2 | 3 | public class ArrayList implements List { 4 | private int[] array; 5 | private int size; 6 | 7 | //init method 8 | public ArrayList() { 9 | 10 | } 11 | //add(ArrayList this, int e) 12 | public void add(int e) { 13 | 14 | } 15 | public void display() { 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /2017-may/2.programming-styles/src/com/alg/top20/oostyle4/Driver.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.oostyle4; 2 | 3 | public class Driver { 4 | 5 | public static void testList(List l) { 6 | l.add(10); 7 | l.display(); 8 | } 9 | public static void main(String[] args) { 10 | //read conf file and create an object of the type specified in conf file 11 | //use reflection utilities 12 | //testList(); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /2017-may/2.programming-styles/src/com/alg/top20/oostyle4/LinkedList.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.oostyle4; 2 | 3 | class ListNode { 4 | int data; 5 | ListNode next; 6 | 7 | ListNode() { 8 | 9 | } 10 | } 11 | public class LinkedList implements List { 12 | private ListNode first; 13 | private ListNode last; 14 | private int size; 15 | 16 | public LinkedList() { 17 | 18 | } 19 | 20 | public void add(int e) { 21 | 22 | } 23 | public void display() { 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /2017-may/2.programming-styles/src/com/alg/top20/oostyle4/List.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.oostyle4; 2 | 3 | //the result of abstracting list is LIST API 4 | public interface List { 5 | void add(int e); 6 | void display(); 7 | } 8 | -------------------------------------------------------------------------------- /2017-may/2.programming-styles/src/com/alg/top20/procedural/ArrayList.java: -------------------------------------------------------------------------------- 1 | struct arraylist { 2 | int* array; 3 | int size; 4 | }; 5 | 6 | struct arraylist* init() { 7 | al = malloc(sizeof(struct arraylist)); 8 | al->array = malloc(10 * sizeof(int)); 9 | al->size = 0; 10 | } 11 | void add(struct arraylist* al, int e) { 12 | 13 | } 14 | 15 | void display(struct arraylist* al) { 16 | 17 | } 18 | 19 | int main() { 20 | struct arraylist* al; 21 | al = init(); 22 | add(al, 10); 23 | add(al, 20); 24 | display(al); 25 | return 0; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /2017-may/2.programming-styles/src/com/alg/top20/procedural/Driver.java: -------------------------------------------------------------------------------- 1 | #include "ArrayList.java" 2 | int main() { 3 | struct arraylist * al; 4 | al = init(); 5 | add(al, 10); 6 | display(al); 7 | } 8 | -------------------------------------------------------------------------------- /2017-may/3.list-oostyle/src/com/alg/top20/list/Driver.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.list; 2 | 3 | import java.util.Random; 4 | 5 | public class Driver { 6 | 7 | public static void testList(List l) { 8 | Random r = new Random(); 9 | for(int i = 0; i < 40; ++i) 10 | l.add(r.nextInt(100) + 1); 11 | l.display(); 12 | } 13 | public static void main(String[] args) { 14 | testList(new ArrayList()); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /2017-may/3.list-oostyle/src/com/alg/top20/list/List.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.list; 2 | 3 | //the result of abstracting list is LIST API 4 | public interface List { 5 | void add(Integer e); 6 | void display(); 7 | Integer get(int ind); 8 | } 9 | -------------------------------------------------------------------------------- /2017-may/4.linkedlist-problems/src/com/alg/top20/linkedlist/ListNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.linkedlist; 2 | class ListNode { 3 | Integer data; 4 | ListNode next; 5 | 6 | ListNode() { 7 | 8 | } 9 | ListNode(Integer data) { 10 | this.data = data; 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /2017-may/5.set-oostyle/src/com/alg/top20/set/ISet.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.set; 2 | 3 | public interface ISet { 4 | boolean add(Integer e); 5 | boolean contains(Integer e); 6 | boolean remove(Integer e); 7 | int size(); 8 | void display(); 9 | } 10 | -------------------------------------------------------------------------------- /2017-may/5.set-oostyle/src/com/alg/top20/set/TestSet.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.set; 2 | 3 | import java.util.Random; 4 | 5 | public class TestSet { 6 | 7 | public static void testSet(ISet set, int n) { 8 | Random r = new Random(); 9 | for(int i = 0; i < n; ++i) { 10 | int tmp = r.nextInt(n)+1; 11 | //System.out.println(tmp); 12 | set.add(tmp); 13 | } 14 | System.out.println(set.size()); 15 | set.display(); 16 | } 17 | public static void main(String[] args) { 18 | int n = Integer.parseInt(args[0]); 19 | testSet(new HashSet(), n); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /2017-may/6.cache-oostyle/src/com/alg/top20/cache/ICache.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.cache; 2 | 3 | public interface ICache { 4 | Integer get(String key); 5 | void put(String key, Integer value); 6 | void display(); 7 | } 8 | -------------------------------------------------------------------------------- /2017-may/7.recursive-thinking/src/com/alg/top20/recursion/TowersOfHonai.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.recursion; 2 | 3 | public class TowersOfHonai { 4 | 5 | public static void honai1(int n, char src, char aux, char target) { 6 | if(n == 1) { 7 | System.out.println(src + "->" + target); 8 | return; 9 | } 10 | honai1(n-1, src,target,aux); 11 | System.out.println(src + "->" + target); 12 | honai1(n-1, aux,src,target); 13 | } 14 | 15 | public static void main(String[] args) { 16 | int n = Integer.parseInt(args[0]); 17 | honai1(n, 'A', 'B', 'C'); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /2017-may/8.dynamic-programming/src/com/alg/top20/dp/MyInteger.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | class MyInteger { 4 | private int max; 5 | public MyInteger() { 6 | max = Integer.MIN_VALUE; 7 | } 8 | public int get() { 9 | return max; 10 | } 11 | public void set(int val) { 12 | max = val; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /2017-may/9.random-generator/src/com/alg/top20/random/Random1.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.random; 2 | import java.util.Random; 3 | 4 | 5 | public class Random1 { 6 | 7 | public static void getRandomJava(int n) { 8 | Random r = new Random(100); 9 | for(int i = 0; i < 10; ++i) 10 | System.out.println(r.nextInt(n)); 11 | } 12 | 13 | public static void getRandom1(int n) { 14 | for(int i = 0; i < 10; ++i) 15 | System.out.println((int)(System.currentTimeMillis() % n)); 16 | } 17 | 18 | public static void main(String[] args) { 19 | int n = Integer.parseInt(args[0]); 20 | getRandomJava(n); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /2017-may/assignments/Assignment1-basic thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2017-may/assignments/Assignment1-basic thinking.pdf -------------------------------------------------------------------------------- /2017-may/assignments/Assignment2-basic thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2017-may/assignments/Assignment2-basic thinking.pdf -------------------------------------------------------------------------------- /2017-may/assignments/Assignment3-linked list problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2017-may/assignments/Assignment3-linked list problems.pdf -------------------------------------------------------------------------------- /2017-may/assignments/Assignment4-set, map.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2017-may/assignments/Assignment4-set, map.pdf -------------------------------------------------------------------------------- /2017-may/c++ tutorial/list/STLlist1.cpp: -------------------------------------------------------------------------------- 1 | //Illustration of STL list operations 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main() { 7 | list l; 8 | l.push_back(30); 9 | l.push_back(20); 10 | l.push_back(10); 11 | l.push_back(40); 12 | l.push_front(15); 13 | l.pop_back(); 14 | l.insert(l.begin(),60); 15 | list::iterator i; 16 | for(i = l.begin(); i != l.end(); i++) 17 | cout<<*i< 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main() { 8 | map m; 9 | m.insert(make_pair(10,"abc")); 10 | m.insert(make_pair(20,"xyz")); 11 | m.insert(make_pair(20,"pqr")); 12 | m.insert(make_pair(25,"def")); 13 | map::iterator i; 14 | for(i = m.begin();i!=m.end();i++) 15 | cout<first<<" "<second< 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main() { 7 | map m; 8 | m.insert(make_pair(10,"abc")); 9 | m.insert(make_pair(20,"xyz")); 10 | m.insert(make_pair(15,"pqr")); 11 | m.insert(make_pair(25,"def")); 12 | map::iterator res = m.find(20); 13 | if(res==m.end()) cout<<"Element mapping not found"<second< 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | void display(map m) { 8 | map::iterator i = m.begin(); 9 | for(;i!=m.end();i++) 10 | cout<first<<" "<second< m; 15 | m.insert(make_pair(10,"abc")); 16 | m.insert(make_pair(20,"xyz")); 17 | m.insert(make_pair(15,"pqr")); 18 | m.insert(make_pair(25,"def")); 19 | display(m); 20 | m.erase(20); 21 | display(m); 22 | getchar(); 23 | } 24 | 25 | 26 | -------------------------------------------------------------------------------- /2017-may/c++ tutorial/map-multimap/STLmap4.cpp: -------------------------------------------------------------------------------- 1 | //Illustration of map operations 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | void display(map m) { 8 | map::iterator i = m.begin(); 9 | for(;i!=m.end();i++) 10 | cout<first<<" "<second< m; 15 | m[10]="abc"; 16 | m[25]="xyz"; 17 | m[20]="def"; 18 | m[10]="pqr"; 19 | m[11]="abc"; 20 | display(m); 21 | m.erase(20); 22 | display(m); 23 | getchar(); 24 | } 25 | 26 | 27 | -------------------------------------------------------------------------------- /2017-may/c++ tutorial/map-multimap/STLmaptmp.cpp: -------------------------------------------------------------------------------- 1 | //Illustration of map operations 2 | #include 3 | #include //it contains both map and multimap 4 | #include 5 | using namespace std; 6 | 7 | int main() { 8 | multimap m; 9 | m.insert(make_pair(10,"abc")); 10 | m.insert(make_pair(20,"xyz")); 11 | m.insert(make_pair(20,"pqr")); 12 | m.insert(make_pair(25,"def")); 13 | multimap::iterator i; 14 | for(i = m.begin();i!=m.end();i++) 15 | cout<first<<" "<second< 2 | using namespace std; 3 | 4 | int main() { 5 | pair p1(10,20); 6 | cout< p2 = make_pair(100, 200); 8 | cout< 2 | #include 3 | using namespace std; 4 | int main() { 5 | priority_queue pq1; 6 | pq1.push(10); 7 | pq1.push(20); 8 | pq1.push(15); 9 | pq1.push(25); 10 | while(!pq1.empty()) { 11 | cout< 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | queue q; 7 | for(long i = 1; i<=10; i++) 8 | q.push(i); 9 | cout<<"queue size:"< 3 | #include 4 | using namespace std; 5 | 6 | int main() { 7 | multiset s; 8 | s.insert(10); 9 | s.insert(20); 10 | s.insert(30); 11 | s.insert(10); 12 | s.insert(20); 13 | s.insert(17); 14 | multiset::iterator i; 15 | for(i=s.begin(); i!=s.end(); ++i) 16 | cout<<*i< 3 | #include 4 | using namespace std; 5 | 6 | int main() { 7 | multiset s; 8 | s.insert(10); 9 | s.insert(20); 10 | s.insert(25); 11 | s.insert(20); 12 | s.insert(15); 13 | s.insert(18); 14 | s.insert(10); 15 | s.insert(15); 16 | s.insert(17); 17 | multiset::iterator start = s.lower_bound(10); 18 | multiset::iterator end = s.upper_bound(20); 19 | for(; start!=end; ++start) 20 | cout<<*start< 3 | #include 4 | using namespace std; 5 | int main() { 6 | stack s; 7 | for(int i = 1; i<=10; i++) 8 | s.push(i); 9 | cout<<"stack size:"< 3 | #include 4 | using namespace std; 5 | int main() { 6 | vector v1; 7 | v1.push_back(30); 8 | v1.push_back(20); 9 | v1.push_back(10); 10 | v1.push_back(40); 11 | cout<<"vector size:"<::iterator i; 15 | for(i=v1.begin(); i!=v1.end(); i++) 16 | cout<<*i<<" "; 17 | cout< 3 | #include 4 | using namespace std; 5 | 6 | int main() { 7 | vector v1; 8 | v1.push_back(30); 9 | v1.push_back(20); 10 | v1.push_back(10); 11 | v1.push_back(40); 12 | vector::iterator i; 13 | for(i = v1.begin(); i!=v1.end();i++) 14 | cout<<*i< nums[r]) return r+1; 8 | while (l < r) { 9 | int m = (l + r) / 2; 10 | if (nums[m] == target) 11 | return m; 12 | if (target < nums[m]) 13 | r = m; 14 | else 15 | l = m + 1; 16 | } 17 | return l; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /2017-september/10.combinatorial problems/src/com/alg/top20/combinatorial/MyInteger.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.combinatorial; 2 | 3 | 4 | public class MyInteger { 5 | int value; 6 | public MyInteger(int value) { 7 | this.value = value; 8 | } 9 | public int get() { 10 | return value; 11 | } 12 | public void set(int value) { 13 | this.value = value; 14 | } 15 | public void incr(int i) { 16 | value += i; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /2017-september/15.bitwise tricks/src/com/alg/top20/bittricks/AllSubsets.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bittricks; 2 | 3 | public class AllSubsets { 4 | 5 | public static void allSubsets(int[] in) { 6 | int n = in.length; 7 | int limit = 1 << n; 8 | for(int i = 0; i < limit; ++i) { 9 | for(int j = 1; j <= n; ++j) { 10 | if( (i & (1<>> 1; 13 | } 14 | System.out.println(); 15 | } 16 | 17 | public static void main(String[] args) { 18 | int n = Integer.parseInt(args[0]); 19 | display(n); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /2017-september/15.bitwise tricks/src/com/alg/top20/bittricks/EvenOddCheck.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bittricks; 2 | 3 | public class EvenOddCheck { 4 | 5 | public static boolean isOdd(int n) { 6 | return (n & 1) != 0; 7 | } 8 | public static void main(String[] args) { 9 | // TODO Auto-generated method stub 10 | 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /2017-september/15.bitwise tricks/src/com/alg/top20/bittricks/HigherLowerMultiples.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bittricks; 2 | 3 | public class HigherLowerMultiples { 4 | 5 | public static int nextHighestMult8(int n) { 6 | return (n+7) & ~7; 7 | } 8 | 9 | public static int prevLowestMult8(int n) { 10 | return n & ~7; 11 | } 12 | public static void main(String[] args) { 13 | int n = Integer.parseInt(args[0]); 14 | System.out.println(prevLowestMult8(n)); 15 | System.out.println(nextHighestMult8(n)); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /2017-september/15.bitwise tricks/src/com/alg/top20/bittricks/IPAddress.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bittricks; 2 | 3 | public class IPAddress { 4 | 5 | public static int getNetworkId(int n) { 6 | int mask = 0xFF000000; 7 | return (n & mask) >>> 24; 8 | } 9 | public static int getHostId(int n) { 10 | int mask = 0xFFFFFF; 11 | return n & mask; 12 | } 13 | 14 | public static void main(String[] args) { 15 | int n = Integer.parseInt(args[0]); 16 | BitWiseUtilities.display(n); 17 | System.out.println(getNetworkId(n)); 18 | System.out.println(getHostId(n)); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /2017-september/15.bitwise tricks/src/com/alg/top20/bittricks/IsPowerOf2.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bittricks; 2 | 3 | public class IsPowerOf2 { 4 | 5 | public static boolean isPowerOf2(int n) { 6 | return (n & (n-1)) == 0; 7 | } 8 | public static void main(String[] args) { 9 | int n = Integer.parseInt(args[0]); 10 | BitWiseUtilities.display(n); 11 | System.out.println(isPowerOf2(n)); 12 | 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /2017-september/2.datastructure design1/src/com/alg/top20/set/ISet.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.set; 2 | 3 | public interface ISet { 4 | boolean add(Integer e); 5 | boolean contains(Integer e); 6 | boolean remove(Integer e); 7 | int size(); 8 | void display(); 9 | } 10 | -------------------------------------------------------------------------------- /2017-september/2.datastructure design1/src/com/alg/top20/set/TestSet.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.set; 2 | 3 | import java.util.Random; 4 | 5 | public class TestSet { 6 | 7 | public static void testSet(ISet set, int n) { 8 | Random r = new Random(100); 9 | for(int i = 0; i < n; ++i) { 10 | int tmp = r.nextInt(n)+1; 11 | //System.out.println(tmp); 12 | set.add(tmp); 13 | //set.display(); 14 | //System.out.println(); 15 | } 16 | System.out.println(set.size()); 17 | set.display(); 18 | } 19 | public static void main(String[] args) { 20 | int n = Integer.parseInt(args[0]); 21 | testSet(new HashSet(), n); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /2017-september/3.datastructure design2/src/com/alg/top20/dsdesign/cache/DListNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.dsdesign.cache; 2 | 3 | public class DListNode { 4 | DListNode prev, next; 5 | String key; 6 | Integer value; 7 | 8 | 9 | public DListNode() { 10 | prev = next = this; 11 | } 12 | public DListNode(String key, Integer value) { 13 | super(); 14 | this.key = key; 15 | this.value = value; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /2017-september/3.datastructure design2/src/com/alg/top20/dsdesign/cache/ICache.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.dsdesign.cache; 2 | 3 | public interface ICache { 4 | Integer get(String key); 5 | void add(String key, Integer value); 6 | void display(); 7 | } 8 | 9 | -------------------------------------------------------------------------------- /2017-september/3.datastructure design2/src/com/alg/top20/dsdesign/queue/TestQueue.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.dsdesign.queue; 2 | 3 | import java.util.Random; 4 | 5 | public class TestQueue { 6 | 7 | public static void main(String[] args) { 8 | Queue q = new Queue(); 9 | int n = Integer.parseInt(args[0]); 10 | Random r = new Random(100); 11 | for(int i = 0; i < n; ++i) { 12 | q.enqueue(r.nextInt(n)); 13 | q.display(); 14 | } 15 | q.dequeue(); 16 | q.display(); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /2017-september/3.datastructure design2/src/com/alg/top20/dsdesign/superstack/TestSuperStack.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.dsdesign.superstack; 2 | 3 | import java.util.Random; 4 | 5 | public class TestSuperStack { 6 | 7 | public static void main(String[] args) { 8 | SuperStack ss = new SuperStack(); 9 | int n = Integer.parseInt(args[0]); 10 | Random r = new Random(100); 11 | for(int i = 0; i < n; ++i) { 12 | ss.push(r.nextInt(n)); 13 | ss.display(); 14 | } 15 | System.out.println(ss.findMin()); 16 | ss.pop(); 17 | ss.display(); 18 | System.out.println(ss.findMin()); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /2017-september/4.linked list problems/src/com/alg/top20/ll/LinkedListUtils.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.ll; 2 | 3 | public class LinkedListUtils { 4 | public static ListNode createList(int n) { 5 | ListNode head = new ListNode(); 6 | for(int i = 0; i < n; ++i) { 7 | ListNode tmp = new ListNode(); 8 | tmp.next = head.next; 9 | head.next = tmp; 10 | } 11 | return head; 12 | } 13 | public static void display(ListNode head) { 14 | for(ListNode current = head; current != null; current = current.next) 15 | System.out.print(current + "->"); 16 | System.out.println(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /2017-september/4.linked list problems/src/com/alg/top20/ll/ListNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.ll; 2 | 3 | public class ListNode { 4 | public ListNode next; 5 | public Integer data; 6 | 7 | 8 | public ListNode() { 9 | next = null; 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /2017-september/4.linked list problems/src/com/alg/top20/ll/detectcycle/ListNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.ll.detectcycle; 2 | 3 | public class ListNode { 4 | ListNode next; 5 | Integer data; 6 | 7 | 8 | public ListNode() { 9 | next = null; 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /2017-september/4.linked list problems/src/com/alg/top20/ll/kthnodefromend/ListNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.ll.kthnodefromend; 2 | 3 | public class ListNode { 4 | ListNode next; 5 | Integer data; 6 | 7 | 8 | public ListNode() { 9 | next = null; 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /2017-september/4.linked list problems/src/com/alg/top20/ll/lca/ListNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.ll.lca; 2 | 3 | public class ListNode { 4 | ListNode next; 5 | Integer data; 6 | 7 | 8 | public ListNode() { 9 | next = null; 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /2017-september/4.linked list problems/src/com/alg/top20/ll/loopnode/ListNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.ll.loopnode; 2 | 3 | public class ListNode { 4 | ListNode next; 5 | Integer data; 6 | 7 | 8 | public ListNode() { 9 | next = null; 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /2017-september/4.linked list problems/src/com/alg/top20/ll/random/ListNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.ll.random; 2 | 3 | public class ListNode { 4 | ListNode next; 5 | Integer data; 6 | 7 | 8 | public ListNode() { 9 | next = null; 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /2017-september/4.linked list problems/src/com/alg/top20/ll/reversal/ListNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.ll.reversal; 2 | 3 | public class ListNode { 4 | ListNode next; 5 | Integer data; 6 | 7 | 8 | public ListNode() { 9 | next = null; 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /2017-september/5.binary tree problems/src/com/alg/top20/trees/MyInteger.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.trees; 2 | 3 | public class MyInteger { 4 | int value; 5 | public MyInteger(int value) { 6 | this.value = value; 7 | } 8 | public int get() { 9 | return value; 10 | } 11 | public void set(int value) { 12 | this.value = value; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /2017-september/5.binary tree problems/src/com/alg/top20/trees/TreeNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.trees; 2 | 3 | public class TreeNode { 4 | public Integer data; 5 | public TreeNode left; 6 | public TreeNode right; 7 | 8 | public TreeNode(int data) { 9 | this.data = data; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /2017-september/6.bst problems/src/com/alg/top20/bst/MyInteger.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bst; 2 | 3 | public class MyInteger { 4 | int value; 5 | public MyInteger(int value) { 6 | this.value = value; 7 | } 8 | public int get() { 9 | return value; 10 | } 11 | public void set(int value) { 12 | this.value = value; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /2017-september/6.bst problems/src/com/alg/top20/bst/TreeNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bst; 2 | 3 | public class TreeNode { 4 | public Integer data; 5 | public TreeNode left; 6 | public TreeNode right; 7 | public int ls_size; 8 | 9 | public TreeNode(int data) { 10 | this.data = data; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /2017-september/6.bst problems/src/com/alg/top20/bst/bstmin/BSTMin.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bst.bstmin; 2 | 3 | import com.alg.top20.bst.BSTUtils; 4 | import com.alg.top20.bst.TreeNode; 5 | 6 | public class BSTMin { 7 | 8 | //TC:O(h) 9 | //SC:O(1) 10 | public static Integer findMin(TreeNode root) { 11 | if(root == null) return null; 12 | while(root.left != null) 13 | root = root.left; 14 | return root.data; 15 | } 16 | public static void main(String[] args) { 17 | int n = Integer.parseInt(args[0]); 18 | TreeNode root = BSTUtils.createBBST(n); 19 | BSTUtils.display1(root); 20 | System.out.println(findMin(root)); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /2017-september/6.bst problems/src/com/alg/top20/bst/serde/SerDe.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bst.serde; 2 | 3 | import com.alg.top20.bst.TreeNode; 4 | 5 | public class SerDe { 6 | 7 | //TC:O(n) 8 | //SC:O(n) -> O(1) 9 | public static void serialize(int[] pre) { 10 | 11 | } 12 | //TC:O(n log n) 13 | //SC:O(n) ??? 14 | public static TreeNode deserialize(int[] pre) { 15 | return null; 16 | } 17 | public static void main(String[] args) { 18 | // TODO Auto-generated method stub 19 | 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /2017-september/7.datastructure design3/src/com/alg/top20/trie/ITrie.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.trie; 2 | 3 | import java.util.List; 4 | 5 | public interface ITrie { 6 | boolean add(String word); 7 | boolean remove(String word); 8 | boolean contains(String word); 9 | List autocomplete(String prefix); 10 | int findLongestPrefix(String s); 11 | void displayAll(); 12 | void print(); 13 | } 14 | -------------------------------------------------------------------------------- /2017-september/8.dynamic programming/src/com/alg/top20/dp/twod/MyInteger.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.dp.twod; 2 | 3 | public class MyInteger { 4 | int value; 5 | public MyInteger(int value) { 6 | this.value = value; 7 | } 8 | public int get() { 9 | return value; 10 | } 11 | public void set(int value) { 12 | this.value = value; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /2017-september/assignments/1.basic problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2017-september/assignments/1.basic problems.pdf -------------------------------------------------------------------------------- /2017-september/assignments/10.backtracking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2017-september/assignments/10.backtracking.pdf -------------------------------------------------------------------------------- /2017-september/assignments/2.basic problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2017-september/assignments/2.basic problems.pdf -------------------------------------------------------------------------------- /2017-september/assignments/3.basic problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2017-september/assignments/3.basic problems.pdf -------------------------------------------------------------------------------- /2017-september/assignments/4.binary search problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2017-september/assignments/4.binary search problems.pdf -------------------------------------------------------------------------------- /2017-september/assignments/5.linked list problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2017-september/assignments/5.linked list problems.pdf -------------------------------------------------------------------------------- /2017-september/assignments/6.datastructure design problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2017-september/assignments/6.datastructure design problems.pdf -------------------------------------------------------------------------------- /2017-september/assignments/7.binary tree problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2017-september/assignments/7.binary tree problems.pdf -------------------------------------------------------------------------------- /2017-september/assignments/8.bst problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2017-september/assignments/8.bst problems.pdf -------------------------------------------------------------------------------- /2017-september/assignments/9.dp problems-1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2017-september/assignments/9.dp problems-1.pdf -------------------------------------------------------------------------------- /2018-feb/10-dp thinking(2d)/src/com/alg/top20/recursion/MyInteger.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.recursion; 2 | 3 | public class MyInteger { 4 | private int value; 5 | public MyInteger(int value) { 6 | this.value = value; 7 | } 8 | public int get() { 9 | return value; 10 | } 11 | public void set(int value) { 12 | this.value = value; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /2018-feb/11.complete search/src/com/alg/top20/cs/AllPartitions.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.cs; 2 | 3 | public class AllPartitions { 4 | 5 | public static void allPartitions1(String in) { 6 | auxPartitions1(0, in, ""); 7 | } 8 | private static void auxPartitions1(int start, String in, String res) { 9 | if(start == in.length()) 10 | System.out.println(res); 11 | for(int i = start; i < in.length(); ++i) { 12 | String tmp = in.substring(start, i+1); 13 | auxPartitions1(i+1, in, res+"+"+tmp); 14 | } 15 | } 16 | public static void main(String[] args) { 17 | allPartitions1(args[0]); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /2018-feb/13.ds-based-thinking2/src/com/alg/top20/ds/trie/ITrie.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.ds.trie; 2 | 3 | import java.util.List; 4 | 5 | public interface ITrie { 6 | boolean add(String key); 7 | boolean contains(String key); 8 | List autocomplete(String prefix); 9 | void display(); 10 | } 11 | -------------------------------------------------------------------------------- /2018-feb/13.ds-based-thinking2/src/com/alg/top20/ds/trie/TSTNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.ds.trie; 2 | 3 | public class TSTNode { 4 | char data; 5 | boolean isword; 6 | TSTNode left; 7 | TSTNode middle; 8 | TSTNode right; 9 | 10 | public TSTNode(char data) { 11 | this.data = data; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /2018-feb/13.ds-based-thinking2/src/com/alg/top20/ds/trie/TestTrie.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.ds.trie; 2 | 3 | public class TestTrie { 4 | 5 | public static void main(String[] args) { 6 | String[] words = 7 | {"pqr", "abc", "ab", "axy", "axz" ,"xyz", "xab", "abcz", "aaa"}; 8 | ITrie trie = new TSTTrie(); 9 | for(int i = 0; i < words.length; ++i) 10 | trie.add(words[i]); 11 | trie.display(); 12 | System.out.println(trie.autocomplete("a")); 13 | System.out.println(trie.autocomplete("ab")); 14 | System.out.println(trie.autocomplete("x")); 15 | System.out.println(trie.autocomplete("")); 16 | 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /2018-feb/2.divide-and-prune/src/com/alg/top20/divideprune/CountOnes.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.divideprune; 2 | 3 | 4 | public class CountOnes { 5 | 6 | public static int countOnes(int[] in) { 7 | int left = 0, right = in.length - 1; 8 | if (in.length == 0 || 9 | in[left] == 0) 10 | return 0; 11 | while (left < right) { 12 | int mid = (int) Math.ceil(left + (right - left) >>> 1); 13 | if (in[mid] == 1) 14 | left = mid; 15 | else 16 | right = mid - 1; 17 | } 18 | return right + 1; 19 | } 20 | 21 | public static void main(String[] args) { 22 | // TODO Auto-generated method stub 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /2018-feb/2.divide-and-prune/src/com/alg/top20/divideprune/MinInRotatedSortedArray.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.divideprune; 2 | 3 | 4 | public class MinInRotatedSortedArray { 5 | 6 | public static int findMin(int[] in) { 7 | int left = 0, right = in.length - 1; 8 | 9 | while (left < right) { 10 | int mid = left + (right - left) >>> 1; 11 | if (in[mid] > in[right]) 12 | left = mid + 1; 13 | else 14 | right = mid; 15 | } 16 | return in[right]; 17 | } 18 | public static void main(String[] args) { 19 | // TODO Auto-generated method stub 20 | 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /2018-feb/3.ds-based-thinking1/src/com/alg/top20/ds/stack/Test.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.ds.stack; 2 | 3 | public class Test { 4 | 5 | //"1234" 6 | public static void main(String[] args) { 7 | /* String s = args[0]; 8 | int result = 0; 9 | for(int i = 0; i < s.length(); ++i) { 10 | result = result * 10 + (int)(s.charAt(i)-'0'); 11 | } 12 | System.out.println(result);*/ 13 | 14 | String s = "12+3/4+(1-2)*7/4"; 15 | String[] tokens = s.split("[+*/()-]"); 16 | for(String token:tokens) 17 | System.out.println(token); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /2018-feb/6.linked-list problems/src/com/alg/top20/ll/ListNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.ll; 2 | 3 | public class ListNode { 4 | int val; 5 | public ListNode next; 6 | 7 | public ListNode() { 8 | 9 | } 10 | public ListNode(int x) { 11 | val = x; 12 | next = null; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /2018-feb/6.linked-list problems/src/com/alg/top20/ll/cache/DListNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.ll.cache; 2 | 3 | public class DListNode { 4 | String key; 5 | Integer value; 6 | DListNode prev; 7 | DListNode next; 8 | 9 | public DListNode() { 10 | prev = next = this; 11 | } 12 | 13 | public DListNode(String key, Integer value) { 14 | this.key = key; 15 | this.value = value; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /2018-feb/6.linked-list problems/src/com/alg/top20/ll/cache/ICache.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.ll.cache; 2 | 3 | public interface ICache { 4 | Integer get(String key); 5 | void put(String key, Integer value); 6 | void display(); 7 | } 8 | -------------------------------------------------------------------------------- /2018-feb/6.linked-list problems/src/com/alg/top20/ll/random/RandomNode2.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.ll.random; 2 | 3 | import java.util.Random; 4 | 5 | import com.alg.top20.ll.ListNode; 6 | 7 | public class RandomNode2 { 8 | public RandomNode2() { 9 | 10 | } 11 | public ListNode getRandom(ListNode head) { 12 | ListNode res = head; 13 | Random r = new Random(); 14 | for(ListNode current = head.next; current != null; current = current.next) { 15 | if(r.nextInt(2) == 0) 16 | res = current; 17 | } 18 | return res; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /2018-feb/6.linked-list problems/src/com/alg/top20/ll/random/RandomNode3.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.ll.random; 2 | 3 | import java.util.Random; 4 | 5 | import com.alg.top20.ll.ListNode; 6 | 7 | public class RandomNode3 { 8 | public RandomNode3() { 9 | 10 | } 11 | public ListNode getRandom(ListNode head) { 12 | ListNode res = head; 13 | Random r = new Random(); 14 | int n = 1; 15 | for(ListNode current = head.next; current != null; current = current.next) { 16 | ++n; 17 | if(r.nextInt(n) == 0) 18 | res = current; 19 | } 20 | return res; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /2018-feb/7.binary-tree problems/src/com/alg/top20/bt/MyInteger.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bt; 2 | 3 | public class MyInteger { 4 | private int value; 5 | public MyInteger(int value) { 6 | this.value = value; 7 | } 8 | public int get() { 9 | return value; 10 | } 11 | public void set(int value) { 12 | this.value = value; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /2018-feb/7.binary-tree problems/src/com/alg/top20/bt/TreeNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bt; 2 | 3 | public class TreeNode { 4 | public int data; 5 | public TreeNode left; 6 | public TreeNode right; 7 | 8 | public TreeNode(int data) { 9 | this.data = data; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /2018-feb/8.bst problems/src/com/alg/top20/bbst/BSTNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bbst; 2 | 3 | public class BSTNode { 4 | public int data; 5 | public BSTNode left; 6 | public BSTNode right; 7 | public int lst_size; 8 | 9 | public BSTNode(int data) { 10 | this.data = data; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /2018-feb/8.bst problems/src/com/alg/top20/bbst/MyInteger.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bbst; 2 | 3 | public class MyInteger { 4 | private int value; 5 | public MyInteger(int value) { 6 | this.value = value; 7 | } 8 | public int get() { 9 | return value; 10 | } 11 | public void set(int value) { 12 | this.value = value; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /2018-feb/8.bst problems/src/com/alg/top20/bbst/SearchBBST.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bbst; 2 | 3 | public class SearchBBST { 4 | 5 | public static boolean search(BSTNode root, int x) { 6 | while(root != null) { 7 | if(x == root.data) return true; 8 | if(x < root.data) root = root.left; 9 | else root = root.right; 10 | } 11 | return false; 12 | } 13 | public static void main(String[] args) { 14 | // TODO Auto-generated method stub 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /2018-feb/8.bst problems/src/com/alg/top20/bbst/TreeNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bbst; 2 | 3 | public class TreeNode { 4 | public int data; 5 | public TreeNode left; 6 | public TreeNode right; 7 | 8 | public TreeNode(int data) { 9 | this.data = data; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /2018-feb/assignments/1.adhoc thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-feb/assignments/1.adhoc thinking.pdf -------------------------------------------------------------------------------- /2018-feb/assignments/2.divide and prune thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-feb/assignments/2.divide and prune thinking.pdf -------------------------------------------------------------------------------- /2018-feb/assignments/3.complete search and backtracking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-feb/assignments/3.complete search and backtracking.pdf -------------------------------------------------------------------------------- /2018-feb/assignments/4.dp problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-feb/assignments/4.dp problems.pdf -------------------------------------------------------------------------------- /2018-feb/assignments/5.string problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-feb/assignments/5.string problems.pdf -------------------------------------------------------------------------------- /2018-feb/assignments/6.trie problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-feb/assignments/6.trie problems.pdf -------------------------------------------------------------------------------- /2018-feb/assignments/7.binary tree problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-feb/assignments/7.binary tree problems.pdf -------------------------------------------------------------------------------- /2018-may/18.bitwise thinking/src/com/alg/top20/bit/AllSubsets.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bit; 2 | 3 | public class AllSubsets { 4 | 5 | public static void allSubsets(String s) { 6 | int n = s.length(); 7 | for(int i = 0; i < (1 << n); ++i) { 8 | StringBuffer sb = new StringBuffer(); 9 | for(int j = 0; j < n; ++j) { 10 | if( (i & (1 << j)) != 0) 11 | sb.append(s.charAt(j)); 12 | } 13 | System.out.println(sb.toString()); 14 | } 15 | } 16 | public static void main(String[] args) { 17 | allSubsets(args[0]); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /2018-may/18.bitwise thinking/src/com/alg/top20/bit/BitUtils.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bit; 2 | 3 | public class BitUtils { 4 | 5 | public static void showBits(int n) { 6 | for(int i = 31; i >= 0; --i) { 7 | if( (n & (1 << i)) != 0) 8 | System.out.print("1"); 9 | else 10 | System.out.print("0"); 11 | } 12 | System.out.println(); 13 | } 14 | public static void main(String[] args) { 15 | // TODO Auto-generated method stub 16 | 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /2018-may/18.bitwise thinking/src/com/alg/top20/bit/BitwiseOperators.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bit; 2 | 3 | public class BitwiseOperators { 4 | 5 | public static void bitwiseOperators() { 6 | int n = 26, m = 4; 7 | BitUtils.showBits(n); 8 | BitUtils.showBits(m); 9 | n = n ^ m; 10 | BitUtils.showBits(n); 11 | } 12 | public static void main(String[] args) { 13 | bitwiseOperators(); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /2018-may/18.bitwise thinking/src/com/alg/top20/bit/HigherLowerMultiplesof8.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bit; 2 | 3 | public class HigherLowerMultiplesof8 { 4 | 5 | public static int prevLowest(int n) { 6 | return n & ~7; 7 | } 8 | 9 | public static int nextHighest1(int n) { 10 | return (n + 7) & ~7; 11 | } 12 | 13 | public static int nextHighest2(int n) { 14 | return (n | 7) + 1; 15 | } 16 | public static void main(String[] args) { 17 | int n = Integer.parseInt(args[0]); 18 | System.out.println(prevLowest(n)); 19 | System.out.println(nextHighest1(n)); 20 | System.out.println(nextHighest2(n)); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /2018-may/18.bitwise thinking/src/com/alg/top20/bit/ModuloPowerof2.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bit; 2 | 3 | public class ModuloPowerof2 { 4 | 5 | public static int solution1(int n) { 6 | return n % 8; 7 | } 8 | 9 | public static int solution2(int n) { 10 | return n & 7; 11 | } 12 | public static void main(String[] args) { 13 | int n = Integer.parseInt(args[0]); 14 | System.out.println(solution1(n)); 15 | System.out.println(solution2(n)); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /2018-may/18.bitwise thinking/src/com/alg/top20/bit/PowerOf2.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bit; 2 | 3 | public class PowerOf2 { 4 | 5 | public static boolean solution1(int n) { 6 | int nones = 0; 7 | for(int i = 31; i >= 0; --i) { 8 | if( (n & (1 << i)) != 0) 9 | ++nones; 10 | } 11 | return nones == 1; 12 | } 13 | public static boolean solution2(int n) { 14 | return (n & (n-1)) == 0; 15 | } 16 | public static void main(String[] args) { 17 | for(int i = 1; i <= 32; ++i) { 18 | BitUtils.showBits(i); 19 | System.out.println(solution2(i)); 20 | } 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /2018-may/2.divide prune/src/com/alg/top20/divideprune/CountZeores.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.divideprune; 2 | public class CountZeores { 3 | 4 | public static int countZeroes(int[] in) { 5 | int l = 0, r = in.length - 1; 6 | // bug: (l+r)/2 7 | // alternatives: l + (r-l)/2, l + (r-l)>>>1 8 | while (r - l > 1) { 9 | int m = l + (r - l) / 2; 10 | if (in[m] == 0) 11 | l = m; 12 | else 13 | r = m - 1; 14 | } 15 | if(in[r] == 0) return r+1; 16 | return l+1; 17 | } 18 | 19 | public static void main(String[] args) { 20 | // TODO Auto-generated method stub 21 | 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /2018-may/2.divide prune/src/com/alg/top20/divideprune/MinInRotatedSortedArray.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.divideprune; 2 | 3 | public class MinInRotatedSortedArray { 4 | 5 | public static int findMin1(int[] in) { 6 | int l = 0; 7 | int r = in.length - 1; 8 | while (l < r) { 9 | int m = l + (r - l) / 2; 10 | if (in[m] > in[r]) 11 | l = m + 1; 12 | else 13 | r = m; 14 | } 15 | return in[l]; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /2018-may/4.basic ds/src/com/alg/top20/orderedset/BTreeNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.set; 2 | 3 | public class BTreeNode { 4 | Integer data; 5 | int lst_size; 6 | BTreeNode left; 7 | BTreeNode right; 8 | 9 | public BTreeNode(Integer data) { 10 | this.data = data; 11 | } 12 | public BTreeNode(Integer data, BTreeNode left, BTreeNode right) { 13 | super(); 14 | this.data = data; 15 | this.left = left; 16 | this.right = right; 17 | } 18 | public BTreeNode() { 19 | } 20 | 21 | 22 | } 23 | -------------------------------------------------------------------------------- /2018-may/4.basic ds/src/com/alg/top20/orderedset/ISortedSet.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.set; 2 | 3 | public interface ISortedSet { 4 | boolean add(Integer key); 5 | boolean contains(Integer key); 6 | boolean remove(Integer key); 7 | int size(); 8 | void display(); 9 | Integer findMin(); 10 | Integer select(int k); 11 | } 12 | -------------------------------------------------------------------------------- /2018-may/4.basic ds/src/com/alg/top20/pq/src/com/alg/top20/pqueue/IPQueue.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.pqueue; 2 | 3 | public interface IPQueue { 4 | Integer findMin(); 5 | Integer removeMin(); 6 | void display(); 7 | int size(); 8 | boolean isEmpty(); 9 | void add(Integer e); 10 | } 11 | -------------------------------------------------------------------------------- /2018-may/5.composite ds/src/com/alg/top20/cache/DListNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.cache; 2 | 3 | public class DListNode { 4 | String key; 5 | Integer value; 6 | DListNode prev; 7 | DListNode next; 8 | 9 | public DListNode() { 10 | prev = next = this; 11 | } 12 | public DListNode(String key, Integer value) { 13 | this.key = key; 14 | this.value = value; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /2018-may/5.composite ds/src/com/alg/top20/cache/TestCache.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.cache; 2 | 3 | public class TestCache { 4 | 5 | 6 | public static void main(String[] args) { 7 | LinkedHashCache cache = new LinkedHashCache(3); 8 | cache.put("abc", 100); 9 | cache.display(); 10 | cache.put("def", 200); 11 | cache.display(); 12 | cache.put("xyz", 300); 13 | cache.display(); 14 | System.out.println(cache.get("abc")); 15 | cache.display(); 16 | cache.put("xab", 400); 17 | cache.display(); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /2018-may/6.recursion/src/Honai.java: -------------------------------------------------------------------------------- 1 | 2 | public class Honai { 3 | 4 | public static void honai1(int n, char src, char aux, char target) { 5 | if(n == 1) { 6 | System.out.println(src + "->" + target); 7 | return; 8 | } 9 | honai1(n-1, src, target, aux); 10 | System.out.println(src + "->" + target); 11 | honai1(n-1, aux, src, target); 12 | } 13 | public static void main(String[] args) { 14 | int n = Integer.parseInt(args[0]); 15 | honai1(n, 'A', 'B', 'C'); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /2018-may/7.linked list problems/src/com/alg/top20/ll/ListNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.ll; 2 | 3 | public class ListNode { 4 | int data; 5 | ListNode next; 6 | } 7 | -------------------------------------------------------------------------------- /2018-may/7.linked list problems/src/com/alg/top20/ll/RandomTest.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.ll; 2 | 3 | import java.util.Random; 4 | 5 | public class RandomTest { 6 | 7 | public static void simulateCoinToss(int n) { 8 | Random r = new Random(); 9 | int nh = 0, nt =0; 10 | for(int i = 1; i <= n; ++i) { 11 | if(r.nextInt(2) == 0) 12 | ++nh; 13 | else 14 | ++nt; 15 | System.out.print(r.nextInt(2)); 16 | } 17 | System.out.println("\n"+ nh +","+nt); 18 | } 19 | public static void main(String[] args) { 20 | int n = Integer.parseInt(args[0]); 21 | simulateCoinToss(n); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /2018-may/8.tree problems/src/com/alg/top20/bt/MyInteger.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bt; 2 | 3 | public class MyInteger { 4 | private int value; 5 | 6 | public MyInteger(int value) { 7 | this.value = value; 8 | } 9 | 10 | public int get() { 11 | return value; 12 | } 13 | 14 | public void set(int value) { 15 | this.value = value; 16 | } 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /2018-may/8.tree problems/src/com/alg/top20/bt/TreeNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bt; 2 | 3 | public class TreeNode { 4 | TreeNode left; 5 | TreeNode right; 6 | Integer data; 7 | 8 | public TreeNode(Integer data) { 9 | super(); 10 | this.data = data; 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /2018-may/9.search tree problems/src/com/alg/top20/bbst/BSTNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bbst; 2 | 3 | public class BSTNode { 4 | int data; 5 | int lrank; 6 | BSTNode left; 7 | BSTNode right; 8 | } 9 | -------------------------------------------------------------------------------- /2018-may/9.search tree problems/src/com/alg/top20/bbst/MyInteger.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bbst; 2 | 3 | 4 | public class MyInteger { 5 | private int value; 6 | 7 | public MyInteger(int value) { 8 | this.value = value; 9 | } 10 | 11 | public int get() { 12 | return value; 13 | } 14 | 15 | public void set(int value) { 16 | this.value = value; 17 | } 18 | 19 | 20 | } 21 | -------------------------------------------------------------------------------- /2018-may/9.search tree problems/src/com/alg/top20/bbst/SearchBBST.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bbst; 2 | public class SearchBBST { 3 | 4 | public static boolean search1(BSTNode root, int x) { 5 | while (root != null) { 6 | if (x == root.data) 7 | return true; 8 | if (x < root.data) 9 | root = root.left; 10 | else 11 | root = root.right; 12 | } 13 | return false; 14 | } 15 | 16 | public static boolean search2(BSTNode root, int x) { 17 | if(root == null) return false; 18 | if(x == root.data) return true; 19 | if(x < root.data) 20 | return search2(root.left, x); 21 | else 22 | return search2(root.right, x); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /2018-may/assignments/1.adhoc-thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-may/assignments/1.adhoc-thinking.pdf -------------------------------------------------------------------------------- /2018-may/assignments/10.greedy problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-may/assignments/10.greedy problems.pdf -------------------------------------------------------------------------------- /2018-may/assignments/11.complete search and backtracking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-may/assignments/11.complete search and backtracking.pdf -------------------------------------------------------------------------------- /2018-may/assignments/12.trie-problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-may/assignments/12.trie-problems.pdf -------------------------------------------------------------------------------- /2018-may/assignments/13.suffix array and suffix tree problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-may/assignments/13.suffix array and suffix tree problems.pdf -------------------------------------------------------------------------------- /2018-may/assignments/14.string-problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-may/assignments/14.string-problems.pdf -------------------------------------------------------------------------------- /2018-may/assignments/15.stack-queue-deque problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-may/assignments/15.stack-queue-deque problems.pdf -------------------------------------------------------------------------------- /2018-may/assignments/16.datastructure design problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-may/assignments/16.datastructure design problems.pdf -------------------------------------------------------------------------------- /2018-may/assignments/17.bitwise problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-may/assignments/17.bitwise problems.pdf -------------------------------------------------------------------------------- /2018-may/assignments/18.sorting.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-may/assignments/18.sorting.pdf -------------------------------------------------------------------------------- /2018-may/assignments/2.adhoc-thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-may/assignments/2.adhoc-thinking.pdf -------------------------------------------------------------------------------- /2018-may/assignments/3.divide and prune thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-may/assignments/3.divide and prune thinking.pdf -------------------------------------------------------------------------------- /2018-may/assignments/4.set-map.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-may/assignments/4.set-map.pdf -------------------------------------------------------------------------------- /2018-may/assignments/5.linked list problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-may/assignments/5.linked list problems.pdf -------------------------------------------------------------------------------- /2018-may/assignments/6.binary tree problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-may/assignments/6.binary tree problems.pdf -------------------------------------------------------------------------------- /2018-may/assignments/7.bst problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-may/assignments/7.bst problems.pdf -------------------------------------------------------------------------------- /2018-may/assignments/8.optimization-dp.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-may/assignments/8.optimization-dp.pdf -------------------------------------------------------------------------------- /2018-may/assignments/9.sorted ds.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-may/assignments/9.sorted ds.pdf -------------------------------------------------------------------------------- /2018-october/0-process internals/src/com/alg/top20/process/StackOverflow.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.process; 2 | 3 | public class StackOverflow { 4 | static int count = 0; 5 | 6 | public static void dummy(int a, int b) { 7 | try { 8 | ++count; 9 | dummy(a, b); 10 | } catch (StackOverflowError e) { 11 | System.out.println(count); 12 | } 13 | } 14 | 15 | public static void main(String[] args) { 16 | dummy(10, 20); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /2018-october/10.optimization-problems/src/com/alg/top20/opt/MyInteger.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.opt; 2 | 3 | public class MyInteger { 4 | int value; 5 | 6 | public MyInteger(int value) { 7 | this.value = value; 8 | } 9 | 10 | public int get() { 11 | return value; 12 | } 13 | 14 | public void set(int value) { 15 | this.value = value; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /2018-october/12.greedy-pattern/src/com/alg/top20/greedy/LIS.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.greedy; 2 | 3 | import java.util.TreeSet; 4 | 5 | public class LIS { 6 | 7 | //greedy choice 8 | public static int lis(int[] in) { 9 | TreeSet tset = new TreeSet(); 10 | for(int x:in) { 11 | Integer ceil = tset.ceiling(x); 12 | if(ceil != null) 13 | tset.remove(ceil); 14 | tset.add(x); 15 | } 16 | return tset.size(); 17 | } 18 | public static void main(String[] args) { 19 | // TODO Auto-generated method stub 20 | 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /2018-october/13.complete-search/src/com/alg/top20/cs/AllPartitions.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.cs; 2 | 3 | public class AllPartitions { 4 | 5 | public static void allPartitions(String in) { 6 | auxPartitions(in, ""); 7 | } 8 | private static void auxPartitions(String in, String out) { 9 | if(in.length() == 0) { 10 | System.out.println(out); 11 | return; 12 | } 13 | for(int i = 0; i < in.length(); ++i) { 14 | auxPartitions(in.substring(i+1), out+in.substring(0, i+1) +"+"); 15 | } 16 | } 17 | 18 | public static void main(String[] args) { 19 | allPartitions(args[0]); 20 | 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /2018-october/5.ds-design/src/com/alg/top20/basic/trie/ITrie.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.basic.trie; 2 | 3 | import java.util.List; 4 | 5 | public interface ITrie { 6 | void add(String s); 7 | boolean contains(String s); 8 | boolean remove(String s); 9 | List autocomplete(String s); 10 | String longestCommonPrefix(String s); 11 | void display(); 12 | } 13 | -------------------------------------------------------------------------------- /2018-october/6.linked-list problems/src/com/alg/top20/ll/ListNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.ll; 2 | 3 | public class ListNode { 4 | Integer data; 5 | ListNode next; 6 | 7 | } 8 | -------------------------------------------------------------------------------- /2018-october/7.binary-tree-problems/src/com/alg/top20/bt/MyInteger.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bt; 2 | 3 | public class MyInteger { 4 | int value; 5 | 6 | public MyInteger(int value) { 7 | this.value = value; 8 | } 9 | 10 | public int get() { 11 | return value; 12 | } 13 | 14 | public void set(int value) { 15 | this.value = value; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /2018-october/7.binary-tree-problems/src/com/alg/top20/bt/TreeNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bt; 2 | 3 | public class TreeNode { 4 | Integer data; 5 | TreeNode left; 6 | TreeNode right; 7 | public TreeNode(Integer data) { 8 | this.data = data; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /2018-october/8.search-tree problems/src/com/alg/top20/bst/MyInteger.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bst; 2 | 3 | public class MyInteger { 4 | int value; 5 | 6 | public MyInteger(int value) { 7 | this.value = value; 8 | } 9 | 10 | public int get() { 11 | return value; 12 | } 13 | 14 | public void set(int value) { 15 | this.value = value; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /2018-october/8.search-tree problems/src/com/alg/top20/bst/SearchBST.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bst; 2 | 3 | public class SearchBST { 4 | 5 | public static boolean search(TreeNode root, int x) { 6 | while (root != null) { 7 | if (x == root.data) 8 | return true; 9 | if (x < root.data) 10 | root = root.left; 11 | else 12 | root = root.right; 13 | } 14 | return false; 15 | } 16 | 17 | public static void main(String[] args) { 18 | // TODO Auto-generated method stub 19 | 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /2018-october/8.search-tree problems/src/com/alg/top20/bst/TreeNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bst; 2 | 3 | public class TreeNode { 4 | Integer data; 5 | TreeNode left; 6 | TreeNode right; 7 | int ls_size; 8 | public TreeNode(Integer data) { 9 | this.data = data; 10 | this.ls_size = 1; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /2018-october/assignments/1.adhoc-thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-october/assignments/1.adhoc-thinking.pdf -------------------------------------------------------------------------------- /2018-october/assignments/10.greedy problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-october/assignments/10.greedy problems.pdf -------------------------------------------------------------------------------- /2018-october/assignments/11.trie-problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-october/assignments/11.trie-problems.pdf -------------------------------------------------------------------------------- /2018-october/assignments/12.suffix array and suffix tree problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-october/assignments/12.suffix array and suffix tree problems.pdf -------------------------------------------------------------------------------- /2018-october/assignments/13.string-problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-october/assignments/13.string-problems.pdf -------------------------------------------------------------------------------- /2018-october/assignments/2.divide and prune thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-october/assignments/2.divide and prune thinking.pdf -------------------------------------------------------------------------------- /2018-october/assignments/3.stack-queue-deque problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-october/assignments/3.stack-queue-deque problems.pdf -------------------------------------------------------------------------------- /2018-october/assignments/4.set-map.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-october/assignments/4.set-map.pdf -------------------------------------------------------------------------------- /2018-october/assignments/5.binary tree problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-october/assignments/5.binary tree problems.pdf -------------------------------------------------------------------------------- /2018-october/assignments/6.bst problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-october/assignments/6.bst problems.pdf -------------------------------------------------------------------------------- /2018-october/assignments/7.optimization-dp.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-october/assignments/7.optimization-dp.pdf -------------------------------------------------------------------------------- /2018-october/assignments/8.sorted datastructures.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-october/assignments/8.sorted datastructures.pdf -------------------------------------------------------------------------------- /2018-october/assignments/9.complete search and backtracking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2018-october/assignments/9.complete search and backtracking.pdf -------------------------------------------------------------------------------- /2019-jan/10.optimization problems/src/com/alg/top20/opt/MyInteger.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.opt; 2 | 3 | 4 | public class MyInteger { 5 | private int data; 6 | public MyInteger(int data) { 7 | this.data = data; 8 | } 9 | public int get() { 10 | return data; 11 | } 12 | public void set(int data) { 13 | this.data = data; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /2019-jan/12.combinatorial problems/src/com/alg/top20/combinatorics/AllPartitions.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.combinatorics; 2 | 3 | public class AllPartitions { 4 | 5 | public static void allPartitions(String in) { 6 | auxPartitions(in, ""); 7 | } 8 | private static void auxPartitions(String in, String res) { 9 | if(in.length() == 0) { 10 | System.out.println(res); 11 | return; 12 | } 13 | for(int i = 0; i < in.length(); ++i) 14 | auxPartitions(in.substring(i+1), res + "+" + in.substring(0, i+1)); 15 | } 16 | public static void main(String[] args) { 17 | allPartitions(args[0]); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /2019-jan/14.randomness and problems/src/com/alg/top20/random/MyRandom.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.random; 2 | 3 | import java.util.Random; 4 | 5 | public class MyRandom { 6 | private Random random = new Random(); 7 | 8 | public int nextInt(int l, int r) { 9 | int a =0, b = r-1, c = l, d = r-1; 10 | int tmp = random.nextInt(b+1); 11 | return ( (tmp-a)/(b-a) * (d-c)) + c; 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /2019-jan/15.string-problems/src/com/alg/top20/string/ITrie.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.string; 2 | 3 | import java.util.List; 4 | 5 | public interface ITrie { 6 | void add(String s); 7 | void remove(String s); 8 | List autocomplete(String s); 9 | String lcp(String s); 10 | void display(); 11 | } 12 | -------------------------------------------------------------------------------- /2019-jan/15.string-problems/src/com/alg/top20/string/MyInteger.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.string; 2 | 3 | public class MyInteger { 4 | private int data; 5 | public MyInteger(int data) { 6 | this.data = data; 7 | } 8 | public int get() { 9 | return data; 10 | } 11 | public void set(int data) { 12 | this.data = data; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /2019-jan/17.bit-wise problems/src/com/alg/top20/bit/BitwiseUtils.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bit; 2 | 3 | public class BitwiseUtils { 4 | 5 | public static void showBits(int n) { 6 | int mask = 1 << 31; 7 | for(int i = 0; i < 32; ++i) { 8 | if(i % 8 == 0) 9 | System.out.print(" "); 10 | if((n & mask) != 0) 11 | System.out.print("1"); 12 | else 13 | System.out.print("0"); 14 | mask = mask >>> 1; 15 | } 16 | System.out.println(); 17 | } 18 | 19 | 20 | } 21 | -------------------------------------------------------------------------------- /2019-jan/17.bit-wise problems/src/com/alg/top20/bit/HighestLowestMultiples.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bit; 2 | 3 | public class HighestLowestMultiples { 4 | 5 | public static int nextHighest(int n) { 6 | return (n + 7) & ~7; 7 | } 8 | 9 | public static int immediateLowest(int n) { 10 | return n & ~7; 11 | //return n & -8 12 | } 13 | public static void main(String[] args) { 14 | int n = Integer.parseInt(args[0]); 15 | System.out.println(nextHighest(n)); 16 | System.out.println(immediateLowest(n)); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /2019-jan/5.linked-list problems/src/com/alg/top20/ll/DListNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.ll; 2 | 3 | public class DListNode { 4 | Integer key; 5 | String value; 6 | DListNode prev; 7 | DListNode next; 8 | 9 | public DListNode() { 10 | prev = next = this; 11 | } 12 | 13 | public DListNode(Integer key, String value) { 14 | this.key = key; 15 | this.value = value; 16 | prev = next = this; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /2019-jan/5.linked-list problems/src/com/alg/top20/ll/LinkedListUtils.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.ll; 2 | 3 | public class LinkedListUtils { 4 | 5 | public static ListNode createList(int n) { 6 | return null; 7 | } 8 | public static void main(String[] args) { 9 | // TODO Auto-generated method stub 10 | 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /2019-jan/5.linked-list problems/src/com/alg/top20/ll/ListNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.ll; 2 | 3 | public class ListNode { 4 | Integer data; 5 | ListNode next; 6 | } 7 | -------------------------------------------------------------------------------- /2019-jan/6.recursion-thinking/src/com/alg/top20/recursion/Honai.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.recursion; 2 | 3 | public class Honai { 4 | 5 | public static void honai1(int n, char src, char aux, char target) { 6 | if(n == 1) { 7 | System.out.println(src +"->" + target); 8 | return; 9 | } 10 | honai1(n-1, src, target, aux); 11 | System.out.println(src +"->" + target); 12 | honai1(n-1, aux,src, target); 13 | } 14 | public static void main(String[] args) { 15 | int n = Integer.parseInt(args[0]); 16 | honai1(n, 'A', 'B', 'C'); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /2019-jan/7.binary tree problems/src/com/alg/top20/bt/BTNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bt; 2 | 3 | public class BTNode { 4 | BTNode left; 5 | BTNode right; 6 | Integer data; 7 | 8 | public BTNode() { 9 | 10 | } 11 | public BTNode(int data) { 12 | this.data = data; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /2019-jan/7.binary tree problems/src/com/alg/top20/bt/MyInteger.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bt; 2 | 3 | public class MyInteger { 4 | private int data; 5 | public MyInteger(int data) { 6 | this.data = data; 7 | } 8 | public int get() { 9 | return data; 10 | } 11 | public void set(int data) { 12 | this.data = data; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /2019-jan/8.bst problems/src/com/alg/top20/bst/BSTNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bst; 2 | 3 | public class BSTNode { 4 | BSTNode left; 5 | BSTNode right; 6 | Integer data; 7 | int local_rank; 8 | 9 | public BSTNode() { 10 | 11 | } 12 | public BSTNode(int data) { 13 | this.data = data; 14 | this.local_rank = 1; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /2019-jan/8.bst problems/src/com/alg/top20/bst/MyInteger.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bst; 2 | 3 | public class MyInteger { 4 | private int data; 5 | public MyInteger(int data) { 6 | this.data = data; 7 | } 8 | public int get() { 9 | return data; 10 | } 11 | public void set(int data) { 12 | this.data = data; 13 | } 14 | public void increment(int value) { 15 | data += value; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /2019-jan/8.bst problems/src/com/alg/top20/bst/Search.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bst; 2 | 3 | public class Search { 4 | 5 | //TC:O(log n) SC:O(1) 6 | public static boolean search(BSTNode root, int x) { 7 | BSTNode current = root; 8 | while (current != null) { 9 | if (x == current.data) 10 | return true; 11 | if (x < current.data) 12 | current = current.left; 13 | else 14 | current = current.right; 15 | } 16 | return false; 17 | } 18 | 19 | public static void main(String[] args) { 20 | // TODO Auto-generated method stub 21 | 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /2019-jan/assignments/1.adhoc-thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2019-jan/assignments/1.adhoc-thinking.pdf -------------------------------------------------------------------------------- /2019-jan/assignments/2.divide and prune thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2019-jan/assignments/2.divide and prune thinking.pdf -------------------------------------------------------------------------------- /2019-jan/assignments/3.stack-queue-deque problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2019-jan/assignments/3.stack-queue-deque problems.pdf -------------------------------------------------------------------------------- /2019-jan/assignments/4.set-map.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2019-jan/assignments/4.set-map.pdf -------------------------------------------------------------------------------- /2019-jan/assignments/5.linked list problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2019-jan/assignments/5.linked list problems.pdf -------------------------------------------------------------------------------- /2019-jan/assignments/6.binary tree problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2019-jan/assignments/6.binary tree problems.pdf -------------------------------------------------------------------------------- /2019-jan/assignments/7.bst problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2019-jan/assignments/7.bst problems.pdf -------------------------------------------------------------------------------- /2019-jan/assignments/8.optimization-dp.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2019-jan/assignments/8.optimization-dp.pdf -------------------------------------------------------------------------------- /2019-jan/assignments/9.sorted set-sorted map.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2019-jan/assignments/9.sorted set-sorted map.pdf -------------------------------------------------------------------------------- /2019-may/10.string-problems/src/com/alg/top20/string/trie/ITrie.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.string.trie; 2 | 3 | import java.util.List; 4 | 5 | public interface ITrie { 6 | void add(String in); 7 | boolean contains(String in); 8 | void remove(String in); 9 | List autocomplete(String prefix); 10 | String lcp(String in); 11 | int size(); 12 | } 13 | -------------------------------------------------------------------------------- /2019-may/12.recursion-to-nonrecursion/src/com/alg/top20/rec/Template1.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.rec; 2 | 3 | public class Template1 { 4 | 5 | public static int f_rec(int n) { 6 | if(n == 0) return 0; 7 | return n + f_rec(n-1); 8 | } 9 | 10 | public static int f_nonrec(int n) { 11 | int sum = 0; 12 | while(n > 0) { 13 | sum = sum + n--; 14 | } 15 | return sum; 16 | } 17 | 18 | public static void main(String[] args) { 19 | int n = Integer.parseInt(args[0]); 20 | System.out.println(f_nonrec(n)); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /2019-may/14.random generators/src/com/alg/top20/random/Random1.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.random; 2 | 3 | public class Random1 { 4 | 5 | public int nextInt(int m) { 6 | return (int)System.currentTimeMillis() % m; 7 | } 8 | public static void main(String[] args) { 9 | Random1 r = new Random1(); 10 | for(int i = 1; i <= 2000; ++i) 11 | System.out.println(r.nextInt(10)); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /2019-may/15.bitwise problems/src/com/alg/top20/bit/BitWiseUtils.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bit; 2 | 3 | public class BitWiseUtils { 4 | 5 | public static void showBits(int n) { 6 | int mask = 1 << 31; 7 | for(int i = 0; i < 32; ++i) { 8 | if( (n & mask) != 0) 9 | System.out.print("1"); 10 | else 11 | System.out.print("0"); 12 | mask = mask >>> 1; 13 | } 14 | System.out.println(); 15 | } 16 | public static void main(String[] args) { 17 | int n = Integer.parseInt(args[0]); 18 | showBits(n); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /2019-may/15.bitwise problems/src/com/alg/top20/bit/BoundaryAlignment.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bit; 2 | 3 | public class BoundaryAlignment { 4 | 5 | public static int immediate_lowest_8(int n) { 6 | return n & ~7; 7 | } 8 | public static int immediate_highest_8(int n) { 9 | return (n + 7) & ~7; 10 | } 11 | public static void main(String[] args) { 12 | int n = Integer.parseInt(args[0]); 13 | System.out.println(immediate_highest_8(n)); 14 | System.out.println(immediate_lowest_8(n)); 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /2019-may/3.linked list problems/linked list problems/src/com/alg/top20/ll/DListNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.ll; 2 | 3 | public class DListNode { 4 | String key; 5 | Integer value; 6 | DListNode prev, next; 7 | 8 | public DListNode() { 9 | prev = next = this; 10 | } 11 | public DListNode(String key, Integer value) { 12 | super(); 13 | this.key = key; 14 | this.value = value; 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /2019-may/3.linked list problems/linked list problems/src/com/alg/top20/ll/ListNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.ll; 2 | 3 | public class ListNode { 4 | Integer data; 5 | ListNode next; 6 | } 7 | -------------------------------------------------------------------------------- /2019-may/4.binary tree problems/src/com/alg/top20/bt/BTNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bt; 2 | 3 | public class BTNode { 4 | Integer data; 5 | BTNode left; 6 | BTNode right; 7 | public BTNode(Integer data) { 8 | this.data = data; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /2019-may/4.binary tree problems/src/com/alg/top20/bt/MyInteger.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bt; 2 | 3 | public class MyInteger { 4 | private int value; 5 | 6 | public MyInteger(int value) { 7 | super(); 8 | this.value = value; 9 | } 10 | public int get() { 11 | return value; 12 | } 13 | public void set(int value) { 14 | this.value = value; 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /2019-may/5.bst problems/src/com/alg/top20/bst/BSTNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bst; 2 | 3 | public class BSTNode { 4 | Integer data; 5 | BSTNode left; 6 | BSTNode right; 7 | int lst_size; 8 | public BSTNode(Integer data) { 9 | this.data = data; 10 | } 11 | public BSTNode(Integer data, int lst_size) { 12 | this.data = data; 13 | this.lst_size = lst_size; 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /2019-may/5.bst problems/src/com/alg/top20/bst/BSTSearch.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bst; 2 | 3 | public class BSTSearch { 4 | 5 | public static boolean search1(BSTNode root, int x) { 6 | while (root != null) { 7 | if (x == root.data) 8 | return true; 9 | if (x < root.data) 10 | root = root.left; 11 | else 12 | root = root.right; 13 | } 14 | return false; 15 | } 16 | 17 | public static void main(String[] args) { 18 | // TODO Auto-generated method stub 19 | 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /2019-may/5.bst problems/src/com/alg/top20/bst/MyInteger.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bst; 2 | 3 | public class MyInteger { 4 | private int value; 5 | 6 | public MyInteger(int value) { 7 | super(); 8 | this.value = value; 9 | } 10 | public int get() { 11 | return value; 12 | } 13 | public void set(int value) { 14 | this.value = value; 15 | } 16 | public void incr() { 17 | ++this.value; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /2019-may/7.dynamic programming/src/com/alg/top20/dp/MyInteger.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.combinatorics; 2 | 3 | public class MyInteger { 4 | private int value; 5 | 6 | public MyInteger(int value) { 7 | super(); 8 | this.value = value; 9 | } 10 | public int get() { 11 | return value; 12 | } 13 | public void set(int value) { 14 | this.value = value; 15 | } 16 | public void incr() { 17 | ++this.value; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /2019-may/9.combinatorial problems/src/com/alg/top20/combinatorics/AllPartitions.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.combinatorics; 2 | 3 | public class AllPartitions { 4 | 5 | public static void partitions1(String in) { 6 | auxPartitions1(in, ""); 7 | } 8 | private static void auxPartitions1(String in, String out) { 9 | if(in.length() == 0) { 10 | System.out.println(out); 11 | return; 12 | } 13 | for(int i = 0; i < in.length(); ++i) 14 | auxPartitions1(in.substring(i+1), out + "+" + in.substring(0, i+1) ); 15 | } 16 | 17 | public static void main(String[] args) { 18 | partitions1(args[0]); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /2019-may/9.combinatorial problems/src/com/alg/top20/combinatorics/AllSequences.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.combinatorics; 2 | 3 | public class AllSequences { 4 | 5 | public static void allSeq1(int n, String in) { 6 | auxSeq1(0, n, in, ""); 7 | } 8 | public static void auxSeq1(int d, int n, String in, String out) { 9 | if(d == n) { 10 | System.out.println(out); 11 | return; 12 | } 13 | for(int i = 0; i < in.length(); ++i) 14 | auxSeq1(d+1, n, in, out+in.charAt(i)); 15 | } 16 | public static void main(String[] args) { 17 | int n = Integer.parseInt(args[1]); 18 | allSeq1(n, args[0]); 19 | } 20 | 21 | 22 | } 23 | -------------------------------------------------------------------------------- /2019-may/assignments/1.adhoc-thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2019-may/assignments/1.adhoc-thinking.pdf -------------------------------------------------------------------------------- /2019-may/assignments/2.divide and prune thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2019-may/assignments/2.divide and prune thinking.pdf -------------------------------------------------------------------------------- /2019-may/assignments/3.set-map.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2019-may/assignments/3.set-map.pdf -------------------------------------------------------------------------------- /2019-may/assignments/4.linked list problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2019-may/assignments/4.linked list problems.pdf -------------------------------------------------------------------------------- /2019-may/assignments/5.binary tree problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2019-may/assignments/5.binary tree problems.pdf -------------------------------------------------------------------------------- /2019-may/assignments/7.bst problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2019-may/assignments/7.bst problems.pdf -------------------------------------------------------------------------------- /2019-may/assignments/8.sorted data structures.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2019-may/assignments/8.sorted data structures.pdf -------------------------------------------------------------------------------- /2019-october/10.combinatorial problems/src/com/alg/top20/combinatorics/AllPartitions.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.combinatorics; 2 | 3 | public class AllPartitions { 4 | 5 | public static void allPartitions1(String in) { 6 | auxAllPartitions1(in, ""); 7 | } 8 | private static void auxAllPartitions1(String in, String res) { 9 | if(0 == in.length()) { 10 | System.out.println(res); 11 | return; 12 | } 13 | for(int i = 0; i < in.length(); ++i) 14 | auxAllPartitions1(in.substring(i+1), res+"+"+in.substring(0, i+1)); 15 | } 16 | 17 | public static void main(String[] args) { 18 | allPartitions1(args[0]); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /2019-october/10.combinatorial problems/src/com/alg/top20/combinatorics/AllSequences.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.combinatorics; 2 | 3 | public class AllSequences { 4 | 5 | public static void allSeq1(String in) { 6 | auxAllSeq1(0, in, ""); 7 | } 8 | private static void auxAllSeq1(int d, String in, String res) { 9 | if(d == in.length()) { 10 | System.out.println(res); 11 | return; 12 | } 13 | for(int i = 0; i < in.length(); ++i) 14 | auxAllSeq1(d+1, in, res+in.charAt(i)); 15 | } 16 | 17 | public static void main(String[] args) { 18 | allSeq1(args[0]); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /2019-october/13.string problems/src/com/alg/top20/string/MyInteger.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.string; 2 | 3 | public class MyInteger { 4 | private int value; 5 | 6 | public MyInteger(int value) { 7 | this.value = value; 8 | } 9 | 10 | public int get() { 11 | return value; 12 | } 13 | 14 | public void set(int value) { 15 | this.value = value; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /2019-october/13.string problems/src/com/alg/top20/string/trie/ITrie.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.string.trie; 2 | 3 | import java.util.List; 4 | 5 | public interface ITrie { 6 | void add(String in); 7 | boolean contains(String in); 8 | boolean remove(String in); 9 | List autocomplete(String prefix); 10 | String lcp(String in); 11 | void print(); 12 | } 13 | -------------------------------------------------------------------------------- /2019-october/13.string problems/src/com/alg/top20/trie/ITrie.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.trie; 2 | 3 | import java.util.List; 4 | 5 | public interface ITrie { 6 | void add(String in); 7 | boolean contains(String in); 8 | boolean remove(String in); 9 | List autocomplete(String prefix); 10 | String lcp(String in); 11 | void print(); 12 | } 13 | -------------------------------------------------------------------------------- /2019-october/3.linked list problems/src/com/alg/top20/linkedlist/ListNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.linkedlist; 2 | 3 | public class ListNode { 4 | Integer data; 5 | ListNode next; 6 | public ListNode() { 7 | 8 | } 9 | public ListNode(int i) { 10 | this.data = i; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /2019-october/6.binary tree problems/src/com/alg/top20/bt/MyInteger.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bt; 2 | 3 | public class MyInteger { 4 | private int value; 5 | 6 | public MyInteger(int value) { 7 | this.value = value; 8 | } 9 | 10 | public int get() { 11 | return value; 12 | } 13 | 14 | public void set(int value) { 15 | this.value = value; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /2019-october/6.binary tree problems/src/com/alg/top20/bt/TreeNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bt; 2 | 3 | public class TreeNode { 4 | TreeNode left; 5 | TreeNode right; 6 | int data; 7 | 8 | public TreeNode() { 9 | 10 | } 11 | 12 | public TreeNode(int data) { 13 | this.data = data; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /2019-october/7.bst problems/src/com/alg/top20/bst/BSTSearch.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bst; 2 | 3 | public class BSTSearch { 4 | 5 | public static boolean treeSearch1(TreeNode root, int x) { 6 | while (root != null) { 7 | if (root.data == x) 8 | return true; 9 | if (x < root.data) 10 | root = root.left; 11 | else 12 | root = root.right; 13 | } 14 | return false; 15 | } 16 | 17 | public static void main(String[] args) { 18 | // TODO Auto-generated method stub 19 | 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /2019-october/7.bst problems/src/com/alg/top20/bst/MyInteger.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bst; 2 | 3 | public class MyInteger { 4 | private int value; 5 | 6 | public MyInteger(int value) { 7 | this.value = value; 8 | } 9 | 10 | public int get() { 11 | return value; 12 | } 13 | 14 | public void set(int value) { 15 | this.value = value; 16 | } 17 | 18 | public void incr() { 19 | this.value++; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /2019-october/7.bst problems/src/com/alg/top20/bst/TreeNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bst; 2 | 3 | public class TreeNode { 4 | TreeNode left; 5 | TreeNode right; 6 | int data; 7 | int lst_size; 8 | 9 | public TreeNode() { 10 | 11 | } 12 | 13 | public TreeNode(int data) { 14 | this.data = data; 15 | } 16 | 17 | public TreeNode(int data, int rank) { 18 | this.data = data; 19 | this.lst_size = rank; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /2019-october/8.sorted ds/src/com/alg/top20/sortedds/MyCalender2.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.sortedds; 2 | 3 | import java.util.TreeMap; 4 | 5 | public class MyCalender2 { 6 | private TreeMap events = new TreeMap(); 7 | 8 | public boolean book(int start, int end) { 9 | Integer floorStart = events.floorKey(start); 10 | if (floorStart != null && events.get(floorStart) > start) 11 | return false; 12 | 13 | Integer ceilStart = events.ceilingKey(start); 14 | if (ceilStart != null && ceilStart < end) 15 | return false; 16 | 17 | events.put(start, end); 18 | return true; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /2019-october/9.dynamic programming/src/com/alg/top20/dp/MyInteger.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.dp; 2 | 3 | public class MyInteger { 4 | private int value; 5 | 6 | public MyInteger(int value) { 7 | this.value = value; 8 | } 9 | 10 | public int get() { 11 | return value; 12 | } 13 | 14 | public void set(int value) { 15 | this.value = value; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /2019-october/assignments/1.adhoc-thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2019-october/assignments/1.adhoc-thinking.pdf -------------------------------------------------------------------------------- /2019-october/assignments/2.divide and prune thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2019-october/assignments/2.divide and prune thinking.pdf -------------------------------------------------------------------------------- /2019-october/assignments/3.set-map.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2019-october/assignments/3.set-map.pdf -------------------------------------------------------------------------------- /2019-october/assignments/4.linked list problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2019-october/assignments/4.linked list problems.pdf -------------------------------------------------------------------------------- /2019-october/assignments/5.binary tree problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2019-october/assignments/5.binary tree problems.pdf -------------------------------------------------------------------------------- /2019-october/assignments/6.bst problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2019-october/assignments/6.bst problems.pdf -------------------------------------------------------------------------------- /2019-october/assignments/7.sorted data structures.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2019-october/assignments/7.sorted data structures.pdf -------------------------------------------------------------------------------- /2020-jan/4.linkedlist problems/src/com/alg/top20/ll/ListNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.ll; 2 | 3 | public class ListNode { 4 | Integer data; 5 | ListNode next; 6 | public ListNode() { 7 | 8 | } 9 | public ListNode(Integer data) { 10 | super(); 11 | this.data = data; 12 | } 13 | } -------------------------------------------------------------------------------- /2020-jan/5.binary tree problems/src/com/alg/top20/bt/MyInteger.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bt; 2 | 3 | public class MyInteger { 4 | private int value; 5 | 6 | public MyInteger(int value) { 7 | super(); 8 | this.value = value; 9 | } 10 | 11 | public int get() { 12 | return value; 13 | } 14 | 15 | public void set(int value) { 16 | this.value = value; 17 | } 18 | 19 | public void incr() { 20 | this.value++; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /2020-jan/5.binary tree problems/src/com/alg/top20/bt/TreeNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bt; 2 | 3 | public class TreeNode { 4 | TreeNode left; 5 | TreeNode right; 6 | int data; 7 | 8 | public TreeNode() { 9 | 10 | } 11 | 12 | public TreeNode(int data) { 13 | this.data = data; 14 | } 15 | } -------------------------------------------------------------------------------- /2020-jan/6.bst problems/src/com/alg/top20/bst/BSTSearch.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bst; 2 | 3 | public class BSTSearch { 4 | 5 | //TC:O(h) SC:O(1) 6 | //precondition: input tree must be bst 7 | public static boolean search1(TreeNode root, int x) { 8 | while (root != null) { 9 | if (root.data == x) 10 | return true; 11 | if (x < root.data) 12 | root = root.left; 13 | else 14 | root = root.right; 15 | } 16 | return false; 17 | } 18 | 19 | public static void main(String[] args) { 20 | // TODO Auto-generated method stub 21 | 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /2020-jan/6.bst problems/src/com/alg/top20/bst/Ceil.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bst; 2 | 3 | public class Ceil { 4 | 5 | // TC:O(h) SC:O(1) 6 | public static int ceil1(TreeNode root, int x) { 7 | int res = Integer.MIN_VALUE; 8 | while (root != null) { 9 | if (root.data == x) 10 | return x; 11 | if (x < root.data) { 12 | res = root.data; 13 | root = root.left; 14 | } else 15 | root = root.right; 16 | } 17 | return res; 18 | } 19 | 20 | public static void main(String[] args) { 21 | // TODO Auto-generated method stub 22 | 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /2020-jan/6.bst problems/src/com/alg/top20/bst/MyInteger.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bst; 2 | 3 | public class MyInteger { 4 | private int value; 5 | 6 | public MyInteger(int value) { 7 | this.value = value; 8 | } 9 | 10 | public int get() { 11 | return value; 12 | } 13 | 14 | public void set(int value) { 15 | this.value = value; 16 | } 17 | 18 | public void incr() { 19 | this.value++; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /2020-jan/6.bst problems/src/com/alg/top20/bst/TreeNode.java: -------------------------------------------------------------------------------- 1 | package com.alg.top20.bst; 2 | 3 | public class TreeNode { 4 | TreeNode left; 5 | TreeNode right; 6 | int data; 7 | 8 | public TreeNode() { 9 | 10 | } 11 | 12 | public TreeNode(int data) { 13 | this.data = data; 14 | } 15 | } -------------------------------------------------------------------------------- /2020-jan/assignments/1.adhoc-thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2020-jan/assignments/1.adhoc-thinking.pdf -------------------------------------------------------------------------------- /2020-jan/assignments/2.divide and prune thinking.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2020-jan/assignments/2.divide and prune thinking.pdf -------------------------------------------------------------------------------- /2020-jan/assignments/3.set-map.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2020-jan/assignments/3.set-map.pdf -------------------------------------------------------------------------------- /2020-jan/assignments/4.linked list problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorithmica-repository/top20/76b155e979a5b847d708965b761060f76a390d5d/2020-jan/assignments/4.linked list problems.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | top20 2 | ===== 3 | 4 | It consists of all the code examples of Top-20(Problem solving) course taken up at Algorithmica across all years. You can use/redistribute this code for academic purpose only. 5 | --------------------------------------------------------------------------------