Introduction to algrithms exercise2.3-7
汉语:描述一个nlgn复杂度的算法:给定一个n个数字的集合,和另一个数字x,判断集合中是否存在两个数字,它们的和是x
题目分析及伪代码实现
如果算法复杂度为n^2,那么很好设计比如可以采用以下算法
TestExistence(A,begin,end,x)
for i<-1 to n
for j<-i+1 to n
if a[i]+a[j]=x
then return i,j
return 0,0
现在要求算法复杂度为nlgn.通过本章的学习,我们知道折半查找和归并法爬序的算法复杂度为nlgn。所以我们猜想这个题目的算法可能和这两种算法挂上钩。
伪代码实现
TestExsistence(S,begin,end,x)
1. MergeSort(S,begin,end);
2.Create S'
for i<-1 to n
S'[i]=x-S[i];
3.MergeSort(S',begin,end);
4.purge S,S' seperately;
4.1 TestEqual(x,y);//比较两个元素是否相等
5. if the merged output contains two consecutive equal value ,the answer is true.
控制此算法复杂度数量级的关键在于控制purge 部分的算法复杂度。
未完待续。
转载于:https://www.cnblogs.com/finallyliuyu/archive/2009/08/12/1544432.html
Introduction to algrithms exercise2.3-7相关推荐
- Blender 3.0基础入门学习教程 Introduction to Blender 3.0
成为Blender通才,通过这个基于项目的循序渐进课程学习所有主题的基础知识. 你会学到什么 教程获取:Blender 3.0基础入门学习教程 Introduction to Blender 3.0- ...
- 网络增强现实开发简介 Introduction to Web AR development
搭配webXR.mindAR.three.js和tensorflow.js 你会学到: 获得构建不同类型的网络增强现实应用程序的实践经验,包括图像效果.人脸效果和世界效果 获得关于增强现实如何在网络浏 ...
- ZBrush全面入门学习教程 Schoolism – Introduction to ZBrush
ZBrush全面入门学习教程 Schoolism – Introduction to ZBrush ZBrush全面入门学习教程 Schoolism – Introduction to ZBrush ...
- 视频色彩校正简介 Introduction to Video Color Correction
视频色彩校正简介 Introduction to Video Color Correction 视频色彩校正简介 Introduction to Video Color Correction MP4 ...
- [转]Introduction of iSCSI Target in Windows Server 2012
Introduction of iSCSI Target in Windows Server 2012 源地址:http://blogs.technet.com/b/filecab/archive/2 ...
- MS UI Automation Introduction
MS UI Automation Introduction 2014-09-17 MS UI Automation是什么 UIA架构 UI自动化模型 UI自动化树概述 UI自动化控件模式概述 UI 自 ...
- 音频(3):iPod Library Access Programming Guide:Introduction
Next Introduction 介绍 iPod库访问(iPod Library Access)让应用程序可以播放用户的歌曲.有声书.和播客.这个API设计使得基本播放变得非常简单,同时也支持高级的 ...
- 2018-3-25论文(Whale Optimizer Algorithm)+(Gery Wolf Optimizer)笔记二---Introduction 对比
代码以及文论的来源: Seyedali Mirjalili http://www.alimirjalili.com/Projects.html 感谢作者!!! 2014年GWO Introductio ...
- 北航云计算公开课 01 Introduction to Cloud Computing
北航云计算公开课 01 Introduction to Cloud Computing_邓侃_新浪博客 北航云计算公开课 01 Introduction to Cloud Computing 受北航软 ...
最新文章
- 利用Injection插件加快Xcode编译速度
- pytorch中的torch.nn.LSTM解析
- 【项目管理】ITTO-采购管理
- 虚拟服务器的磁盘,虚拟服务器磁盘扩容
- 【Python】Flask框架系列(三):session和cookie操作、get/post请求、钩子函数
- 计算机PPT03,南京大学计算机网络课件03.ppt
- lru算法c语言实现单链表,操作系统之LRU算法 C语言链表实现
- 过滤代码中的html标签
- 【图像处理】美图秀秀使用技巧:抠图、透明、改色、教程
- UML基础(八)--构件图
- linux tomcat6安装及配置
- BUG记录:org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is no
- 武汉东湖学院计算机科学学院团委,【计算机科学学院】
- 2019年,转行到互联网行业,还有必要么?
- [转]IE6下的CSS BUG枚举
- CSS样式之块元素行内元素
- web项目没有小蓝点
- 李娜大骂老公姜山的内幕真相(图)
- 科脉如何修改服务器名字,科脉云商助手服务器设置
- Z3 Solver中Tactic的使用
热门文章
- CF 295A - Greg and Array 差分數列
- 洛谷 2585 [ZJOI2006]三色二叉树——树形dp
- [转]application.properties详解 --springBoot配置文件
- 转---谈谈HTTP协议中的短轮询、长轮询、长连接和短连接
- 重载赋值运算符含动态申请
- Android自定义控件之仿汽车之家下拉刷新
- android获取string.xml的值
- Android RecyclerView详解
- android textView调整字体的间距和行间距
- android 访问https服务器