一些有意思的算法代码[转载]

转载自:http://coolshell.cn/articles/6010.html

 

Keith Schwarz是一个斯坦福大学计算机科学系的讲师。他对编程充满了热情。他的主页上他自己正在实现各种各样的有意思的算法和数据结构,http://www.keithschwarz.com/interesting/, 目前这个网页上有88个(见下面的列表),但这位大哥要干135个,你可以看看他的To-Do List。

从这个列表上,我们可以看到,他从去年7月份就在自己实现这些东西了,我把他实现的这些算法转过来,

  • 一方面我们可以学习一下这些算法和代码,因为很多东西对我来说都比较新,我以前列举过一些经典的算法,算法和数据结构词典,还有可视化的数据结构和算法, 不过感觉都没有这个全。
  • 另一方面我希望这个事可以影响到一些正在学习编程的人。看看别人是怎么学习编程的,希望对你有借鉴作用。
NameLinkDate AddedLanguageDescription
Binomial Heap(link)7‑24‑2010C++An implementation of a binomial heap data structure for use as a priority queue.
Bounded Priority Queue(link)7‑24‑2010C++An implementation of a priority queue with a fixed upper limit to its size..
Matrix(link)7‑24‑2010C++A collection of classes for manipulating matrices.
VList(link)8‑16‑2010JavaAn implementation of the List abstraction backed by a VList.
Function Wrapper(link)8‑16‑2010C++A C++ wrapper class around unary functions.
String(link)8‑17‑2010C++An implementation of a string abstraction that uses the small string optimization.

 

