Algorithm
文章平均质量分 59
哈天奇不奇
这个作者很懒,什么都没留下…
展开
-
Bubble Sort
package com.fairy.test;public class BubbleSort { public static void bubbleSort(int[] a) { for (int i = 0; i < a.length; i++) { for (int j = a.length - 1; j > i; j--) { if (...原创 2012-05-29 17:55:10 · 53 阅读 · 0 评论 -
Print all possible combinations of coins per change amount
原创转载请注明出处:http://agilestyle.iteye.com/blog/2361927 Question:Given a change amount, print all possible combinations using different sets of coins Solution:核心思想:递归1. Sort coins from larg...原创 2017-03-13 14:24:43 · 154 阅读 · 0 评论 -
Print all pairs of values a sorted array that sum up to a given value M
原创转载请注明出处:http://agilestyle.iteye.com/blog/2361909 QuestionPrint all pairs of values a sorted array that sum up to a given value M Example Solution1. Scan from both ends, calculate t...原创 2017-03-13 12:16:34 · 97 阅读 · 0 评论 -
Merge Two Sorted Arrays without additional memory
原创转载请注明出处:http://agilestyle.iteye.com/blog/2361133 QuestionMerge Two Sorted Arrays into the larger array, given the large array has extra storage. Merge without additional memory Requireme...原创 2017-03-09 13:58:32 · 124 阅读 · 0 评论 -
Use stack (LIFO) to simulate queue (FIFO)
原创转载请注明出处:http://agilestyle.iteye.com/blog/2360962 Solution1. Using 2 stacks1.1. One stack to accept incoming values in FILO manner1.2. The other stack to reverse the values in first stack...原创 2017-03-08 16:28:12 · 105 阅读 · 0 评论 -
Print all elements at a given level in the binary tree
原创转载请注明出处:http://agilestyle.iteye.com/blog/2360924 method 1 —— 使用两个队列use a queue to store elements and levelskeep dequeing elements until the associated levels equals to the desired levelp...原创 2017-03-08 15:09:42 · 90 阅读 · 0 评论 -
Verify if a tree is a binary search tree(BST)
原创转载请注明出处:http://agilestyle.iteye.com/blog/2360893 Binary Search Treeany node in left sub-tree < its parentany node in rigth sub-tree > its parent核心思想:递归recursively to check valu...原创 2017-03-08 12:11:38 · 121 阅读 · 0 评论 -
Print all valid combinations of groups of parenthesis
原创转载请注明出处:http://agilestyle.iteye.com/blog/2360764 Given Three pairs of "((()))"Print "()()(), (())(), ()(()), ((()))" 核心思想:递归package org.fool.java.test;public class ParenthesisPrint...原创 2017-03-07 16:42:24 · 79 阅读 · 0 评论 -
Reverse a linked list
原创转载请注明出处:http://agilestyle.iteye.com/blog/2360694 Recursive IdeaReverse(Head -> Remaining List)=>Reverse(Remaining List) -> Head Example:Reverse(1->2->3->4->5)...原创 2017-03-07 13:08:01 · 132 阅读 · 0 评论 -
Get all subset of a set
原创转载请注明出处:http://agilestyle.iteye.com/blog/2360659 找出一个Set集合中的所有子集比如全集为 {1, 2, 3}子集则有{},{1},{2},{3},{1,2},{1,3},{2,3},{1,2,3} 此算法的核心思想:递归package org.fool.java.collections;import ja...原创 2017-03-07 10:14:24 · 173 阅读 · 0 评论 -
Trie树
原创转载请注明出处:http://agilestyle.iteye.com/blog/2358785 Trie树Trie树即字典树,又称单词查找树或键树,是一种树形结构,是一种哈希树的变种。典型应用是用于统计和排序大量的字符串(但不仅限于字符串),所以经常被搜索引擎系统用于文本词频统计。它的优点是:最大限度地减少无谓的字符串比较,查询效率比哈希表高。Trie是一颗存储多个字符串的树...原创 2017-02-23 21:51:43 · 90 阅读 · 0 评论 -
倒排索引
原创转载请注明出处:http://agilestyle.iteye.com/blog/2358625 倒排索引倒排索引(英语:Inverted index),也常被称为反向索引、置入档案或反向档案,是一种索引方法,被用来存储在全文搜索下某个单词在一个文档或者一组文档中的存储位置的映射。它是文档检索系统中最常用的数据结构。有两种不同的反向索引形式:一条记录的水平反向索引(或...原创 2017-02-23 11:53:08 · 117 阅读 · 0 评论 -
快速排序图例
原创转载请注明出处:http://agilestyle.iteye.com/blog/2358405 Quick Sort27作为pivot,从前向后找比27大的(i++),从后向前找比27小的(j--),进行swap,重复 i++、j--、swap,直到 i=j,一趟快排结束Note:快排体现的是 分治 + 递归 的思想 ...原创 2017-02-22 10:35:53 · 266 阅读 · 0 评论 -
一致性Hash
转自:http://blog.csdn.net/cywosp/article/details/23397179/原创 2017-02-21 22:01:50 · 70 阅读 · 0 评论 -
洗扑克牌(乱数排序)
原创转载请注明出处:http://agilestyle.iteye.com/blog/2358123 基本思想:54张牌从小到大有序排列,产生一个0-53的随机乱数作为Index,并且与当前的值进行swap,遍历过后,54张牌就从有序变为乱序了package org.fool.test;import java.util.Random;public class Shu...原创 2017-02-20 20:05:21 · 211 阅读 · 0 评论 -
AVL树,红黑树,B树,B+树,Trie树
原创转载请注明出处:http://agilestyle.iteye.com/blog/2357562 AVL树AVL是最先发明的自平衡二叉查找树,在AVL树中任何节点的两个子树的高度最大差别为1,也被称为高度平衡树二叉树,所以通常的结果是,维护这种高度平衡所付出的代价比从中获得的效率收益还大,故而实际的应用不多,更多的地方是用追求局部而不是非常严格整体平衡的红黑树。当然,如果场景中...原创 2017-02-16 22:22:59 · 133 阅读 · 0 评论 -
算法复杂度速查表(转)
转自:每个程序员都应该收藏的算法复杂度速查表原创 2016-07-14 16:56:59 · 90 阅读 · 0 评论 -
Binary Search
原创转载请注明出处:http://agilestyle.iteye.com/blog/2273610 Binary Search原理package org.fool.test;public class BinarySearch { public static int binarySearch(int[] nums, int num) { int low = 0...原创 2016-01-24 18:54:18 · 61 阅读 · 0 评论 -
Find the 'closest' value in a BST with a given value M
原创转载请注明出处:http://agilestyle.iteye.com/blog/2361956 Question:Find the 'closest' value in a BST with a given value M Analysis:1. Traditional Binary Search Tree searching M: O(logN) time to...原创 2017-03-13 15:27:24 · 139 阅读 · 0 评论