有关“逆序个数问题”的算法设计与分析报告.docVIP

有关“逆序个数问题”的算法设计与分析报告.doc

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
  4. 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
  5. 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们
  6. 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
  7. 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
有关“逆序个数问题”的算法设计与分析报告

逆序个数问题算法研究 秦韬,全昱立,薛梅,李丽萍 (陕西师范大学 计算机科学学院,陕西 西安 710119) 摘 要: n个元素组成的a[1],a[2],…,a[n]。若i〈j且a[i]〉a[j]则称 (a[i],a[j])是一个逆序对。中逆序对的个数称为的逆序数。按定义计算逆序数要通过n(n-1)/2此次比较,时间复杂度是 O(n2)。一种方法利用树状数组计算逆序数,时间复杂度降为O(nlog2(n))。计算逆序数时间复杂度降为O(nlog2(n))主要思路是将元素从大到小依次放置在数状数组中对于每一个元素i来说因它前面的数比它大而计算出逆序数t[i]利用树状数组的结构特征即可以O(log2(n))的时间复杂度而统计出t[i]那么最终总的逆序数为∑t[i], XUE Mei, LI Li-ping (Dept. of 2013, School of Computer Science, Shaanxi Normal University, Xi’an 710119, China) Abstract: Sequence consisting of n elements, a [1], a [2], ..., a [n]. If i j and a [i] a [j], called (a [i], a [j]) is a reverse pair, or troublemakers on. Sequence in reverse order of the number called reverse number sequence. First, by definition violent methods to solve, count the number of reverse through n (n-1) / 2 the comparison, the time complexity is O (n2). Secondly, for a method of optimizing the use of computing the inverse number Binary Indexed Tree, the time complexity is reduced to O (nlog2 (n)). Finally, calculated according to the partition number reverse merge sort algorithm, the time complexity is reduced to O (nlog2 (n)). Sort Binary Indexed Tree optimization main idea is to be placed in decreasing order of the number of elements like array, for each element i, the result of its previous number larger than it calculated the number of reverse t [i], the use of characteristics Binary Indexed Tree structure, that can be O (log2 (n)) time complexity and the statistics t [i], then the final total number of reverse Σt [i]. The final optimization is the use of divide and conquer approach, through compromise to reduce complexity. Key words: Inverse number; Binary Indexed Tree; Divide and conquer merge; Algorithm 1 引言 逆序个数问题的描述: 多人排成一个队列,我们认为从低到高是正确的序列,但是总有部分人不遵守秩序。如果说,前面的人比后面的人高(两人身高一样认为是合适的), 那么我们就认为这两个人是一对“捣乱分子”,比如说,现在存在一个序列: 176, 178, 180, 170, 171 这些捣乱分子对为 176, 170, 176, 171, 178, 170, 178, 171, 180, 170, 180, 171,? 那么,现在给出一个整型序列,请找出这些捣乱分子对的个数(仅给出捣乱分子对的数目即可,不用具体的对) 输入: 为一个文件(in),文件的每一行为一个序列。序列全为数字,数字间用”,”分

文档评论(0)

zilaiye + 关注
实名认证
文档贡献者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档