
algorithm
文章平均质量分 85
matdodo
use knowledge to make the world better.
展开
-
[leetcode] Maximum Split of Positive Even Integers
Maximum Split of Positive Even IntegersYou are given an integerfinalSum. Split it into a sum of amaximumnumber ofuniquepositive even integers.For example, givenfinalSum = 12, the following splits arevalid(unique positive even integers sum...原创 2022-05-01 08:18:28 · 435 阅读 · 0 评论 -
Find the Kth number c++ version
最小堆的应用原创 2016-03-02 16:32:46 · 1195 阅读 · 3 评论 -
Lotto 迭代算法 cpp
题目内容:给定N个数字,再从中选定M个数字出来。将每一种组合内的数字又小到大排列之后,将所有组合按照字典序排列,请你找到第X组的第Y个数字。给定的数字为1~N。范例:范例1:(N,M,X,Y) = (5,2,8,2)所有组合按顺序排列为:(1 2), (1 3), (1 4), (1 5), (2 3),(2原创 2016-03-22 00:40:07 · 1029 阅读 · 0 评论 -
计算逆序数对
python语言:#-*- coding:utf-8 -*-#import pdbdef sort_count(data): """ using merge sort and count inversion """ global count count = 0 def merge_sort(data): global cou原创 2016-02-28 11:08:20 · 1051 阅读 · 0 评论 -
[笔记]binaryheap
Binary Heap 二叉堆优先队列在图算法中有着广泛应用。 如何构建优先队列呢? 使用列表? 在列表中,插入操作为O(n)O(n),排序操作为O(nlogn)O(nlogn)。 但是,我们可以做的更好。 这种数据结构是二叉堆。 由二叉堆构建的优先队列的出队入队操作为O(lgn)O(lgn) 二叉堆分为最小堆,最大堆。 最小堆为在堆顶放置最小元素的堆结构。最顶端就是最小值。bina原创 2015-08-07 20:47:51 · 843 阅读 · 0 评论 -
sequence alignment
# this problem is also called 'edit distance'# consider sequence X = (x1,x2,..,xm) and Y=(y1,y2, ..., yn);# an alignment is a subset A belongs to {1,...,m} * {1, .., n}# for any (i,j) and (i',j'原创 2017-10-20 06:01:48 · 1730 阅读 · 0 评论 -
chain matrix product
# given matrix A1, A2, ..., An# the sizes of them are m0*m1, m1*m2, ..., m(n-1) * mn# in general, a matrix with size m*n multipling a matrix with size of n*p will need mnp operations.# let cost(i,原创 2017-10-21 21:49:16 · 703 阅读 · 0 评论 -
[笔记]python数据结构之线性表:linkedlist链表,stack栈,queue队列
python数据结构之线性表python内置了很多高级数据结构,list,dict,tuple,string,set等,在使用的时候十分舒心。但是,如果从一个初学者的角度利用python学习数据结构时,这些高级的数据结构可能给我们以迷惑。比如,使用list实现queue的时候,入队操作append()时间复杂度可以认为是O(1),但是,出队操作pop(0)的时间复杂度就是O(n)。原创 2015-06-06 17:47:10 · 16288 阅读 · 2 评论 -
C 语言实现的哈夫曼编码huffman coding
C 语言实现的哈夫曼编码huffman coding项目地址项目地址https://github.com/ludlows/chuffman编码操作需要给个文本作为输入,输出 密码本 和 二进制编码解码操作需要密码本和二进制编码, 输出 解码后的文本。...原创 2019-04-23 07:47:08 · 1140 阅读 · 0 评论 -
Level Order Traversal 图的层序遍历 cpp
题目内容:給一棵tree,還有他的root,輸出這棵tree的level order traversal。Note : 一個節點可能有大於兩個的孩子節點。Note : 當一個節點有多個孩子需要造訪時,由數字編號小的節點開始造訪。输入格式:第一行為一個正整數T(T第一行有2個整數,N R,分別代表N個點以及root為編號R的節點,所有點的編號為1~N。 接下原创 2016-03-21 11:10:40 · 917 阅读 · 0 评论 -
Adjacent Node Sum (图的邻接表表示 C语言)
图的非矩阵表示,邻接表表示。原创 2016-03-07 20:13:15 · 1207 阅读 · 0 评论 -
[笔记]tree
tree 树名词解释node 节点树的基本组成部分。节点内可以存储重要的信息。edge 边边是树的另一种基本结构。边将两个节点连接在一起,表示两个节点间存在某种关系。树中的每个节点(除了根节点)都有且只有一条输入边。但可以有无数条输出边。root 根节点在树中,根节点有且只有一个。并且根节点没有输入边。path 路径路径由有顺序的节点序列表示。这些序列间由边连接起来。children 子节点输入边来原创 2015-08-07 14:58:37 · 644 阅读 · 0 评论 -
[笔记]利用归并排序计算逆序数的个数
归并排序是分治算法的实例之一。 利用归并排序可以直接计算出数据中逆序数的对数,并且时间复杂度并不大(O(nlogn)的时间复杂度)。 下面的程序,读入一列txt文件,并计算文件中逆序数对的个数。 txt文件中,数据只有一列,且都是整数,并且所有数据中没有重复数字。原创 2015-07-31 14:42:58 · 1285 阅读 · 0 评论 -
[笔记]HashMap
in binary sort the algorithm complexcity is O(logn). can we do better ? is there an algorithm that it has O(1) time complexcity for searching? yes there is. that is hashing.a hash table is a col原创 2015-07-31 14:59:24 · 615 阅读 · 0 评论 -
[笔记]sort
sort原创 2015-08-04 00:45:50 · 658 阅读 · 0 评论 -
[笔记] binarySearchTree AVLTree
binary search treesearch tree operations1.tree() 2.put(key,value) 3.get(key) 4.in() 5.delete() 6.len()binary search tree nodeclass TreeNode(object): def __init__(self,key,val,left=None,right=N原创 2015-09-06 17:06:04 · 889 阅读 · 0 评论 -
[笔记]图
graph概念vertex 节点A vertex (also called a “node”) is a fundamental part of a graph. It can have a name, which we will call the “key.” A vertex may also have additional information. We will call this addi原创 2015-09-19 20:38:15 · 847 阅读 · 0 评论 -
最大堆
问题:Max Heap题目内容:實作Max heap的三種操作:push, pop, top。指令0 x:代表push,將x push進max heap。指令1 : 代表pop,將最大的數字pop出來,若heap為空則忽略這道指令。指令2 : 代表top,將最大的數字印出來,若heap為空則忽略這道指令。输入格式:本題只有一道測資。測資第一行為一原创 2016-03-02 16:29:45 · 590 阅读 · 0 评论 -
迷宫问题Maze (BFS) 广度优先遍历 C语言
迷宫小问题原创 2016-03-08 11:28:27 · 7407 阅读 · 1 评论 -
用Python计算北京地铁的两站间最短换乘路线
用Python计算北京地铁的两站间最短换乘路线地铁数据地铁数据用字典表示: {station:{neighbor1:line number,neighbor2:line number,…},station2:{…},…} 现在我们有地铁的站名,下面就是如何将地铁站名转化为上面所需要的标准字典格式。 从网上找到的地铁站名为字符串:line1=u'''苹果园 古城路 八角游乐园 八宝山 玉泉路 五原创 2015-05-24 20:01:28 · 18716 阅读 · 45 评论