本月博客排行
-
第1名
龙儿筝 -
第2名
johnsmith9th -
第3名
wy_19921005 - zysnba
- sgqt
- lemonhandsome
年度博客排行
-
第1名
宏天软件 -
第2名
青否云后端云 -
第3名
龙儿筝 - gashero
- wallimn
- vipbooks
- benladeng5225
- wy_19921005
- fantaxy025025
- e_e
- zysnba
- ssydxa219
- sam123456gz
- javashop
- arpenker
- tanling8334
- kaizi1992
- xpenxpen
- wiseboyloves
- xiangjie88
- ranbuijj
- ganxueyun
- xyuma
- sichunli_030
- wangchen.ily
- jh108020
- lemonhandsome
- zxq_2017
- jbosscn
- Xeden
- luxurioust
- johnsmith9th
- lzyfn123
- zhanjia
- forestqqqq
- ajinn
- nychen2000
- wjianwei666
- hanbaohong
- daizj
- 喧嚣求静
- mwhgJava
- silverend
- kingwell.leng
- lchb139128
- lich0079
- kristy_yy
- jveqi
- java-007
- sunj
最新文章列表
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. ...
怎么不开根号算平方根?
写一个函数,不用开根号算平方根。
这是网上一个题目,一开始一筹莫展,看了答案恍然大悟,就是用二分法去逼近。
const double error = 0.000000001f;
double findSqrt(double t){
double high = t;
double low = 0;
while(high-low >= e ...
算法:去除字符串中的重复字母
问题:去除字符串中的重复字符,不能使用额外空间(1或者2个变量除外)。
很简单的练手题,但是发现很难写正确。
public class DuplicateChar {
//return length of the final string
public static int removeDuplicateChar(char []str){
int len = str.l ...
找零钱问题
假设有25美分,10美分,5美分,1美分的硬币足够多,假设有N美分钱,问你怎么用这些硬币表示?
用perl重新做这个问题,前面用java做过
use strict;
use warnings;
my $count = 0;
sub changes {
my ($coins_ref, $factors_ref, $value) = @_;
my @ ...
怎样生成全排列?
我前面写过一种方法生成全排列,现在看用DP的方法解决。
参考How to generate permutations 看前面的那种解法。
DP的思路就是生成N个数的全排列,先考虑生成前面N-1个数字的全排列,然后把最后一个数字插入上一步每个结果的每个缝隙中,形成最后的结果。用perl比较好操纵数组,写起来的程序比较简单。(可惜这个博客不支持perl语法高亮啊)
use strict; ...
sierpinski triangle 2d in maya(with python API 2.0)
在国庆前我刚好完成手上的工作,有两三天的空闲,于是就去研究了一下分形就当是练习算法,谢尔宾斯基三角形就是其中一个,关于它可以看http://en.wikipedia.org/wiki/Sierpinski_triangle
这里我们使用掏(去)心法和python API 2.0来实现谢尔宾斯基三角形2d(还存在3d的)版本.
算法很简单
创建或得到一个三角形,等腰三角形最好,但不是等 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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:
_________________________________________ ...
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 ...
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 ...
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 ...