
算法
文章平均质量分 75
iteye_9715
这个作者很懒,什么都没留下…
展开
-
palindrome
package palindrome;/*Problem StatementA palindrome is a string that reads the same forward and backward. A palindrome substring is a contiguous sequence of characters taken from a string that form a p...2008-07-14 17:39:00 · 178 阅读 · 0 评论 -
字符串搜索算法总结
因为在网上搜寻hash算法的知识,无意中又找到一些字符串搜索算法。 由于之前已经学习过一些搜索算法,觉得应该可以归为一类。因此就写一篇文章来记录下学习的过程。问题:在一长字符串中找出其是否包含某子字符串。首先当然还是简单算法,通过遍历来检索所有的可能:[code="java"] public static int naiveSearch(String content...2010-04-26 09:12:51 · 203 阅读 · 0 评论 -
二叉搜索树的java实现
[code="java"]public class BinarySearchTree { private static class Entity { private T node = null; private Entity parent = null; private Entity left = null; private Entity right =...2010-05-05 09:46:09 · 75 阅读 · 0 评论 -
红黑树的TreeMap实现
红黑树是每个节点都带有颜色属性的二叉查找树,颜色或红色或黑色。在二叉查找树强制一般要求以外,对于任何有效的红黑树我们增加了如下的额外要求:性质1. 节点是红色或黑色。性质2. 根是黑色。性质3. 所有叶子都是黑色(叶子是NIL节点)。性质4. 每个红色节点的两个子节点都是黑色。(从每个叶子到根的所有路径上不能有两个连续的红色节点)性质5. 从任一节点到其每个...原创 2010-05-26 08:56:33 · 115 阅读 · 0 评论 -
HTML - DOM
最近在做一个web前端的项目,其中有一个需求便是,如何将HTML与DOM互相转换。DOM ---> HTMLDOM向HTML的转换相对比较简单, 因为DOM节点是树状的,我们只需要利用递归遍历整个DOM树,就可以生成比较完整的HTML。在firebug中有一个相当完善的解决方案,其中对某些类型的节点做了escape, 如果你的生成的结果要求并不是那么严格的话,可以去...原创 2010-06-13 10:36:59 · 89 阅读 · 0 评论 -
动态规划算法
多阶段决策过程,是指这样的一类特殊的活动过程,问题可以按时间顺序分解成若干相互联系的阶段,在每一个阶段都要做出决策,全部过程的决策是一个决策序列。要使整个活动的总体效果达到最优的问题,称为多阶段决策问题。一个多阶段决策过程最优化问题的动态规划模型通常包含以下要素:1.阶段阶段(step)是对整个过程的自然划分。通常根据时间顺序或空间特征来划分阶段,以便按阶段的次序解优化问题...原创 2010-06-22 08:49:24 · 221 阅读 · 0 评论 -
java写的四则运算器
本打算做一个从RE到NFA的转换器,思路已经理清了,但是在动手做的时候,遇到了很多问题,有些技术难点都遗忘了,包括如何定义闭包,如何利用递归来实现。 于是回头重新拾起这些技术,边学边思考,做了个四则运算器练练手,为着那个大目标做准备。 基本的思路是这样的: 根据输入的四则运算表达式,生成一棵二叉树,树的根节点是操作符,而子树可能是叶子节点,即数字。也可能是另一个运算表...2011-08-19 22:19:18 · 198 阅读 · 0 评论 -
SquareDigits
Problem Statement ***Note: Please keep programs under 7000 characters in length. Thank youClass Name: SquareDigitsMethod Name: smallestResultParameters: intReturns: intDefine th...2010-07-06 12:36:27 · 127 阅读 · 0 评论 -
存储中间计算结果的动态规划算法
public class RodCutting { public static void main(String[] args) { int n = 5; int[] prices = new int[]{1, 4, 5, 6, 8}; long start = System.currentTimeMillis(); System.out.println(cu...原创 2012-04-18 15:50:48 · 306 阅读 · 0 评论 -
STRUTS2 源码 - Logging System
看了STRUTS2的源码,了解了它的logging系统,觉得还是蛮有意思的,用到了很多设计模式。 先看类结构图: 1. 工厂方法模式这个就不说了,直接明了。 2. 伪单例模式LoggerFactory是个抽象方法,同时里面也包含了对于LoggerFactory的伪单例实现。为什么是伪单例,因为看起来像是单例模式,但其实你也可以创建多个实例: ...原创 2012-05-24 08:51:52 · 158 阅读 · 0 评论 -
摩尔投票法
摩尔投票法 提问: 给定一个int型数组,找出该数组中出现次数最多的int值。 解决方案: 遍历该数组,统计每个int值出现次数,再遍历该集合,取出出现次数最大的int值。 这算是一个比较经典的解决办法,其中可能会用到Map来做统计。如果不使用Map,则时间复杂度会超过线性复杂度。除此之外,也没有什么特别好的办法。 今天在leetcode上遇到这样一道题目,...原创 2015-06-30 20:13:46 · 468 阅读 · 0 评论 -
数组双指针算法的研究
双指针算法在数组/链表操作中应用广泛,很多时候,为了完成某个目的,常常需要不断的循环检查数组或是链表,又或者需要拷贝出额外的存贮空间来保存中间结果。在其中的一些情况下,如果能够合理的应用数组双指针,则可以极大的减少算法的时间复杂度和空间复杂度。 根据初始双指针的位置,可以将之分为双头部指针,双尾部指针以及头尾指针. 今天我们就来看几个利用数组双指针算法的例子。 案例1:...原创 2015-07-14 16:59:28 · 322 阅读 · 0 评论 -
常见hash算法
感谢因特网提供的便利,暂时先放着,以后慢慢理解转载 http://www.partow.net/programming/hashfunctions/ [code="java"]/* ************************************************************************** * ...2010-04-23 14:33:21 · 153 阅读 · 0 评论 -
Hash算法(转载)
转载 http://www.iwms.net/n923c43.aspx---------------什么是 HashHash 的重要特性Hash 函数的实现主要的 Hash 算法Hash 算法的安全问题Hash 算法的应用结 论---------------Hash,一般翻译做“散列”,也有直接音译为"哈希" 的,就是把任意长度的输入(又叫做预映...2010-04-23 14:23:05 · 127 阅读 · 0 评论 -
排序算法总结
花了一个月时间学习了算法导论上的排序算法,学而不思则惘,现在把学习中的经验心得,都记录下来。排序 -- 交换排序 -- 冒泡排序 bubble sort -- 快速排序 quick sort -- 归并排序 -- 合并排序merge sort ...2010-04-16 10:09:32 · 89 阅读 · 0 评论 -
CraneWork
/*Problem Statement There are three stacks of crates - two of them outside of the warehouse, and one inside the warehouse. We have a crane that can move one crate at a time, and we would like to mo...2008-07-14 19:14:00 · 113 阅读 · 0 评论 -
SalesRouting
package salesRouting;/*Problem Statement You want to send a group of salespeople from location 0 to location 1, but no two of them can travel through the same location (other than 0 and 1). This remo...2008-07-15 10:53:00 · 75 阅读 · 0 评论 -
FactorialSystem
/*Problem StatementIn the factorial number system the value of the first digit (from the right) is 1!, the value of the second digit is 2!, ..., and the value of the n-th digit is n!. This means that ...2008-07-21 19:36:00 · 146 阅读 · 0 评论 -
RecurringNumbers
/*Problem StatementA rational number is defined as a/b, where a and b are integers, and b is greater than 0. Furthermore, a rational number can be written as a decimal that has a group of digits that ...2008-07-22 09:41:00 · 129 阅读 · 0 评论 -
HardDuplicateRemover
/*Problem StatementWe have a sequence of integers, and we would like to remove all duplicate elements from this sequence. There may be multiple ways to perform this task. For example, given the sequen...2008-07-23 15:17:00 · 81 阅读 · 0 评论 -
BlockStructure
/*Problem StatementA group of vertical blocks are placed densely one after another on the ground. The blocks each have a width of 1, but their heights may vary. For example, if the heights of the vert...2008-07-23 20:55:00 · 107 阅读 · 0 评论 -
TheaterVisit
/*Problem StatementYou want to buy two neighboring tickets in the first row of the theater so that one of the tickets is as far from the aisles as possible.You will be given a String describing the fi...2008-07-28 17:31:00 · 87 阅读 · 0 评论 -
SkipStones
/*Problem StatementWhen a stone is thrown across water, sometimes it will land on the water and bounce rather than falling in right away. Suppose that a stone is thrown a distance of n. On each succes...2008-07-28 17:31:00 · 422 阅读 · 0 评论 -
什么是最小二乘拟合
对于一个数据点(x1, y1), ... (xn, yn)的集合, 我们常常试图画一条线,它最能接近于这些数据代表的趋势, 使用最小二乘拟合,我们寻找一条形如y=mx+b的线,使得下面这个误差度量最小:(mxi + b - yi)2 叠加符号,打不出来.......2007-09-14 21:27:00 · 183 阅读 · 0 评论 -
汉诺塔的变种
1. 有三根柱子,在一根柱子上从下往上按大小顺序摞着n片圆盘。要求把圆盘从下面开始按大小顺序重新摆放在另一根柱子上。并且规定,在小圆盘上不能放大圆盘,在三根柱子之间一次只能移动一个圆盘。[code="java"]package hanoi;/** * formulas: * T0 = 0 * Tn = Tn-1 + 1 * * closed form: *...原创 2009-08-12 22:47:17 · 266 阅读 · 0 评论 -
逻辑思维游戏
请回答下面10个问题: 1。 第一个答案是b的问题是哪一个? (a)2;(b) 3;(c)4;(d)5;(e)6 2。唯一的连续两个具有相同答案的问题是: (a)2,3;(b)3,4;(c)4,5;(d)5,6;(e)6,7; 3。本问题答案和哪一个问题的答案相同? (a...2009-10-12 22:48:03 · 125 阅读 · 0 评论 -
(转)最长回文字串算法
来自(http://blog.163.com/zhaohai_1988/blog/static/2095100852012716105847112/) 最长回文子串 最长回文子串是最初我在网易笔试的时候遇见的,当时天真的把原字符串S倒转过来成为S‘,以为这样就将问题转化成为了求S和S’的最长公共子串的问题,而这个问题是典型的DP问题,我也...原创 2015-01-18 14:30:18 · 170 阅读 · 0 评论