矩阵线性相关则矩阵行列式_搜索线性时间中的排序矩阵

矩阵线性相关则矩阵行列式

声明 (Statement)

We have to search for a value x in a sorted matrix M. If x exists, then return its coordinates (i, j), else return (-1, -1).

我们必须在排序的矩阵M中搜索值x 。 如果x存在,则返回其坐标(i,j) ,否则返回(-1,-1)

Image for post

Let us consider the above matrix as an example. In this example, we are going to search for the value 12. Since 12 is present in the matrix, the algorithm should return its coordinates (2, 1)

让我们以上述矩阵为例。 在此示例中,我们将搜索值12。由于矩阵中存在12,因此算法应返回其坐标(2,1)

简单方法 (Simple Approach)

A simple approach is to traverse all the values in the matrix and check if it is equal to 12.

一种简单的方法是遍历矩阵中的所有值并检查其是否等于12。

Image for post

The worst case time complexity of the above algorithm will be O(n x m) = O(n²) when n = m

n = m时,上述算法的最坏情况下时间复杂度将为O(nxm)= O(n²)

高效方法 (Efficient Approach)

The above algorithm behaves worse for large values of n and m. Let us look into the efficient algorithm now.

对于较大的n和m值,上述算法的性能较差。 现在让我们研究高效算法。

算法 (Algorithm)

1. Start from Top Right position (0, m - 1) in the matrix M2. If the value is equal to x return (0, m - 1)3. Move one row down if the current value is less than x4. Move one column left if the current value is greater than x

Let us apply this algorithm into our matrix M. We are going to search for the value 12 in M

让我们将此算法应用到矩阵M中。我们将在M中搜索值12

Image for post
Step 1 and 2
步骤1和2
  1. Start from the Top Right value 5 at M[0][4]. 5 is less than 12, so 12 should be somewhere in the bottom of the matrix since all row and column values are sorted in ascending order. So we move one row down.

    M [0] [4]的右上角值5开始 5小于12,因此12应该在矩阵底部的某个位置,因为所有行和列值都按升序排序。 因此,我们向下移动了一行。

  2. The value 10 at M[1][4] is also less than 12, so we move one row down.

    M [1] [4]上的值10也小于12,因此我们向下移动了一行。

Image for post
Step 3 and 4
步骤3和4

3. The value 15 at M[2][4] is greater than 12, so 12 should be somewhere in the left of the matrix, so we move one column left.

3. M [2] [4]上的值15大于12,因此12应该在矩阵的左侧某处,因此我们向左移动一列。

4. The value 14 at M[2][3] is also greater than 12, so we move one column left

4. M [2] [3]上的值14也大于12,因此我们向左移动一列

Image for post
Step 5 and 6
步骤5和6

5. The value 13 at M[2][2] is greater than 12, so we move one column left

5. M [2] [2]的值13大于12,所以我们向左移动一列

6. The value at M[2][1] is equal to 12, so we return its index (2, 1)

6. M [2] [1]处的值等于12,因此我们返回其索引(2,1)

The worst case time complexity of the above algorithm will be O(n + m) = O(2n) = O(n) when n = m, because we will be iterating all rows and all columns once if x is at the bottom left position (n - 1, 0)

n = m时,上述算法的最坏情况下时间复杂度将为O(n + m)= O(2n)= O(n) 因为如果 x 位于左下角 我们将对所有行和所有列进行一次迭代 位置 (n-1,0)

You can find the Java solution for this algorithm in the Github repo.

您可以在Github存储库中找到该算法的Java解决方案。

谢谢🙏 (Thank you 🙏 👋🤘)

Linkedin | Github

Linkedin | Github

翻译自: https://medium.com/swlh/search-sorted-matrix-in-linear-time-c999234d39a

矩阵线性相关则矩阵行列式

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/388370.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

计算机英文版个人简历发文,计算机个人简历英文_英文简历.doc

计算机个人简历英文_英文简历I have the honor to present a brief introduction of myself to you in compliance with the requirements of your graduate admissionI was born in November 7th, 1966, at the town of Changing, Beijing. My parents are doing business and…

一地鸡毛 OR 绝地反击,2019年区块链发展指南

如果盘点2018年IT技术领域谁是“爆款流量”,那一定有个席位是属于区块链的,不仅经历了巨头、小白纷纷入场的光辉岁月,也经历了加密货币暴跌,争先退场的一地鸡毛。而当时间行进到2019年,区块链又将如何发展呢? 近日,全球知名创投研究机构CBInsight发布了《What’s Next …

iphone UITableView及UIWebView的使用

1。新建一个基于Navigation-based Application的工程。 2。修改原来的RootViewController.h,RootViewController.m,RootViewController.xib为MyTableViewController.h,MyTableViewController.m,MyTableViewController.xib。 3。点击MainVindow.xib,将R…

python 的datetime模块使用

1.datetime模块主要是5个类 date #日期类 年月日 datetime.date(year,month,day) time #时间类 时分秒 datetime.time(hour,minute,second,microsecond,tzoninfo),返回18:29:30 datetime #日期时间类 datetime(year, month, day[, hour[, minute[, second[, microsecond[,tzinf…