nstream(link)8‑31‑2010C++An stream class that sends and receives data over a network.
Snake(link)8‑31‑2010C++An implementation of the game Snake with a rudimentary AI.
Mergesort(link)9‑14‑2010C++An implementation of the mergesort algorithm.
Next Permutation(link)10‑6‑2010C++An implementation of the next_permutation STL algorithm.
Interval Heap(link)10‑17‑2010JavaAn implementation of a double-ended priority queue using an interval heap.
Linear-Time Selection(link)10‑18‑2010C++A deterministic, linear-time selection algorithm using the median-of-medians algorithm.
Heapsort(link)10‑18‑2010C++An implementation of the heapsort algorithm.
Union-Find(link)10‑19‑2010JavaAn implementation of a disjoint-set data structure using a disjoint set forest.
Radix Sort(link)10‑19‑2010C++An implementation of the radix sort algorithm.
Rational(link)10‑23‑2010C++A data structure representing a rational number.
DPLL(link)10‑23‑2010HaskellAn implementation of the DPLL algorithm for solving CNF-SAT.
Smoothsort(link)10‑27‑2010C++An implementation of the smoothsort algorithm, an adaptive heapsort variant.
Extendible Array(link)10‑28‑2010JavaA dynamic array class with O(1) worst-case runtime lookup and append.
In-Place Merge(link)10‑29‑2010C++An implementation of a merge algorithm that runs in-place.
Random Shuffle(link)10‑29‑2010C++An algorithm for generating a random permutation of a set of elements.
Random Sample(link)10‑29‑2010C++An O(n) time, O(1) space algorithm for randomly choosing k elements out of a stream with uniform probability.
Natural Mergesort(link)10‑30‑2010C++An implementation of natural mergesort, an adaptive variant of mergesort.
Interpolation Search(link)10‑31‑2010C++An implementation of the interpolation search algorithm.
Introsort(link)10‑31‑2010C++An implementation of the introsort algorithm, a fast hybrid of quicksort, heapsort, andinsertion sort.
Hashed Array Tree(link)11‑3‑2010JavaAn implementation of a dynamic array backed by a hashed array tree.
Recurrence Solver(link)11‑13‑2010C++A fast algorithm for generating terms of a sequence defined by a linear recurrence relation.
Fibonacci Heap(link)11‑15‑2010JavaAn implementation of a priority queue backed by a Fibonacci heap.
Dijkstra’s Algorithm(link)11‑16‑2010JavaAn implementation of Dijkstra’s algorithm for single-source shortest paths.
Prim’s Algorithm(link)11‑17‑2010JavaAn implementation of Prim’s algorithm for computing minimum spanning trees.
Kruskal’s Algorithm(link)11‑17‑2010JavaAn implementation of Kruskal’s algorithm for computing minimum spanning trees.
Majority Element(link)11‑17‑2010C++A fast, linear-time algorithm for finding the majority element of a data set.
Haar Transform(link)11‑17‑2010C++A set of functions to decompose a sequence of values into a sum of Haar wavelets.
Argmax(link)11‑19‑2010C++A pair of functions to compute the arg min or max of a function on some range.
Derivative(link)11‑19‑2010C++A function object that approximates the derivative of a function.
Levenshtein Distance(link)11‑19‑2010C++An algorithm for computing the Levenshtein distance between two sequences.
Skiplist(link)11‑20‑2010C++An implementation of a skip list, a randomized data structure for maintaining a sorted collection.
van Emde Boas Tree(link)11‑26‑2010C++An implementation of a sorted associative array backed by a van Emde Boas tree.
Cuckoo HashMap(link)11‑27‑2010JavaAn implementation of a hash table using cuckoo hashing.
Needleman-Wunsch Algorithm(link)11‑28‑2010C++An implementation of the Needleman-Wunsch algorithm for optimal string alignment.
Treap(link)11‑28‑2010C++An implementation of a sorted associative array backed by a treap.
Floyd-Warshall Algorithm(link)12‑10‑2010JavaAn implementation of the Floyd-Warshall algorithm for all-pairs shortest paths in a graph.
Power Iteration(link)12‑10‑2010C++An implementation of the power iteration algorithm for finding dominant eigenvectors.
Edmonds’s Matching Algorithm(link)12‑15‑2010JavaAn implementation of Edmonds’s matching algorithm for finding maximum matchings in undirected graphs.
Kosaraju’s Algorithm(link)12‑15‑2010JavaAn implementation of Kosaraju’s algorithm algorithm for finding strongly connected components of a directed graph.
2-SAT(link)12‑15‑2010JavaA linear-time algorithm for solving 2-SAT.
Bellman-Ford Algorithm(link)12‑17‑2010JavaAn implementation of the Bellman-Ford algorithm for single-source shortest paths.
Topological Sort(link)12‑17‑2010JavaAn algorithm for computing a topological sort of a directed acyclic graph.
Graham Scan(link)12‑19‑2010C++An implementation of the Graham scan for finding convex hulls in 2D space.
Bipartite Testing(link)12‑19‑2010JavaA linear-time algorithm for checking whether a directed graph is bipartite.
Johnson’s Algorithm(link)12‑19‑2010JavaAn implementation of Johnson’s algorithm for all-pairs shortest paths.
Strassen Algorithm(link)12‑20‑2010C++An implementation of the Strassen algorithm for fast matrix multiplication.
Cartesian Tree Sort(link)12‑21‑2010C++An implementation of Cartesian tree sort, an adaptive, out-of-place heapsort variant.
Ford-Fulkerson Algorithm(link)12‑21‑2010JavaAn implementation of the Ford-Fulkerson maximum-flow algorithm.
Scaling Ford-Fulkerson(link)12‑22‑2010JavaAn modification of the Ford-Fulkerson maximum-flow algorithm that uses scaling to achieve polynomial time..
Splay Tree(link)12‑27‑2010C++An implementation of a sorted associative array backed by a splay tree.
Ternary Search Tree(link)12‑28‑2010C++An implementation of a sorted set of strings backed by a ternary search tree.
Ring Buffer(link)12‑30‑2010JavaAn implementation of a FIFO queue using a ring buffer.
AVL Tree(link)12‑30‑2010C++A sorted associative container backed by an AVL tree.
Rabin-Karp Algorithm(link)1‑1‑2011C++An implementation of the Rabin-Karp algorithm for string matching.
RPN Evaluator(link)1‑18‑2011C++ / strainA library to tokenize and evaluate simple arithmetic expressions in reverse Polish notation.
Shunting-Yard Algorithm(link)1‑18‑2011C++ / strainAn implementation of Dijkstra’s shunting-yard algorithm for converting infix expressions to reverse-Polish notation.
Skew Binomial Heap(link)1‑20‑2011C++An implementation of a priority queue backed by a skew binomial heap.
2/3 Heap(link)3‑1‑2011C++An implementation of a priority queue whose branching factor alternates at different levels to maximize performance.
Zeckendorf Logarithm(link)3‑10‑2011C++An algorithm based on Zeckendorf representations that efficiently computes logarithms.
Factoradic Permutations(link)3‑17‑2011C++A set of algorithms for generating permutations using the factoradic number system.
Binary Cyclic Subsets(link)3‑20‑2011C++A set of algorithms for generating subsets in lexicographical order using binary numbers and cyclic shifts.
Fibonacci Iterator(link)3‑22‑2011C++An STL-style iterator for iterating over the Fibonacci numbers.
Fibonacci Search(link)3‑22‑2011C++An implementation of the Fibonacci search algorithm.
Euclid’s Algorithm(link)4‑18‑2011HaskellAn implementation of Euclid’s algorithm and applications to continued fractions and the extended Euclidean algorithm.
Find Duplicate(link)4‑18‑2011PythonAn algorithm to find a repeated element in an array using Floyd’s cycle-finding algorithm.
Permutation Generator(link)4‑19‑2011PythonA generator for producing all permutations of a list of elements.
Matrix Find(link)4‑19‑2011PythonA solution to the classic interview question of searching a sorted matrix for a particular value.
Binary GCD(link)4‑23‑2011SchemeAn implementation of the binary GCD algorithm for computing greatest common divisors of nonnegative integers.
Knuth-Morris-Pratt Algorithm(link)5‑3‑2011PythonAn implementation of the Knuth-Morris-Pratt algorithm for fast string matching.
Kadane’s Algorithm(link)5‑7‑2011C++An implementation of Kadane’s algorithm for solving the maximum-weight subarray problem.
Karatsuba’s Algorithm(link)8‑15‑2011PythonAn implementation of Karatsuba’s algorithm for fast integer multiplication.
Min-Stack(link)8‑15‑2011C++An implementation of a LIFO stack that supports O(1) push, pop, and find-minimum.
Random Bag(link)8‑15‑2011PythonA data structure that supports insertion and removal of a uniformly-random element.
Min-Queue(link)8‑15‑2011C++An implementation of a FIFO queue that supports O(1) push, pop, and find-minimum.
Lights-Out Solver(link)8‑29‑2011C++A solver for the game Lights Out using Gaussian elimination over GF(2).
Maximum Single-Sell Profit(link)11‑9‑2011PythonFour algorithms for the maximum single-sell profit problem, each showing off a different algorithmic technique.
Generalized Kadane’s Algorithm(link)11‑10‑2011C++A generalization of Kadane’s algorithm for solving the maximum subarray problem subject to a length restriction.
Longest Range(link)11‑19‑2011JavaAn algorithm for solving the longest contiguous range problem.
Egyptian Fractions(link)11‑20‑2011PythonAn implementation of the greedy algorithm for finding Egyptian fractions.
LL(1) Parser Generator(link)11‑21‑2011JavaAn LL(1) parser generator.
LR(0) Parser Generator(link)11‑23‑2011JavaAn LR(0) parser generator.
Word Ladders(link)11‑27‑2011JavaScriptA program for finding word ladders between two words.

