
数据结构与算法
文章平均质量分 69
_iorilan
10年以上软件工程经验,先后从事在线教育/IT金融/即时通信/政府/物流平台/零售/门禁/监控等领域。专注夯实基础/项目成本与架构平衡/框架调研/团队高效协同工作
展开
-
平衡二叉查找树(AVL)
原文:http://www.cppblog.com/guogangj/archive/2009/10/26/99502.html十一、平衡二叉查找树(AVL)前面说了,二叉查找树方便查找取值插入删除,其复杂度不过为Ο(logn),但这是个“期望值”,因为我们也有比较差的情况,比如转载 2011-07-08 16:06:27 · 1586 阅读 · 0 评论 -
使用线性探测法构造哈希表
原文:http://hi.baidu.com/jiang_yy_jiang/blog/item/931d763ed8edc8f2838b13c3.html 已知一组关键字为(26,36,41,38,44,15,68,12,06,51),用除余法构造散列函数,用线性探查法解决冲突构转载 2011-07-11 17:30:34 · 4525 阅读 · 1 评论 -
二叉排序树与二叉堆
原文:http://blog.163.com/clevertanglei900@126/blog/static/111352259201131891452434/1 快排效率是不稳定的nlogn2 二叉树实现排序的效率是稳定的nlogn3 用二叉树实现排序有两种方法: 二叉排序树转载 2011-07-26 10:29:09 · 2373 阅读 · 1 评论 -
数学之二分法
1.确定区间[a,b] , 验证f(a) * f(b) 2.求区间(a,b)的中点m3.计算f(m)3.1 若f(m) = 0 , m 就是函数的零点3.2 if f(a) * f(m) 3.3 else if f(b) * f(m) 4.if abs(a - b) 重复2-4原创 2013-05-16 22:35:35 · 1517 阅读 · 0 评论 -
How To Build a Balance Binary Tree(BBT)
In Balance Tree the point is how to balance the tree byrotating .Two Things to be find out :1> ClosetLost Balance Point -- LBP ( Abs(leftHeight – rightHeight) > 1 )2> Find Sub-Tree --S原创 2013-07-06 13:19:42 · 1377 阅读 · 0 评论 -
Red Black Tree
Red-Black Tree 5 essentials :· each node color is red or black .· root color is black· each leaf is black· if parent is red color , then children are black .原创 2013-07-12 11:42:43 · 1665 阅读 · 0 评论 -
huffmanTree build and huffman Coding
huffMan Tree:Imagine that here is one article , which contains 27 'A' , 8 'B' ...and 5 'F' :A 27 , B 8 , C15, D15, E30 ,F5So now build a Huffman tree(1)take first TWO numbers , (2)constru原创 2013-07-04 18:24:17 · 1537 阅读 · 0 评论 -
Generate Min-Cost Tree using Kruskal
For each some Graph , may need to find out the "Minimum cost " way to build .for this graph , Now need to find out the min-cost tree .This method is named asKruskal :Now we get {v0,v1,原创 2013-07-31 17:19:38 · 1291 阅读 · 0 评论 -
How To Get Min-Cost Between two points in graph (Dijkstra’s algorithm)
How To Get Min-Cost Between twopoints in graph(Dijkstra’s algorithm) Now See This Graph :which is just like asubway map . Now Question is : how to calculate fromA to (B,C,D,E,F原创 2013-08-01 17:05:42 · 1405 阅读 · 1 评论 -
CPM(Critical Path Method )
CPM(Critical Path Method ) is now widely used in projectmanagement to control the schedule of the project life cycle . Now I will show you how to find out the critical activities andhow to create原创 2013-08-02 12:09:18 · 2084 阅读 · 0 评论 -
排序详解之归并排序
归并排序本文章将介绍归并排序,时间复杂度为n*lg(n)的归并排序,不仅效率高,而且是稳定的(而堆排序,快排是不稳定的)。要排序的数组:5 , 1, 9 ,3, 7 , 4 , 8 ,6 , 2 归并排序过程:1. 计算组元素个数,count ,以count=2为起始个数,每次count*=2,count∈[2,arr.Count]2. 每次把数原创 2013-08-17 10:43:25 · 1158 阅读 · 0 评论 -
二分查找,插值查找,斐波那契查找
二分查找,插值查找,斐波那契查找:1.二分查找:伪代码:while(leftbeginif key == arr[left] or key == arr[right] or key == arr[left+right/2]return indexelse if key< arr[(left+index)/2]then right = (left+right)/2原创 2013-08-09 16:12:37 · 1133 阅读 · 0 评论 -
ToopoLogical Sort (拓扑排序)
ToopoLOgical Sort Target :Sort the nodes in graph ,to find out the graph have cycle or not .result nodes only contains the nodes have not "involed in the cycle"steps :0.prepare node原创 2013-06-21 12:18:55 · 1179 阅读 · 0 评论 -
排序详解之快速排序
快速排序 快速排序使用分治的思想,以某个数为分割点,每一趟排序下来,左边数都比它小,右边数都比它大,然后再对左右两边数组做递归操作。时间复杂度(平均情况):n*lg(n) 排序步骤:1. 以左边首元素为分割点,拿出来存在midElement里(这时候左边首位置空了)2. 从右边找比midElement小的数,放在刚才左边空的位置,就是首位(这时,原创 2013-08-17 11:42:29 · 1379 阅读 · 0 评论 -
(排序详解之 堆排序)
堆排序本文将介绍一下堆排序的过程。 要点:(最小堆为例)1. 调整堆函数:传入节点索引,对比当前节点与父节点大小,如果小于则交换位置,以父节点位置递归执行。2. 设index=Arr.Count/ 2 -1 ,取到index位置的子节点,将子节点和当前节点依次传入递归函数执行,i∈[0,index],i--循环执行3. 每次移除根节点,原创 2013-08-15 23:44:38 · 1227 阅读 · 0 评论 -
Shell Sort (排序详解之 希尔排序)
排序详解 之 希尔排序原创 2013-08-15 17:29:43 · 1832 阅读 · 3 评论 -
Selection Sort(排序详解 之 选择排序)
排序详解 之 选择排序原创 2013-08-14 11:39:44 · 1525 阅读 · 0 评论 -
Set Deepth for each node in forest
Set Deepth for each tree node of a forestTreeNode Entity: public class TreeNode { public string Name { get; set; } public TreeNode ParrentNode { get; set; }原创 2013-07-10 11:33:04 · 1192 阅读 · 0 评论 -
使用两点经纬度计算距离
转自:http://www.cnblogs.com/ycsfwhh/archive/2010/12/20/1911232.htmlprivate const double EARTH_RADIUS = 6378.137;//地球半径private static double rad(double d){ return d * Math.PI / 180.0;转载 2013-02-28 18:39:47 · 1066 阅读 · 0 评论 -
中缀表达式转后缀表达式
1.声明队列Expressions,和堆栈Operators ,并定义优先级:( 和 ):3* 和/ : 2+ 和 - :1 数值越大,优先级越高foreach(每一个计算单元 in 当前中缀表达式){2.遇到数字直接进队列3.遇到左括号 '('直接进堆栈4.遇到右括号while(栈顶元素!=左括号){入队列弹出}弹出(为原创 2013-06-06 18:06:27 · 1593 阅读 · 0 评论 -
2-3 Tree (Multiple Searching Tree )
2-3Tree Defination :1. A tree can have more than one values2. If node have 1 value ,then only 2 children3. If node have 2 value ,then have 3 children During Insertion ,原创 2013-08-09 17:34:18 · 1212 阅读 · 0 评论 -
算法练习之二叉查找树 C++实现
/////////////////Node.h//////////////////class BTree{public: ////methods void InsertNode(TNode* node); void PrintNode(TNode* head);原创 2011-07-08 15:23:00 · 1164 阅读 · 0 评论 -
16进制字符串和byte数组的转化类
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Imps.Services.IDCService.Utility{原创 2011-09-28 17:46:20 · 1581 阅读 · 0 评论 -
在指定范围内 生成随机序列算法(可用于洗牌算法)
public List GetRandomLst(int from, int to) { var lst = Enumerable.Range(from, to - from + 1); return lst.OrderBy(a => Guid.NewGuid()).ToList(); }原创 2011-09-29 16:26:21 · 1299 阅读 · 0 评论 -
数据结构之链栈 C++实现
/////定义////////////////////////////节点类class Node{public: ////methods Node(void); Node(int data); ~Node(void); /////members原创 2011-07-08 16:43:25 · 1469 阅读 · 0 评论 -
二分查找法 C#实现
复习二分查找法。public int FindPosition(int num, int[] arr) { int left = 0; int right = arr.Length - 1;原创 2011-09-22 11:06:23 · 2586 阅读 · 0 评论 -
算法之 求两个数的最大公约数 C++实现
////欧几里得算法(求两个数的最大公约数)int God(int M,int N){int rem ;while(N > 0){rem=M%N;M=N;N=rem;}return M;} 调用: int _tmain(int argc, _TCHAR* argv[]){ int rlt = God(360,60);原创 2011-06-29 15:49:00 · 1985 阅读 · 0 评论 -
求最大子序列的和
求最大子序列的和 传统的嵌套循环的解法: /////获得最大子序列的和,复杂度O(n^2)int GetMaxSubSequence(int* arr,int len){ int i, j; int curSum; /* 当前序列和 */ int maxSum; /* 最大序列和 */ /* 初始化最大子序列和原创 2011-06-28 19:40:00 · 1503 阅读 · 0 评论 -
Name Count -- Javascript 实现
问题描述:Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alph原创 2014-06-02 16:23:30 · 1272 阅读 · 0 评论 -
Non--Abundant numbers
Non--Abundant numbers原创 2014-06-03 10:30:21 · 1211 阅读 · 0 评论 -
硬币面值的组成多少种可能---Javascript实现
硬币面值的组成多少种可能---Javascript实现原创 2014-06-03 18:53:32 · 1843 阅读 · 0 评论 -
Project Ruler 算法练习之除数问题
Project Ruler 算法练习之除数问题原创 2014-06-04 22:20:58 · 1322 阅读 · 0 评论 -
Project Ruler 算法练习之 10 进制 转 2进制 以及数字对称
Project Ruler 算法练习之 10 进制 转 2进制 以及数字对称原创 2014-06-05 12:43:26 · 1495 阅读 · 0 评论 -
Project Ruler 算法练习之 Truncate Prime
Project Ruler 算法练习之 Truncate Prime原创 2014-06-05 15:03:43 · 2118 阅读 · 0 评论 -
两大数相乘 -- javascript 实现
两大数相乘 -- javascript 实现原创 2014-05-30 15:37:48 · 2392 阅读 · 0 评论 -
二分法查找 --JS 实现
var indexOfSorted = function f(arr,n){ //assume : arr has been sorted var low = 0; var high = arr.length - 1; var mid = (low + high) / 2; while(high - low > 1){ if(n == arr[low]){return low原创 2014-06-28 14:15:31 · 5964 阅读 · 0 评论 -
会议安排最优算法
算法之会议时间安排原创 2014-06-28 00:05:15 · 3966 阅读 · 2 评论 -
正整数划分的另一种解法
Step 1: n ==1 : return 1 n == 2 : return [1,1],[2]Step 2:for n > 2a.arr.push(n)b.arr.push([n-1,1])c.1 get result of recursion(n-2)c.2 combine n==2 & result => retc.3 remove duplicate record in retcod原创 2014-06-27 15:25:20 · 1297 阅读 · 0 评论 -
ProjectRuler 算法练习之 位数组成字符串相同的整数
Problem :It can be seen that the number, 125874, and its double, 251748, contain exactly the same digits, but in a different order.Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and原创 2014-06-27 15:33:59 · 1382 阅读 · 0 评论 -
打印杨辉三角 --JS
var arr = new Array();for(var i = 0 ;i < 6 ; i++){if(i == 0){arr.push(1);}else if(i == 1){arr = new Array();arr.push(1);arr.push(1);}else{var arr2 = new Array();arr2.push(1);for(var j = 0;j<ar原创 2014-06-28 23:23:42 · 2559 阅读 · 0 评论