![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Algorithm
文章平均质量分 65
Agile牧
最重要的,拥有跟随内心与直觉的勇气,你的内心与直觉多少已经知道你真正想要成为什么样的人。任何其它事物都是次要的。
展开
-
Bubble Sort
(a[j] < a[j - 1]) { int temp = a[j]; a[j] = a[j - 1]; a[j - 1] = temp; } } } printArray(a); } public static void printArray(int[] a) { for (int i : a) { System.out.print(i + " "); } Syste原创 2012-05-29 17:55:10 · 74 阅读 · 0 评论 -
Verify if a tree is a binary search tree(BST)
原创 2017-03-08 12:11:38 · 99 阅读 · 0 评论 -
Print all elements at a given level in the binary tree
levels equals to the desired levelprint out elements and stop when queue is empty method 2 —— 递归recursionkeep track of current level versus desired levelprint out element when current = desired package org.fool.java.test;import java.uti原创 2017-03-08 15:09:42 · 90 阅读 · 0 评论 -
Use stack (LIFO) to simulate queue (FIFO)
values in first stack, so LIFO+LIFO becomes FIFO for value retrieval 2. An example2.1. Incoming order: (1,2,3)2.2. Stack 1 storage order(top to bottom): (3,2,1)2.3. Stack 2 after pushing and popping all values in Stack 1:(top to bottom): (1,2,3)原创 2017-03-08 16:28:12 · 122 阅读 · 0 评论 -
Merge Two Sorted Arrays without additional memory
memory RequirementsLong sorted array {1,3,5,0,0,0} (0 means blank spaces), so used length is 3The short sorted array {2,4}The expected merged array will be {1,2,3,4,5,0}Additionally, no additional memory is usede.g. declaring a new array is原创 2017-03-09 13:58:32 · 83 阅读 · 0 评论 -
Print all pairs of values a sorted array that sum up to a given value M
both ends, calculate the sum2. if(sum is equal to M), print and shrink the focus window3. if(sum is less than M), shift left focus index by 14. if(sum is bigger than M), shift right focus index by 15. Stop the loop when left is larger or equal to原创 2017-03-13 12:16:34 · 160 阅读 · 0 评论 -
Print all possible combinations of coins per change amount
原创 2017-03-13 14:24:43 · 118 阅读 · 0 评论 -
Find the 'closest' value in a BST with a given value M
ing M: O(logN) time to return found M or not 2. "closest" value in BST to M: A particular value in the BST tree so that Math.abs(value-M) should be minimal Solution:1. Keep track of the whole searching path to find M and the diff between原创 2017-03-13 15:27:24 · 123 阅读 · 0 评论 -
检索出文本中出现次数最多的单词
现的次数,最后放入list,按出现次数进行降序排列Note:此方法不是最优解,还有更高效的算法,欢迎拍砖 package org.fool.test;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;public class Test { public static void main(String[] args) {原创 2017-09-06 21:29:27 · 827 阅读 · 0 评论 -
Print all valid combinations of groups of parenthesis
st;public class ParenthesisPrintTest { public static void main(String[] args) { printParenthesis(3, 3, ""); } // left and right remains are keeping track of how many remaining parenthesis left for printing // cu原创 2017-03-07 16:42:24 · 82 阅读 · 0 评论 -
Reverse a linked list
;2->3->4->5)=>Reverse(2->3->4->5) -> 1 Demopackage org.fool.java.collections;public class ReverseLinkedListTest { public static void main(String[] args) { List l = new List原创 2017-03-07 13:08:01 · 107 阅读 · 0 评论 -
Get all subset of a set
原创 2017-03-07 10:14:24 · 117 阅读 · 0 评论 -
Binary Search
int num) { int low = 0; int high = nums.length - 1; while (low <= high) { int mid = (low + high) / 2; if (num > nums[mid]) { low = mid + 1; } else if (num < nums[mid]) { high = mid - 1; } else {原创 2016-01-24 18:54:18 · 90 阅读 · 0 评论 -
算法复杂度速查表(转)
原创 2016-07-14 16:56:59 · 115 阅读 · 0 评论 -
AVL树,红黑树,B树,B+树,Trie树
原创 2017-02-16 22:22:59 · 109 阅读 · 0 评论 -
洗扑克牌(乱数排序)
swap,遍历过后,54张牌就从有序变为乱序了package org.fool.test;import java.util.Random;public class Shuffle { public static void main(String[] args) { int a[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,原创 2017-02-20 20:05:21 · 154 阅读 · 0 评论 -
一致性Hash
原创 2017-02-21 22:01:50 · 73 阅读 · 0 评论 -
快速排序图例
原创 2017-02-22 10:35:53 · 172 阅读 · 0 评论 -
倒排索引
原创 2017-02-23 11:53:08 · 103 阅读 · 0 评论 -
Trie树
原创 2017-02-23 21:51:43 · 98 阅读 · 0 评论 -
不可逆加密算法
原创 2017-09-19 22:11:54 · 431 阅读 · 0 评论