
算法
文章平均质量分 65
辕门骁骑
这个作者很懒,什么都没留下…
展开
-
随机拉丁方阵(Random Latin squares)
大小为n的拉丁方阵是指各行列中的每个符号仅出现一次,随机拉丁方阵生成任意给定n个符号的随机输出。原创 2022-04-30 08:34:13 · 6659 阅读 · 1 评论 -
AVL树
在计算机科学中,AVL树是最早被发明的自平衡二叉查找树。在AVL树中,任一节点对应的两棵子树的最大高度差为1,因此它也被称为高度平衡树。查找、插入和删除在平均和最坏情况下的时间复杂度都是O(log n)。增加和删除元素的操作则可能需要借由一次或多次树旋转,以实现树的重新平衡。AVL树得名于它的发明者G. M. Adelson-Velsky和Evgenii Landis,他们在1962年的论文《An algorithm for the organization of information》中公开了这一数据结原创 2020-12-23 17:49:44 · 3619 阅读 · 0 评论 -
百囚徒问题(100 prisoners problem)
该问题由丹麦计算机科学家Peter Bro Miltersen于2003年首次提出。问题描述在监狱中有100名囚犯,被编号为1-100号。典狱长决定给囚犯们一次特赦的机会,条件是通过一项挑战。在一个房间中放着一个有100个抽屉的橱柜,里面随机放着与囚犯编号对应的1-100的号码牌。挑战开始后,每个囚犯依次进入该房间,打开不超过半数的抽屉,并从中找到与自己对应的号码则为成功,每名囚犯出去时该橱柜...原创 2020-04-30 11:09:59 · 13796 阅读 · 0 评论 -
Canny边缘检测算法(Canny edge detector)
Canny边缘检测算子是澳洲计算机科学家约翰·坎尼(John F. Canny)于1986年开发出来的一个多级边缘检测算法。算法步骤1. 降噪任何边缘检测算法都不可能在未经处理的原始数据上很好地处理,所以第一步是对原始数据与高斯平滑模板作卷积,得到的图像与原始图像相比有些轻微的模糊(blurred)。这样,单独的一个像素噪声在经过高斯平滑的图像上变得几乎没有影响。2. 寻找图像中的亮度梯度...原创 2020-04-17 14:35:33 · 17462 阅读 · 0 评论 -
排序算法——希尔排序
希尔排序是直接插入排序改进后更高效的一个版本,也称为缩小增量排序。希尔排序是把记录按下标的一定增量分组,对每组使用直接插入排序算法排序;随着增量逐渐减少,每组包含的关键词越来越多,当增量减至1时,整个文件恰被分成一组,算法便终止。希尔排序是基于插入排序的以下两点性质而提出改进方法的:插入排序在对几乎已经排好序的数据操作时,效率高,即可以达到线性排序的效率但插入排序一般来说是低效的,因为插...原创 2019-07-23 16:01:09 · 2206 阅读 · 0 评论 -
排序算法——堆排序
在介绍堆排序之前我们首先应该弄清楚堆排序可以解决什么问题,答案是显而易见的:排序。说得通俗点儿就是对一组无序的数字进行调整,使其按照从大到小或者从小大到的顺序有序排列。既然知道了堆排序的作用了,那么有的同学就会有疑问了,为什么“排序”前面加了“堆”呢?究竟什么是堆呢?这一节我们就详细了解什么是堆?如何利用堆进行排序?定义堆排序定义堆排序(Heapsort)是指利用堆这种数据结构所设计的一种...原创 2019-07-22 14:48:18 · 10809 阅读 · 0 评论 -
排序算法——睡眠排序(Sleep sort)【代码实现】
Bashfunction sleep_and_echo { sleep "$1" echo "$1"} for val in "$@"; do sleep_and_echo "$val" &done waitC#include <stdlib.h>#include <unistd.h>#include <sys/types....原创 2019-07-18 19:40:55 · 5030 阅读 · 1 评论 -
排序算法——希尔排序(Shell sort)【代码实现】
ActionScriptfunction shellSort(data:Array):Array{ var inc:uint = data.length/2; while(inc > 0) { for(var i:uint = inc; i< data.length; i++) { var tmp:Object = data[i]; for(var j:u...原创 2019-07-18 19:41:19 · 3407 阅读 · 0 评论 -
排序算法——基数排序(Radix sort)【代码实现】
C#include <stdio.h>#include <limits.h>#include <stdlib.h>#include <time.h> // Get size of statically allocated array#define ARR_LEN(ARR) (sizeof ARR / sizeof *ARR)// Ge...原创 2019-06-21 21:04:14 · 3502 阅读 · 0 评论 -
排序算法——全排序(Permutation sort)【代码实现】
ActionScript//recursively builds the permutations of permutable, appended to front, and returns the first sorted permutation it encountersfunction permutations(front:Array, permutable:Array):Array {...原创 2019-06-16 15:45:47 · 8964 阅读 · 0 评论 -
排序算法——耐心排序(Patience sort)【代码实现】
C#include<stdlib.h>#include<stdio.h> int* patienceSort(int* arr,int size){ int decks[size][size],i,j,min,pickedRow; int *count = (int*)calloc(sizeof(int),size),*sortedArr = (int*)m...原创 2019-06-17 22:24:55 · 4242 阅读 · 0 评论 -
排序算法——煎饼排序(Pancake sort)【代码实现】
Cint pancake_sort(int *list, unsigned int length){ //If it's less than 2 long, just return it as sorting isn't really needed... if(length<2) return 0; int i,a,max_num_pos,mo...原创 2019-06-16 22:23:31 · 3206 阅读 · 0 评论 -
排序算法——堆排序【代码实现】
伪代码function heapSort(a, count) is input: an unordered array a of length count (first place a in max-heap order) heapify(a, count) end := count - 1 while end > 0 do (swap t...原创 2019-06-15 20:15:55 · 2428 阅读 · 0 评论 -
排序算法——侏儒排序(Gnome sort)【代码实现】
伪代码function gnomeSort(a[0..size-1]) i := 1 j := 2 while i < size do if a[i-1] <= a[i] then // for descending sort, use >= for comparison i := j ...原创 2019-06-14 11:06:30 · 2402 阅读 · 0 评论 -
排序算法——计数排序【代码实现】
伪代码function countingSort(array, min, max): count: array of (max - min + 1) elements initialize count with 0 for each number in array do count[number - min] := count[number - min] ...原创 2019-06-15 13:46:05 · 6928 阅读 · 0 评论 -
排序算法——梳排序(Comb sort)【代码实现】
伪代码function combsort(array input) gap := input.size //initialize gap size loop until gap = 1 and swaps = 0 //update the gap value for a next comb. Below is an example gap := i...原创 2019-06-13 21:45:35 · 3492 阅读 · 0 评论 -
排序算法——鸡尾酒排序(Cocktail sort)【代码实现】
伪代码function cocktailSort( A : list of sortable items ) do swapped := false for each i in 0 to length( A ) - 2 do if A[ i ] > A[ i+1 ] then // test whether the two ...原创 2019-06-11 16:06:36 · 3899 阅读 · 0 评论 -
排序算法——圆形排序(Circle Sort)【代码实现】
伪代码function circlesort (index lo, index hi, swaps) { if lo == hi return (swaps) high := hi low := lo mid := int((hi-lo)/2) while lo < hi { if (value at lo) > (value at hi)...原创 2019-06-11 10:27:25 · 8863 阅读 · 0 评论 -
排序算法——选择排序【代码实现】
ActionScriptfunction selectionSort(input: Array):Array { //find the i'th element for (var i:uint = 0; i < input.length; i++) { //set minIndex to an arbitrary value var minIndex:uint=i; //f...原创 2019-06-09 11:23:32 · 11012 阅读 · 0 评论 -
排序算法——猴子排序(Bogosort)【代码实现】
伪代码while not InOrder(list) do Shuffle(list)done原创 2019-06-10 11:24:02 · 8563 阅读 · 0 评论 -
排序算法——珠排序(Bead sort)【代码实现】
C#include <stdio.h>#include <stdlib.h> void bead_sort(int *a, int len){ int i, j, max, sum; unsigned char *beads;# define BEAD(i, j) beads[i * max + j] for (i = 1, max = a[0]; i...原创 2019-06-09 10:46:54 · 6507 阅读 · 1 评论 -
排序算法——快速排序【代码实现】
伪代码function quicksort(array) less, equal, greater := three empty arrays if length(array) > 1 pivot := select any element of array for each x in array if x <...原创 2019-06-09 10:25:37 · 8836 阅读 · 0 评论 -
排序算法——插入排序【代码实现】
伪代码function insertionSort(array A) for i from 1 to length[A]-1 do value := A[i] j := i-1 while j >= 0 and A[j] > value do A[j+1] := A[j] j :...原创 2019-06-08 19:54:01 · 6280 阅读 · 0 评论 -
排序算法——冒泡排序
冒泡排序如果存在10个不同大小的气泡,那我们怎么快速的将这十个气泡排序呢,我们可以想象一下,由底至上地把较少的气泡逐步地向上升,这样经过遍历一次后,最小的气泡就会被上升到顶(下标为0),然后再从底至上地这样升,循环直至十个气泡大小有序。冒泡排序的定义冒泡排序是一种简单的排序算法。它重复地走访过要排序的数列,一次比较两个元素,如果他们的顺序错误就把他们交换过来。走访数列的工作是重复地进行直到没...原创 2019-06-08 19:22:40 · 10368 阅读 · 0 评论 -
排序算法——归并排序【代码实现】
伪代码function mergesort(m) var list left, right, result if length(m) ≤ 1 return m else var middle = length(m) / 2 for each x in m up to middle - 1 add x to left...原创 2019-06-08 19:03:15 · 7823 阅读 · 0 评论 -
排序算法——冒泡排序【代码实现】
伪代码repeat if itemCount <= 1 return hasChanged := false decrement itemCount repeat with index from 1 to itemCount if (item at index) > (item at (index + 1)) ...原创 2019-06-08 16:16:37 · 10830 阅读 · 0 评论 -
LZW(Lempel-Ziv-Welch)算法【代码实现】
C#include <stdio.h>#include <stdlib.h>#include <string.h>#include <stdint.h>#include <unistd.h>#include <fcntl.h>#include <sys/types.h>#include <sy...原创 2020-01-13 21:18:36 · 9623 阅读 · 0 评论 -
CRC-32【代码实现】
C#include <inttypes.h>#include <stdio.h>#include <string.h> uint32_trc_crc32(uint32_t crc, const char *buf, size_t len){ static uint32_t table[256]; static int have_table = ...原创 2019-11-10 18:07:42 · 11579 阅读 · 1 评论 -
布朗树(Brownian tree)【代码实现】
C#include <string.h>#include <stdlib.h>#include <time.h>#include <math.h>#include <FreeImage.h> #define NUM_PARTICLES 1000#define SIZE 800 void draw_...原创 2019-07-26 18:49:59 · 3431 阅读 · 0 评论 -
查找算法——二分查找【代码实现】
伪代码递归 // initially called with low = 0, high = N-1 BinarySearch(A[0..N-1], value, low, high) { // invariants: value > A[i] for all i < low value < A[i] for al...原创 2019-07-31 12:29:52 · 8074 阅读 · 0 评论 -
分形树(Fractal tree)【代码实现】
C#include <SDL/SDL.h>#ifdef WITH_CAIRO#include <cairo.h>#else#include <SDL/sge.h>#endif#include <cairo.h>#include <stdlib.h>#include <time.h>#include <...原创 2019-09-11 09:33:00 · 7260 阅读 · 0 评论 -
MD5算法【代码实现】
C#include <stdio.h>#include <stdlib.h>#include <string.h>#include <openssl/md5.h> const char *string = "The quick brown fox jumped over the lazy dog's back"; int main()...原创 2019-09-11 11:10:49 · 10538 阅读 · 0 评论 -
毕达哥拉斯树(Pythagoras tree)【代码实现】
C#include<graphics.h>#include<stdlib.h>#include<stdio.h>#include<time.h> typedef struct{ double x,y;}point; void pythagorasTree(point a,point b,int times){ point c...原创 2019-09-12 08:30:06 · 4450 阅读 · 0 评论 -
K-d tree【代码实现】
C#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>#include <time.h> #define MAX_DIM 3struct kd_node_t{ double x[MAX_DIM]; struct k...原创 2019-09-12 08:34:12 · 1736 阅读 · 1 评论 -
SHA-256算法【代码实现】
C#include <stdio.h>#include <string.h>#include <openssl/sha.h> int main (void) { const char *s = "Rosetta code"; unsigned char *d = SHA256(s, strlen(s), 0); int i; for (i ...原创 2019-09-13 15:39:23 · 9795 阅读 · 0 评论 -
SHA-1算法【代码实现】
C#include <stdio.h>#include <stdlib.h>#include <string.h>#include <openssl/sha.h> int main(){ int i; unsigned char result[SHA_DIGEST_LENGTH]; const char *string = ...原创 2019-09-13 15:39:47 · 9344 阅读 · 3 评论 -
平衡二叉树【代码实现】
C{ struct node *n = calloc(1, sizeof *n); *n = (struct node) { value, 1, {nnil, nnil} }; return n;} int max(int a, int b) { return a > b ? a : b; }inline void set_height(struct node *n) {...原创 2019-08-03 18:48:59 · 5851 阅读 · 0 评论