转载于:https://www.cnblogs.com/wufawei/archive/2011/12/18/2291650.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/297666.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

python web前端开发面试_面试前端,听听别人怎么说!

分享一个人的面试经验:一年半经验,百度、有赞、阿里面试总结前言人家都说,前端需要每年定期出来面面试,衡量一下自己当前的技术水平以及价值,本人17年7月份,毕业到现在都没出来试过,也没很想换工…

requestmapping注解访问404_【框架】127:几个非常重要的注解

今天是刘小爱自学Java的第127天。感谢你的观看,谢谢你。今天的知识点有点多,有点记不过来了。学习内容安排如下:使用注解优化昨天写的springMVC入门程序。映射路径各种风格的学习,也就对应了注解RequestMapping中的参数。各种类型…

Dapr + .NET Core实战(二) 服务调用

服务调用是什么在分布式应用程序中的服务之间进行调用会涉及到许多挑战。例如:维护其他服务的地址。如何安全地调用服务。在发生短暂的 暂时性错误 时如何处理重试。分布式应用程序调用链路追踪。服务调用构建块通过使用 Dapr 挎斗作为服务的 反向代理 来解决这些难…

华为新员工入职时信息安全保密手册

一、新员工入职信息安全须知 新员工入职后,在信息安全方面有哪些注意事项? 接受“信息安全与保密意识”培训; 每年应至少参加一次信息安全网上考试; 办理员工卡; 签署劳动合同(含保密职责)&…

第五周项目2-对象作为数据成员

回想Engineer类的数据成员,有眼镜、背包等。某Engineer的眼镜、背包,是Glass、Bag类的对象。类中的数据成员,其类型可以是简单类型,也可以是类。通过这种方式,将某些类组合到另外的类中,当作其中的一个“部…

谷歌排名第一的编程语言,死磕它这两点,小白也能学的会!不信你看!

全世界只有3.14 % 的人关注了爆炸吧知识谷歌排名第一的编程语言时什么?毫无疑问:肯定是 Python。也难怪,作为大数据时代和人工智能时代的必备语言,Python 的优点太多了,语言简洁、易学、开发效率高、可移植性强......另…

android主动显示流程,Activity加载显示基本流程

