随笔分类 - [41]Algorithm算法
-
《算法导论》
摘要:关于学习算法的教材,我选择了LoveJenny书单书籍推荐-记这几年看的书中提到的《算法导论》资料现代计算机常用数据结构和算法(算法导论第一版中文版)数据结构与算法:C#语言描述(中文)(清风前辈推荐的书,觉得更适合我现在的情况)算法导论HTML版算法导论部分习题Introduction to Algorithms, Second Edition(这是CHM格式的完美英文版,目录、附录、练习、插图都不缺)百度文库和新浪资料里也还有很多资料,用到的话再整理。简介《算法导论》原书名——《Introduction to Algorithms》,是一本十分经典的计算机算法书籍与高德纳(Donald E 阅读全文
-
《算法导论》学习目录
摘要:关于学习算法的教材,我选择了LoveJenny书单书籍推荐-记这几年看的书中提到的《算法导论》资料现代计算机常用数据结构和算法(算法导论第一版中文版)数据结构与算法:C#语言描述(中文)(清风前辈推荐的书,觉得更适合我现在的情况)算法导论HTML版算法导论部分习题Introduction to Algorithms, Second Edition(这是CHM格式的完美英文版,目录、附录、练习、插图都不缺)百度文库和新浪资料里也还有很多资料,用到的话再整理。简介《算法导论》原书名——《Introduction to Algorithms》,是一本十分经典的计算机算法书籍与高德纳(Donald E 阅读全文
-
理解利用狄克斯特拉算法求最小生成树
摘要:《数据结构》第8章 图 P222例8.8 利用狄克斯特拉算法求最小生成树首先说几个概念:1、在无向图G中,若从订单vi到顶点vj有路径,则称vi和vj是连通的。2、一个连通图的生成树是一个极小连通子图,它含有图中全部顶点,但只有构成一颗树的(n-1)条边。图的所有生成树中具有边上的权值之和最小的树称为图的最小生成树。3、在一个无权的图中,若从一顶点到另一顶点存在着一条路径,称该路径上所有经过的边的数目为该路径长度,它等于该路径上的顶点数减1。 把路径长度最短的那条路径叫做最短路径。而狄克斯特拉算法就是求在一个图中,从指定顶点到其他顶点的最短路径。书中源代码:#include <stdio 阅读全文
-
局部性原理浅析——良好代码的基本素质
摘要:开篇一个优秀的程序、优美的代码,一般都具有良好的局部性。简洁、高效是每个程序员的追求。了解程序的局部性,能编写出更高效的代码。因为有良好局部性的程序能更好的利用缓存。不过这方面的只是将在以后的文章中介绍。这篇文章就简单的介绍以下程序的局部性原理。什么是局部性局部性通常有两种形式:时间局部性(temporal locality)时间局部性指的是:被引用过一次的存储器位置在未来会被多次引用(通常在循环中)。空间局部性(spatial locality)如果一个存储器的位置被引用,那么将来他附近的位置也会被引用。(这样说过于理论了些,在下面的论述中会有例子说明)数据引用局部性例子是最好说明问题的途径 阅读全文
-
数据结构与算法
摘要:一、数据的存储结构1.顺序存储结构(sequencestoragestructure)是逻辑上相邻的节点存储在物理位置上也相邻的存储单元里。2.链式存储结构(linkedstoragestructure)不要求逻辑上相邻的节点存储在物理位置上也相邻。3.索引存储是在存储节点信息同时,建立一个附加的索引表,然后利用索引表中的索引号的值来确定节点的存储单元地址。4.散列存储是根据节点的值累确定存储地址,把节点值作为自变量,通过一个称之为散列函数的计算规则确定该节点存储单元地址。二、数据类型1.高级语言的数据类型分2种:原子类型和结构类型。Char.intfloatdoublevoid等是原子类型, 阅读全文
-
C++基础代码--20余种数据结构和算法的实现
摘要:过年了,闲来无事,翻阅起以前写的代码,无意间找到了大学时写的一套C++工具集,主要是关于数据结构和算法、以及语言层面的工具类。过去好几年了,现在几乎已经回忆不起当年写代码时的情况,不过,通过文件头部注释里的日期,还是依稀想起了那些日子发生的一些事情,不禁感慨了一番。感概之余,随便翻阅了一下,发现当年的编程手法和现在相比,略显稚嫩,风格也相差的比较大了,明显受到当时读的一些经典C++书籍的影响。不过好在代码质量都算可以,都属于基础的语言层面以及数据结构的代码,操作指针比较小心,每个类也都有测试的样例,感觉对初学者应该会有用,于是拿到这里放出来,希望能对准备学习和正在学习C++语言编程的朋友有所裨 阅读全文
-
眼睛直观感受几种常用排序算法
摘要:1 快速排序介绍: 快速排序是由东尼·霍尔所发展的一种排序算法。在平均状况下,排序n个项目要Ο(nlogn)次比较。在最坏状况下则需要Ο(n2)次比较,但这种状况并不常见。事实上,快速排序通常明显比其他Ο(nlogn) 算法更快,因为它的内部循环(inner loop)可以在大部分的架构上很有效率地被实现出来,且在大部分真实世界的数据,可以决定设计的选择,减少所需时间的二次方项之可能性。步骤:从数列中挑出一个元素,称为 "基准"(pivot),重新排序数列,所有元素比基准值小的摆放在基准前面,所有元素比基准值大的摆在基准的后面(相同的数可以到任一边)。在这个分区退 阅读全文
-
KMP算法分析
摘要:文中的公式图片在chrome浏览器下显示不正常,IE则显示正常。一、引言主串(被扫描的串):S=,i 为主串下标指针,指示每回合匹配过程中主串的当前被比较字符;模式串(需要在主串中寻找的串):P=,j 为模式串下标指针,指示每回合匹配过程中模式串的当前被比较字符。字符串匹配:在主串中扫描与模式串完全相同的部分,并返回其在主串中的位置,这里的起始扫描位置默认为主串的第一个字符,即默认pos=1,其他情况类似。朴素匹配算法:在模式串与主串的匹配过程中,一共要进行n=Length(S)回合的匹配,每一回合分别从主串的起始字符、、...、开始进行。在具体某一回合的匹配过程中,每当模式串P中的某一字符与 阅读全文
-
二叉树
摘要:【数据机构和算法】章节中的【二叉树】,一直都觉得比较难。 使用C++语言用类进行了封装,以便于今后学习! 首先,定义了二叉树的节点类View Code// BinaryTreeNode.h: interface for the BinaryTreeNode class.// 二叉树的节点 NODE// 节点 、 左节点 、右节点// 2011-12-13 chen ang//////////////////////////////////////////////////////////////////////#if !defined(AFX_BINARYTREENODE_H__C6FD7... 阅读全文
-
动态规划策略
摘要:一、概念动态规划策略,一种分治策略。和贪婪策略一样,通常是用来解决最优解问题。分治故名就是将问题分解为几个子问题来解决,动态规划的特点就是分解的子问题中(子问题又可以分解成子问题)每次选择选择最优解。 动态规划主要的特点是在做决定前她知道所有子问题的信息。 动态规划的两个重要要素是:1)最优子结构。2)重叠子问题。 1)最优子结构,这是采取动态规划策略解最优化问题后要做的第一步。所谓最优化子结构是说若问题的一个最优解中包含了子问题的最优解,则该问题具有最优子结构。这个是我们采取动态规划的一个充分条件(当然这个条件也满足贪婪策略),问题出现这个条件就可以考虑采取动态规划。 一般要考虑的因素是: 阅读全文
-
搜索分词实现
摘要:HubbleDotNet 和 Lucene.Net 匹配相关度的比较http://www.cnblogs.com/eaglet/archive/2010/09/07/1820267.html很多网友在使用 Lucene.net (Lucene java 版本也是一样)后会感觉Lucene.net 的匹配相关度存在问题,搜索得到的结果往往不是希望的结果,不完全匹配的记录往往比完全匹配的记录排序还要靠... 阅读全文
-
数据结构
摘要:06√数据结构&JSJC#数据结构(四)----树和二叉树 摘要: 最近要给一个打算学.net的朋友准备些资料。打算先整理一下数据结构方面的东西。这是第四篇:C#数据结构----树和二叉树阅读全文posted @ 2009-07-22 16:52 青羽 阅读(472) | 评论 (1) 编辑C#数据结构(三)----串和数组 摘要: 最近要给一个打算学.net的朋友准备些资料。... 阅读全文
-
C# 数据结构 单链表反转
摘要:首先,单链表本身是一个递归定义的数据结构,也就是说,单链表中每个节点指向的依然是一个单链表,所以可以使用递归的特性来完成这个问题: static Node ReverseLink(Node list) { if (list.next == null) { return list; } else { Node n = ReverseLink(list.next); list.next.next = ... 阅读全文
-
C# 面试算法
摘要:从一个数组里选出最大的两个数 阅读全文
-
算法大全(1)单链表
摘要:声明,本文所有13道算法题目,覆盖了基本上所有常见的单链表问题,全都用C#实现,并测试通过,代码下载:TestLink.zip1.单链表反转2.找出单链表的倒数第4个元素3.找出单链表的中间元素4.删除无头单链表的一个节点5.两个不交叉的有序链表的合并6.有个二级单链表,其中每个元素都含有一个指向一个单链表的指针。写程序把这个二级链表称一级单链表。7.单链表交换任意两个元素(不包括表头)8.判断单... 阅读全文
-
求N个字符串的最大公共子串
摘要:今天在一个perl论坛上面看到了这个题目,说是微软的面试题。用javascript写了一个实现,可能效率不是很高,回去研究研究模式匹配算法先~<script>var s1 = "drhe123rherhert346",s2 = "hxert32344",n = 0, t, max_len = 0, match_hash ={},s_loop = s1.length > s2.le... 阅读全文
-
最大公共字串(C#实现版)
摘要:LCS (Longest Common Subsequence) 算法用于找出两个字符串最长公共子串。算法原理:(1) 将两个字符串分别以行和列组成矩阵。(2) 计算每个节点行列字符是否相同,如相同则为 1。(3) 通过找出值为 1 的最长对角线即可得到最长公共子串。 人 民 共 和 时 代中 0, 0, 0, 0, 0, 0华 0, 0, 0, 0, 0, 0人 1, 0, 0, 0, 0, ... 阅读全文