最新文章列表

插入排序(包括希尔排序)及其变体

package com.algorithm; /** * 插入排序及其变体 * * List可转化为数组进行排序 * Object数组中的元素必须实现Comparable接口,即元素必须是可比的 */ public class InsertSort { /** * 直接插入排序 */ public static void insertS ...
zhouYunan2010 评论(0) 有1526人浏览 2011-10-24 18:17

Algorithm 05 : 给定一个数组,寻找第K大的数

给定一个无序数组,求数组中第K大的数。 答:求一个数组中第K大数可以借用快速排序算法的思想,主要思路如下:       (1)在数组中随机选择一个数作为支点。       (2)将比作为支点数大的所有数放在这个支点的左边,支点放在数组中间的位置。       (3)设支点左边元素的个数为L,那么可以分以下三种情况:               (a)当K=L的时候,直接返回支点即是所要求的第K大的 ...
YuHuang.Neil 评论(1) 有3089人浏览 2011-10-11 13:44

Algorithm 04 : 寻找两个有序数组中的第N个数,要求时间复杂度为O(logm+logn)

Question : Give a divide and conquer algorithm for the following problem : you are                  given two sorted lists of size m and n, and are allowed unit time access                  to the it ...
YuHuang.Neil 评论(0) 有2339人浏览 2011-10-04 21:32

Algorithm 03 : 合并两个有序数组

Question : Merge a sorted array of size n into another sorted array of size m+n. 问题:合并两个有序的数组,将一个长度为n的数组插入到指定的长度为m的数组中。 /** * @author YuHuang * @vision 2011-10-04 * This program is only ...
YuHuang.Neil 评论(0) 有981人浏览 2011-10-04 13:32

Algorithm 02 : 以K个元素为一组逆转链表

Question : Reverse a Linked List in groups of given size K. 问题:以K个元素为一组逆转链表。 /** * @author YuHuang * @vision 2011-10-03 * This program is only for algorithm training. * */ clas ...
YuHuang.Neil 评论(0) 有941人浏览 2011-10-03 22:29

Algorithm 01 : 寻找最长有序子序列

Question : To find max sorted contiguous subsequence of an Array. 问题:查找数组中的最长有序子序列。 /** * @author YuHuang * @vision 2011-10-03 * This program is only for algorithm training. * */ ...
YuHuang.Neil 评论(0) 有1178人浏览 2011-10-03 15:55

最优二叉树(哈弗曼树)

   提到哈弗曼树就必须提到节点权值,权值一般具有实际意义,比如此节点出现的概率,次数等。 必须提供权值才能构建出一棵哈弗曼树,因为哈弗曼树的定义为带权路径长度最小的二叉树。 树的带权路径长度为所有叶子节点的带权路径长度。 节点的带权路径长度为该节点到树的路径长度乘以节点权值。 哈希曼树最主要的应用是产生哈希曼编码。 为特点元素设计哈希曼编码要求二进制编码尽可能的短,并且任意一个字符的编码不是另外一 ...
zhouYunan2010 评论(0) 有3042人浏览 2011-10-01 15:38

归并排序(MergeSort) Java实现

归并排序的Java实现: import java.util.Arrays; public class MergeSort { public static void sort(Comparable[] data, int p, int r) { /* * p = 0; r = 3; total 4; * q = ...
hongjn 评论(0) 有3246人浏览 2011-09-17 21:31

经典算法——最长平台问题

经典最长平台算法 已知一个已经从小到大排序的数组,这个数组中的一个平台(Plateau)就是连续的一串值相同的元素,并且这一串元素不能再延伸。例如,在1,2,2,3,3,3,4,5,5,6中[1]、[2,2]、[3,3,3]、[4]、[5,5]、[6]都是平台。尝试编写一个程序,接受一个数组,把这个数组中最长的平台找出来。在上面的例子中3,3,3就是该数组中最长的平台。 要求: 1、使用的变量越 ...
YuHuang.Neil 评论(0) 有1074人浏览 2011-09-01 16:41

编程珠玑(1)

开始看了下编程珠玑,书的开篇就是一个排序的问题,今天就来实践一下,稍作修改,如题目大意:生成1千万个1亿以内的不重复的数据集合. public final static int count = 100000000; private static boolean[] collect = new boolean[count]; private static int[] source = new ...
zhoucl 评论(1) 有1175人浏览 2011-08-29 14:10

[转载 + 实现] 只有10%程序员能正确实现二分查找算法

在CSDN看到一篇题为《只有10%程序员能正确实现二分查找算法》的文章(原文链接http://news.csdn.net/a/20100423/218099.html),很有意思,在不进行测试的情况下, ...
lony1107 评论(1) 有1198人浏览 2011-08-28 13:03

Threaded Binary Tree

#include <stdio.h> enum pointer_tag { LINK, THREAD }; struct node { char* data; struct node* lchild; struct node* rchild; enum pointer_tag ltag, rtag; }; void visit(char* ...
yaojingguo 评论(0) 有940人浏览 2011-07-17 22:23

Solution to 10.4-6 in Introduction to Algorithms, Third Edition

#include <stdio.h> #define RIGHT_SIBLING 0 #define PARENT 1 #define NIL 0 struct node { int key; struct node* left_child; struct node* p; int flag; }; int visit_paren ...
yaojingguo 评论(0) 有1337人浏览 2011-07-15 15:45

Solution to 10.4-5 in Introduction to Algorithms, Third Edition

  #include <stdio.h> #define TRAVERSE 0 #define LEFT_BACKTRACK 1 #define RIGHT_BACKTRACK 2 struct node { int key; struct node* p; struct node* left; struct node *right; }; ...
yaojingguo 评论(0) 有1783人浏览 2011-07-15 13:36

Solution to 10.3-5 in Introduction to Algorithms, Third Edition

  #include <stdio.h> int next[9]; int key[9]; int prev[9]; int L; int F; void print_array(); void print_list(int); void print_lists(); void create(); void exchange(int, int); void ...
yaojingguo 评论(0) 有1333人浏览 2011-07-13 18:43

0/1背包问题动态规划的Ruby实现

  # encoding:utf-8 # ruby1.9是用ASCII编码来读源码的, http://zires.info/2011/03/17/invalid-multibyte-char-us-ascii-ruby1-9/ class KnapSack attr_reader :weight, :value attr_writer :weight, :value ...
Mr.Chris 评论(0) 有2156人浏览 2011-07-03 13:42

Randomize-In-Place

  #include <stdlib.h> #include <stdio.h> void swap(int *a, int *b) { int temp; temp = *a; *a = *b; *b = temp; } void info(int arr[], int len) { int i; for (i = 0; ...
yaojingguo 评论(0) 有958人浏览 2011-06-01 22:43

计算数组元素的乘积

Given an array a[i], your task is to generate an array b[i], b[i] is the product of the numbers in the array except the i th number.   My solution:   DP problem?   Define two functions: f(i)=a[ ...
standalone 评论(0) 有1106人浏览 2010-11-03 20:56

最近博客热门TAG

Java(141744) C(73651) C++(68608) SQL(64571) C#(59609) XML(59133) HTML(59043) JavaScript(54919) .net(54785) Web(54514) 工作(54118) Linux(50905) Oracle(49875) 应用服务器(43289) Spring(40812) 编程(39454) Windows(39381) JSP(37542) MySQL(37267) 数据结构(36424)

博客人气排行榜

    博客电子书下载排行

      >>浏览更多下载

      相关资讯

      相关讨论

      Global site tag (gtag.js) - Google Analytics