![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
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 · 63 阅读 · 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 · 163 阅读 · 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 · 103 阅读 · 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 · 132 阅读 · 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 · 116 阅读 · 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 · 100 阅读 · 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 · 135 阅读 · 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 · 86 阅读 · 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 · 139 阅读 · 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 · 184 阅读 · 0 评论 -
Trie树
原创转载请注明出处:http://agilestyle.iteye.com/blog/2358785 Trie树Trie树即字典树,又称单词查找树或键树,是一种树形结构,是一种哈希树的变种。典型应用是用于统计和排序大量的字符串(但不仅限于字符串),所以经常被搜索引擎系统用于文本词频统计。它的优点是:最大限度地减少无谓的字符串比较,查询效率比哈希表高。Trie是一颗存储多个字符串的树...原创 2017-02-23 21:51:43 · 97 阅读 · 0 评论 -
倒排索引
原创转载请注明出处:http://agilestyle.iteye.com/blog/2358625 倒排索引倒排索引(英语:Inverted index),也常被称为反向索引、置入档案或反向档案,是一种索引方法,被用来存储在全文搜索下某个单词在一个文档或者一组文档中的存储位置的映射。它是文档检索系统中最常用的数据结构。有两种不同的反向索引形式:一条记录的水平反向索引(或...原创 2017-02-23 11:53:08 · 134 阅读 · 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 · 273 阅读 · 0 评论 -
一致性Hash
转自:http://blog.csdn.net/cywosp/article/details/23397179/原创 2017-02-21 22:01:50 · 80 阅读 · 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 · 230 阅读 · 0 评论 -
AVL树,红黑树,B树,B+树,Trie树
原创转载请注明出处:http://agilestyle.iteye.com/blog/2357562 AVL树AVL是最先发明的自平衡二叉查找树,在AVL树中任何节点的两个子树的高度最大差别为1,也被称为高度平衡树二叉树,所以通常的结果是,维护这种高度平衡所付出的代价比从中获得的效率收益还大,故而实际的应用不多,更多的地方是用追求局部而不是非常严格整体平衡的红黑树。当然,如果场景中...原创 2017-02-16 22:22:59 · 152 阅读 · 0 评论 -
算法复杂度速查表(转)
转自:每个程序员都应该收藏的算法复杂度速查表原创 2016-07-14 16:56:59 · 104 阅读 · 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 · 71 阅读 · 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 · 155 阅读 · 0 评论