本文章是基于Android源码6.0讲解Activity加载显示基本流程首先上一张图给大家一个直观的了解首先一个布局页面的加载是在Activity中的setContentView(R.layout.res)开始;我们就从Acitvity源码中的setContentView方法入手public void setContentView(LayoutRes int layoutResID)…

VIM之Project 项目管理工具

VIM是Linux和Unix下常用的文本编辑工具,在编写代码和阅读代码中经常使用。但VIM进行代码项目管理时,没有IDE集成开发工具方便,现在提供一个VIM插件Project,可以对代码项目进行简单的集中管理一、 下载安装1、 在 Vim 网站上下载最…

vue数组刷新_Vue数组更新方法

Vue的核心是数据与视图的双向绑定,当我们修改数组时,Vue会检测到数据变化,所以用v-for渲染的视图也会立即更新。Vue包含了一组观察数组变异的方法,使用他们改变数组也会触发视图更新。push()pop()shift()unshift()splice()sort()r…

python提供什么机制处理程序运行错误_浅谈Python异常处理机制

异常机制己经成为衡量一门编程语言是否成熟的标准之一,使用异常处理机制的 Python 程序有更好的容错性,更加健壮。 对于计算机程序而言,情况就更复杂了一一没有人能保证自己写的程序永远不会出辛苦!就算程序没有错误,你…

WPF DataGrid 通过自定义表头模拟首行固定

WPF DataGrid 通过自定义表头模拟首行固定独立观察员 2021 年 9 月 25 日最近工作中要在 WPF 中做个表格,自然首选就是 DataGrid 控件了。问题是,UI 设计的表格是在首行有一个新增按钮,那一行样式和其它数据行是一样的,就在表头下…

python和C语言分别实现插入排序

python语言代码:代码1 defInsertSort(numbers,n):2 fori inrange(1,n):3 j i-14 tem numbers[i]5 whilenumbers[j]>tem andj>0:6 numbers[j1] numbers[j]7 j -18 else:9 numbers[j1] tem10 print"Onthe sort:",numbers11 12 a [9,8,7,6,5,4,3,2,1,0…

Windows用户安全小技巧

本文适用于具有管理员用户和标准用户的所有Windows系统,如Windows 2000以上的操作系统,UAC是Windows Vista以上版本的具有功能。新安装的Windows系统或者新购买的含有Windows系统计算机一开始都需要安装许多软件并需要设置较多的含有Windows安全或用户控…

根据url获取html源码,通过URL访问和获取html源代码

Uniform Resource Locator ,在Internet的WWW服务程序上用于指定信息位置的表示方法指定互联网或本地上(web服务中)的文件、对象资源 等,或者说它相当于一个互联网上资源的一个指针协议 主机 路径 资源http://www.itfuture.org/forum/index.jsp …

从网恋到失恋只需要一秒...

1 原来放下一个人如此简单...▼2 而且到现在衣服都没找到▼3 这东西叫糖醋液,实验室比例是:糖:醋:酒:水1:2:3:4▼4 老师:这孩子真有原则▼5 呵,绝交吧▼…

Log4net数据表

USE [ASPNETDB] GO /****** 对象: Table [dbo].[Log] 脚本日期: 12/21/2011 22:41:53 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[Log]([ID] [int] IDENTITY(1,1) NOT NULL,[Date] [datetime] NOT NULL,[Threa…

go float64 比较_Go 每日一库之 plot

Go 每日一库之 plot简介本文介绍 Go 语言的一个非常强大、好用的绘图库——plot。plot内置了很多常用的组件,基本满足日常需求。同时,它也提供了定制化的接口,可以实现我们的个性化需求。plot主要用于将数据可视化,便于我们观察、…

大前端快闪:package.json文件知多少?

最近在公司某项目参与了一些前端工作,作为后端抠脚大汉,改点前端细节磕磕绊绊,改点大前端、工程化、HTTP交互倒也还能做到柳暗花明。于是打算用后端程序猿的视角记录一些{大前端}的知识快闪,也算是帮助读者构建完整的全栈技能体系…

大牛C++编程开发学习建议50条

2019独角兽企业重金招聘Python工程师标准>>> 每个从事C开发的朋友相信都能给后来者一些建议,但是真正为此进行大致总结的很少。本文就给出了网上流传的对C编程开发学习的50条建议,总结的还是相当不错的,编程学习者(不仅…

JQuery函数在IE浏览器中测试的注意事项

这几天刚学JQuery,在测试hide,show,slideToggle函数的时候,在firefox浏览器都很正常,而在IE浏览器里面却出现一些动画异常。这些过渡效果快结束的时候,都出现了一些跳动的现象,例如我对一个段落…