物联网数据可视化_激发好奇心:数据可视化如何增强博物馆体验

物联网数据可视化When I was living in Paris at the beginning of this year, I went to a minimum of three museums a week. While this luxury was made possible by the combination of an ICOM card and unemployment, it was founded on a passion for museums. Looking…

计算机公开课教学反思,语文公开课教学反思

语文公开课教学反思引导语: 在语文的公开课结束后,教师们在教学 有哪些需要反思的呢?接下来是yjbys小编为大家带来的关于语文公开课教学反思,希望会给大家带来帮助。篇一:语文公开课教学反思今天早上,我上了一节语文…

中国连续十年成马来西亚最大贸易伙伴

中新社吉隆坡1月30日电 (记者 陈悦)马来西亚国际贸易和工业部30日发布的2018年马来西亚贸易报告显示,2018年马来西亚与中国的贸易额约为3138.1亿林吉特(马来西亚货币,约合774亿美元),较上年同期增长8.1%,约占马来西亚对外贸易总额…

Iphone NSMutableArray,NSMutableDictionary AND 动态添加按钮

一.NSMutableDictionary NSMutableDictionary * tags; 1.NSMutableDictionary 添加内容: [tags setValue:xxx forKey :xxx]; 2.NSMutableDictionary 遍历: for(NSString * title in tags){ //其中得到的title是key } 3.NSMutableD…

bzoj2938: [Poi2000]病毒

被Star_Feel大爷带着做题 明显大力AC机然后找环 本来我一开始想的是先去有另一个病毒为前缀的病毒,结果今天早上写的时候偷懒没写 结果跳fail的时候会跳到中间。。。无语,Star_Feel大爷叫我son或一下now和fail就过了 还有神仙是直接把fail接到儿子的更流…

bigquery数据类型_将BigQuery与TB数据一起使用后的成本和性能课程

bigquery数据类型I’ve used BigQuery every day with small and big datasets querying tables, views, and materialized views. During this time I’ve learned some things, I would have liked to know since the beginning. The goal of this article is to give you so…

中国计算机学科建设,计算机学科建设战略研讨会暨“十四五”规划务虚会召开...

4月15日下午,信息学院计算机系举办了计算机科学与技术学科建设战略研讨会暨“十四五”规划务虚会。本次会议的主旨是借第五轮学科评估的契机,总结计算机学科发展的优劣势,在强调保持优势的同时,更着眼于短板和不足,在未…

iphone开发如何隐藏各种bar

转载至:http://blog.csdn.net/riveram/article/details/7291142 状态条StatusBar [cpp] view plaincopyprint?[UIApplication sharedApplication].statusBarHidden YES; [UIApplication sharedApplication].statusBarHidden YES; 导航条NavigationBar [cpp] v…

Swift5.1 语言指南(九) 闭包

★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs.com/strengthen/)➤GitHub地址&a…

服务器被攻击怎么修改,服务器一直被攻击怎么办?

原标题:服务器一直被攻击怎么办?有很多人问说,网站一直被攻击,什么被挂马,什么被黑,每天一早打开网站,总是会出现各种各样的问题,这着实让站长们揪心。从修改服务器管理账号开始&…

脚本 api_从脚本到预测API

脚本 apiThis is the continuation of my previous article:这是我上一篇文章的延续: From Jupyter Notebook To Scripts从Jupyter Notebook到脚本 Last time we discussed how to convert Jupyter Notebook to scripts, together with all sorts of basic engine…

Iphone代码创建视图

要想以编程的方式创建视图,需要使用视图控制器中定义的viewDidLoad方法,只有在运行期间生成UI时才需要实现该方法。 在此只贴出viewDidLoad方法的代码,因为只需要在这个方法里面编写代码: [cpp] view plaincopyprint?- (void)vi…

聊聊flink Table的OrderBy及Limit

序 本文主要研究一下flink Table的OrderBy及Limit 实例 Table in tableEnv.fromDataSet(ds, "a, b, c"); Table result in.orderBy("a.asc");Table in tableEnv.fromDataSet(ds, "a, b, c");// returns the first 5 records from the sorted …

binary masks_Python中的Masks概念

binary masksAll men are sculptors, constantly chipping away the unwanted parts of their lives, trying to create their idea of a masterpiece … Eddie Murphy所有的人都是雕塑家,不断地消除生活中不必要的部分,试图建立自己的杰作理念……埃迪墨…

css+沿正方形旋转,CSS3+SVG+JS 正方形沿着正方本中轴移动翻转的动画

CSS语言:CSSSCSS确定* {margin: 0;padding: 0;fill: currentColor;vector-effect: non-scaling-stroke;}html {overflow: hidden;}body {display: flex;flex-direction: column;margin: 0;min-width: 10em;height: 100vh;}body > svg,body > input,body > …

Iphone在ScrollView下点击TextField使文本筐不被键盘遮住

1.拖一个Scroll View视图填充View窗口&#xff0c;将Scroll View视图拖大一些&#xff0c;使其超出屏幕。 2.向Scroll View拖&#xff08;添加&#xff09;多个Label视图和Text View视图。 3.在.h头文件中添加如下代码&#xff1a; [cpp] view plaincopyprint?#import <U…