最新文章列表

Quick Sort

1.  Quicksort is honored as one of top 10 algorithms of 20th century in science and engineering. It's prevalent in practice, takes O(nlogn) time "on average" and works in place.   2.  ...
leonzhx 评论(0) 有1322人浏览 2013-03-10 11:45

怎么不开根号算平方根?

写一个函数,不用开根号算平方根。 这是网上一个题目,一开始一筹莫展,看了答案恍然大悟,就是用二分法去逼近。 const double error = 0.000000001f; double findSqrt(double t){ double high = t; double low = 0; while(high-low >= e ...
standalone 评论(0) 有2395人浏览 2012-12-24 22:55

迷宫寻路

写了一个小程序,使用BFS(宽度优先),GREED(贪婪算法),A*(启发式),GA(遗传算法)来解决迷宫寻路问题,大家看看算法有没有可以的改进的地方?源代码可以直接查看。 Demo地址: http://slab.sinaapp.com/pathfinder/ 由于使用了canvas来显示,所以请使用支持html5的浏览器来查看(chrome,firefox,IE9+等)。
sandy 评论(0) 有1448人浏览 2012-12-19 09:53

[转] 高效的产生一组不重复的随机数

原文地址: http://www.blogjava.net/lhulcn618/archive/2010/02/21/313522.html 需求描述:从 0 到 n 之间选 k 个不重复的数组成一个序列。 伪代码如下: for(i = 0; i < n; i++) { x[i] = i; } for(i = 0; i < k; i++) { t = r ...
yhz61010 评论(0) 有3398人浏览 2012-11-16 15:46

算法:去除字符串中的重复字母

问题:去除字符串中的重复字符,不能使用额外空间(1或者2个变量除外)。 很简单的练手题,但是发现很难写正确。 public class DuplicateChar { //return length of the final string public static int removeDuplicateChar(char []str){ int len = str.l ...
standalone 评论(2) 有3128人浏览 2012-11-06 22:50

找零钱问题

假设有25美分,10美分,5美分,1美分的硬币足够多,假设有N美分钱,问你怎么用这些硬币表示? 用perl重新做这个问题,前面用java做过 use strict; use warnings; my $count = 0; sub changes { my ($coins_ref, $factors_ref, $value) = @_; my @ ...
standalone 评论(0) 有1521人浏览 2012-10-29 15:59

怎样生成全排列?

我前面写过一种方法生成全排列,现在看用DP的方法解决。 参考How to generate permutations  看前面的那种解法。 DP的思路就是生成N个数的全排列,先考虑生成前面N-1个数字的全排列,然后把最后一个数字插入上一步每个结果的每个缝隙中,形成最后的结果。用perl比较好操纵数组,写起来的程序比较简单。(可惜这个博客不支持perl语法高亮啊) use strict; ...
standalone 评论(0) 有1296人浏览 2012-10-29 11:25

sierpinski triangle 2d in maya(with python API 2.0)

在国庆前我刚好完成手上的工作,有两三天的空闲,于是就去研究了一下分形就当是练习算法,谢尔宾斯基三角形就是其中一个,关于它可以看http://en.wikipedia.org/wiki/Sierpinski_triangle 这里我们使用掏(去)心法和python API 2.0来实现谢尔宾斯基三角形2d(还存在3d的)版本. 算法很简单 创建或得到一个三角形,等腰三角形最好,但不是等 ...
schi 评论(1) 有2038人浏览 2012-10-22 20:41

Print all binary search trees

Problem: Given numbers 1,2,3...N, print all binary search trees that can be constructed with these N numbers. Solution: package alg; import java.util.ArrayList; import java.util.Collections ...
standalone 评论(0) 有995人浏览 2012-10-16 17:01

Little-Known Awesome Algorithms: Fenwick Trees – Rapidly Find Cumulative Frequen

http://www.swageroo.com/wordpress/little-known-awesome-algorithms-fenwick-range-trees-rapidly-find-cumulative-frequency-sums/ This is to solve range query problems. Questions can be like below 引用Ima ...
standalone 评论(0) 有996人浏览 2012-09-28 17:28

find the subtree with max sum

Problem: Given a binary tree, each node has an integer value attached (can be negative), write code to find the subtree with the max sum. My solution: Basically this is a recursive problem, for each ...
standalone 评论(0) 有1349人浏览 2012-09-18 15:04

Analysis of Algorithms

1.  Scientific method of analyzing algorithm:   a)  Observe some feature of the natural world.   b)  Hypothesize a model that is consistent with the observations.   c)  Predict events using the hypo ...
leonzhx 评论(0) 有1276人浏览 2012-09-12 13:27

Union-Find

1. Dynamic Connectivity Problem :     a)  Union command : connect two objects     b)  Find/connected query: is there a path connecting the two objects?   2. Quick-find     a) Integer array id[] o ...
leonzhx 评论(0) 有1146人浏览 2012-09-12 08:44

Lock Free Stack

This example is copied from book "Java Concurrency in Practice". From this example we can learn that the lock free queue code is not correct for MPMC (multi-producer-multi-consumer) in my pr ...
standalone 评论(0) 有1154人浏览 2012-09-06 15:31

8-Queen Problem

Problem: Write an algorithm to print all ways of arranging eight queens on a chess board so that none of them share the same row, column or diagonal. My Code: _________________________________________ ...
standalone 评论(0) 有1457人浏览 2012-09-03 14:54

Number of ways to represent money

Problem: Given an infinite number of quarters (25 cents), dimes (10 cents), nickels (5 cents) and pennies (1 cent), write code to calculate the number of ways of representing n cents. My code: pack ...
standalone 评论(0) 有870人浏览 2012-09-03 11:34

Find all valid parentheses

Problem: Implement an algorithm to print all valid (e.g., properly opened and closed) combinations of n-pairs of parentheses. 给定一个正整数N,打印所有可能的N对括号序列,例子如下。 EXAMPLE: input: 3 (e.g., 3 pairs of parent ...
standalone 评论(0) 有1221人浏览 2012-09-02 16:56

Find the previous and next nearest number with same 1 bits

Problem: Given an integer, print the next smallest and next largest number that have the same number of 1 bits in their binary representation Solution from CareerCup book: public static boolean Ge ...
standalone 评论(0) 有1101人浏览 2012-09-01 15:14

最近博客热门TAG

Java(141747) C(73651) C++(68608) SQL(64571) C#(59609) XML(59133) HTML(59043) JavaScript(54918) .net(54785) Web(54513) 工作(54116) Linux(50906) Oracle(49876) 应用服务器(43288) Spring(40812) 编程(39454) Windows(39381) JSP(37542) MySQL(37268) 数据结构(36423)

博客人气排行榜

    博客电子书下载排行

      >>浏览更多下载

      相关资讯

      相关讨论

      Global site tag (gtag.js) - Google Analytics