![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Algorithm
文章平均质量分 81
puffsun
这个作者很懒,什么都没留下…
展开
-
MapReduce Algorithm - Secondary Sort
Secondary sort is used to sort to allow some records to arrive at a reducer ahead of other records, it requires an understanding of both data arrangement and data flow (partitioning, sorting and gro...原创 2013-07-25 19:34:46 · 145 阅读 · 0 评论 -
基础数据结构和算法九:Binary Search Tree
A binary search tree (BST) is a binary tree where each node has a Comparable key (and an associated value) and satisfies the restriction that the key in any node is larger than the keys in all no...原创 2013-11-28 22:39:46 · 202 阅读 · 0 评论 -
基础数据结构和算法八:Binary search
Binary search needs an ordered array so that it can use array indexing to dramatically reduce the number of compares required for each search, using the classic and venerable binary search algorithm...原创 2013-11-28 21:21:41 · 184 阅读 · 0 评论 -
Overview of MapReduce Algorithm Design
Although the programming model of MapReduce framework force one to express algorithms in terms of a small set of rigidly defined components, there are many tools at one's disposal to shape the flow ...原创 2013-07-11 09:32:02 · 80 阅读 · 0 评论 -
MapReduce Algorithm - Reduce-side Join
Reduce-side join is also known as repartition join. The idea is quite simple: we map over both datasets and emit the join key as the intermediate key, and the tuple itself as the intermediate value....原创 2013-07-11 08:46:26 · 69 阅读 · 0 评论 -
MapReduce Algorithm - in Map Combining
In this blog post, I will demonstrate severval techniques for local aggregation using the sample word count example. The original WordCount example comes from Hadoop examples. But I'll try to improv...原创 2013-07-10 22:38:12 · 129 阅读 · 0 评论 -
基础数据结构和算法七:Priority queue & Heap sort
Some important applications of priority queues include simulation systems, where the keys correspond to event times, to be processed in chronological order; job scheduling, where the keys correspond...原创 2013-11-27 19:47:59 · 347 阅读 · 0 评论 -
基础数据结构和算法六:Quick sort
Quick sort is probably used more widely than any other. It is popular because it is not difficult to implement, works well for a variety of different kinds of input data, and is substantially faster...原创 2013-11-21 19:33:14 · 221 阅读 · 0 评论 -
基础数据结构和算法五:Merge sort
One of mergesort’s most attractive properties is that it guarantees to sort any array of N items in time proportional to N * log N. Its prime disadvantage is that it uses extra space proportional...原创 2013-11-20 21:44:40 · 220 阅读 · 0 评论 -
基础数据结构和算法十:2-3 search tree
Binary search tree works well for a wide variety of applications, but they have poor worst-case performance. Now we introduce a type of binary search tree where costs are guaranteed to be logarit...原创 2013-11-30 11:07:02 · 355 阅读 · 0 评论 -
基础数据结构和算法十一:Red-black binary search tree
The insertion algorithm for 2-3 trees just described is not difficult to understand; now, we will see that it is also not difficult to implement. We will consider a simple representation known as...原创 2013-12-01 12:12:35 · 230 阅读 · 0 评论 -
MapReduce Algorithm - Semi-joins
In relational world, semi-join can be defined as a join between two tables returns rows from the first table where one or more matches are found in the second table. The difference between a semi-jo...原创 2013-07-25 18:15:04 · 79 阅读 · 0 评论 -
MapReduce Algorithm - Another Way to Do Map-side Join
Map-side join is also known as replicated join, and gets is name from the fact that the smallest of the datasets is replicated to all the map hosts. You can find a implementation in Hadoop in Action...原创 2013-07-25 17:51:08 · 132 阅读 · 0 评论 -
基础数据结构和算法十四:Directed Graphs
In directed graphs, edges are one-way: the pair of vertices that defines each edge is an ordered pair that specifies a one-way adjacency. Many applications (for example, graphs that represent the ...原创 2013-12-15 22:40:30 · 889 阅读 · 0 评论 -
基础数据结构和算法十三:Undirected Graphs (2)
Design pattern for graph processing. Since we consider a large number of graph-processing algorithms, our initial design goal is to decouple our implementations from the graph representation. T...原创 2013-12-13 22:51:29 · 255 阅读 · 0 评论 -
基础数据结构和算法十三:Undirected Graphs
A graph is a set of vertices and a collection of edges that each connect a pair of vertices. Vertex names are not important to the definition, but we need a way to refer to vertices. By convention, ...原创 2013-12-13 20:15:59 · 337 阅读 · 0 评论 -
PageRank Algorithm in MapReduce
In chapter 5 of Data-Intensive Text Processing with MapReduce, it introduces how to implement PageRank algorithm in MapReduce way. Here I am not going to talk more about PageRank itself, please refe...原创 2013-07-14 12:12:29 · 148 阅读 · 0 评论 -
Breadth-first Graph Search in MapReduce
In chapter 5 of the book "Data-Intensive Text Processing with MapReduce", it introduced how to parallel breadth-first graph search with MapReduce. This parallel algorithm is a variant of Dijkstra's ...原创 2013-07-13 20:44:43 · 132 阅读 · 0 评论 -
基础数据结构和算法十二:Hash table
Search algorithms that use hashing consist of two separate parts. The first part is to compute a hash function that transforms the search key into an array index. Ideally, different keys would map...原创 2013-12-02 22:06:01 · 205 阅读 · 0 评论 -
基础数据结构和算法四:Shell sort
Shellsort is a simple extension of insertion sort that gains speed by allowing exchanges of array entries that are far apart, to produce partially sorted arrays that can be efficiently sorted, ev...原创 2013-11-20 19:11:30 · 165 阅读 · 0 评论 -
Comparing two sorting algorithms
Generally we compare algorithms by■ Implementing and debugging them■ Analyzing their basic properties■ Formulating a hypothesis about comparative performance■ Running experiments to validate...原创 2013-11-19 21:16:59 · 113 阅读 · 0 评论 -
基础数据结构和算法三:Insertion Sort
As in selection sort, the items to the left of the current index are in sorted order during the sort, but they are not in their final position, as they may have to be moved to make room for smaller ...原创 2013-11-19 21:06:47 · 161 阅读 · 0 评论 -
Shell Sort in Java
基本思想: 先取一个小于n的整数d1作为第一个增量,把文件的全部记录分成d1个组。所有距离为dl的倍数的记录放在同一个组中。先在各组内进行直接插人排序;然后,取第二个增量d2<d1重复上述的分组和排序,直至所取的增量dt=1(dt<dt-l<…<d2<d1),即所有记录放在同一组中进行直接插入排序为止。 该方法实质上是一种分组插入方法。import ...原创 2011-12-01 21:54:10 · 64 阅读 · 0 评论 -
组合的问题,递归实现
输入一个字符串,输出该字符串中字符的所有组合。举个例子,如果输入abc,它的组合有a、b、c、ab、ac、bc、abc。假设我们想在长度为n的字符串中求m个字符的组合。我们先从头扫描字符串的第一个字符。针对第一个字符,我们有两种选择:一是把这个字符放到组合中去,接下来我们需要在剩下的n-1个字符中选取m-1个字符;二是不把这个字符放到组合中去,接下来我们需要在剩下的n-1个字符中选择m个...原创 2011-11-30 22:58:48 · 78 阅读 · 0 评论 -
递归实现背包问题-Java
Java递归实现背包问题:问题描述: 有N件物品和一个容量为V的背包。第i件物品的费用是c,价值是w。求解将哪些物品装入背包可 使这些物品的费用总和不超过背包容量,且价值总和最大。 基本思路: 这是最基础的背包问题,特点是:每种物品仅有一件,可以选择放或不放。 用子问题定义状态:即f[v]表示前i件物品恰放入一个容量为v的背包可以获得的最大价值。则 其状态转移方程便是:f...原创 2011-11-30 21:55:04 · 1322 阅读 · 0 评论 -
递归求乘方
递归求一个数的乘方代码:仅仅是示例而已,实际应用中应该使用Java类库方法。 /** * calculate power of a number recursively. * @author Sun Kui */public class Power { private static int count = 1; public static v...原创 2011-11-29 22:27:32 · 470 阅读 · 0 评论 -
归并排序
归并排序是一种相当稳健的排序算法,无论何种输入序列,其期望时间复杂度和最坏时间复杂度都是O(nlogn), 这已经达到了基于比较排序算法的渐进下界。因此归并排序时常会用于对可能导致quicksort退化的序列排序。归并排序是典型的分治算法,常见的实现如下: private void merge(int[] arr, int lowerPtr, int upperPtr, int ...原创 2011-11-28 22:51:26 · 56 阅读 · 0 评论 -
尾递归与线性递归
下面两个程序是scheme写的计算阶乘的递归和尾递归实现线性递归:(define (factorial n) (if (=n 1) 1 (* n (factorial (- n 1))))) 尾递归:(define (factorial n) (fact-iter 1 1 n))(define (fact-iter ...原创 2011-11-13 16:48:03 · 100 阅读 · 0 评论 -
算24算法实现
1、 概述 给定4个整数,其中每个数字只能使用一次;任意使用 + - * / ( ) ,构造出一个表达式,使得最终结果为24,这就是常见的算24点的游戏。这方面的程序很多,一般都是穷举求解。本文介绍一种典型的算24点的程序算法,并 给出两个具体的算24点的程序:一个是面向过程的C实现,一个是面向对象的java实现。2、基本原理 基本原理是穷举4个整数所有可...原创 2010-02-03 23:27:00 · 664 阅读 · 0 评论 -
递归算法详解
原文可见:http://www.cnblogs.com/zhangqqqf/archive/2008/09/12/1289730.html C通过运行时堆栈支持递归函数的实现。递归函数就是直接或间接调用自身的函数。 许多教科书都把计算机阶乘和菲波那契数列用来说明递归,非常不幸我们可爱的著名的老潭老师的《C语言程序设计》一书中就是从阶乘的计算开始的函数递归。...原创 2010-02-02 22:57:14 · 91 阅读 · 0 评论 -
以一个枢纽值二分一个数组
划分算法由两个指针开始,分别指向数组的两头。在左边的指针向右移动,右边的指针向左移动。左边的指针leftPtr初始化为第一个数据项,右边的指针rightPtr初始化为数组的最后一项。算法如下: import java.util.Random;public class Partition { private long[] theArr; private i...原创 2011-12-02 21:30:31 · 59 阅读 · 0 评论 -
快速排序实现1
算法思想:快速排序使用分治法(Divide and conquer)策略来把一个串行(list)分为两个子串行(sub-lists)。步骤为:从数列中挑出一个元素,称为 "基准"(pivot),重新排序数列,所有元素比基准值小的摆放在基准前面,所有元素比基准值大的摆在基准的后面(相同的数可以到任一边)。在这个分区退出之后,该基准就处于数列的中间位置。这个称为分区(parti...原创 2011-12-03 23:16:12 · 129 阅读 · 0 评论 -
基础数据结构和算法二:Selection sort
One of the simplest sorting algorithms works as follows: First, find the smallest item in the array and exchange it with the first entry (itself if the first entry is already the smallest). Then,...原创 2013-11-19 20:57:06 · 131 阅读 · 0 评论 -
基础数据结构和算法一:UnionFind
The problem that we consider is not a toy problem; it is a fundamental computational task, and the solution that we develop is of use in a variety of applications, from percolation in physical ch...原创 2013-11-19 20:47:04 · 114 阅读 · 0 评论 -
MapReduce Algorithm - Map-side Join
Writing code to do joins from scratch is fairly involved. Rather than writing MapReduce programs you might consider using a higher level framework such as Pig, Hive or Cascading, in which join opera...原创 2013-07-03 21:47:12 · 84 阅读 · 0 评论 -
二叉搜索树的节点删除算法
删除节点是二叉搜索树操作中最复杂的,但对有些应用又非常重要,有必要好好研究一下。 一个取巧的办法:在树节点中加入一个boolean字段,比如isDeleted。需要删除一个节点时就把这个字段置为true,其他操作比如find()在查找之前先判断这个节点是否已经标记为删除了,这样删除的节点将不会改变树的结构,当然这样做还会继续保留这种已经删除的节点。对某些应用场景,这种做法是有优势的,比如已...2011-12-08 22:21:01 · 408 阅读 · 0 评论 -
基数排序(Radix Sort)
计数排序的缺点很明显,需要额外的空间C来作为计数数组,虽然时间复杂度为O(n+k),但当输入序列里元素取值很大的时侯,如k=O(n2),时,此时时间复杂度已经达到n2数量级了,空间的消耗也是让人无法承受的。这里介绍一种另一种线性排序算法——基数排序,可以应对数值很大的情况。 基数排序,即一个数位一个数位地进行排序,平常生活中我们经常使用的一种算法思想:如要对一个日期进行排...原创 2011-12-07 00:06:52 · 332 阅读 · 0 评论 -
计数排序(Counting Sort)
计数排序假设n个输入元素中的每一个都是介于0-k的整数,此处k为某个整数。计数排序顾名思义离不开计数,我们要计的是输入元素中相同元素出现的次数。对每一个输入元素x,确定小于x的元素的个数,那样排序之后,x在最终输出数组中的位置就可以确定了。例如:如果有17个元素小于x,则x就位于第18个输出的位置上。当然有几个元素相同时,这个方法就略微改进一下,因为不能将它们放在同一个位置上。假定输入数...原创 2011-12-06 23:53:07 · 200 阅读 · 0 评论 -
桶排序(bucket sort)
文章来源:http://hxraid.iteye.com/blog/647759原文中有基于CPP的实现,本文将CPP代码翻译为Java。原文写得很不错,复制过来做个笔记。 全依赖“比较”操作的排序算法时间复杂度的一个下界O(N*logN)。但确实存在更快的算法。这些算法并不是不用“比较”操作,也不是想办法将比较操作的次数减少到 logN。而是利用对待排数据的某些限定性假设 ,来避免绝...原创 2011-12-05 23:45:55 · 107 阅读 · 0 评论 -
快速排序实现2
这个算法实现中,对小的子数组使用插入排序,借此来提高性能。Knuth推荐对小数组的切割点为9,正是程序中使用的值。实践中还需要根据测试请看选择更好的切割点。 import java.util.Random;public class QuickSort2 { private long[] theArr; private int nElems; ...原创 2011-12-04 22:02:55 · 90 阅读 · 0 评论