简体   繁体   English

适用于Java 1000 * 1000矩阵的数据结构。

[英]Suitable data structure for Java 1000*1000 matrix.

I am practising java programming. 我正在练习Java编程。 I encountered a problem which requires 1000 x 1000 matrix which stores integers value less than 1500 我遇到了一个需要1000 x 1000矩阵的问题,该矩阵存储的整数值小于1500

I would want to navigate across all the elements I might need to fetch max element and its 4 adjacent elements. 我想浏览所有可能需要获取max元素及其4个相邻元素的元素。

What is the best data structure which doesn't affect performance? 不影响性能的最佳数据结构是什么?

1  2  3  4
5  6  7  8
9  10 11 12
12 14 15 16

for the element 11 --> 7, 10, 12, 15 are adjacent elements. 对于元素11 --> 7, 10, 12, 15是相邻的元素。

what is wrong with the 2d array data structure? 二维数组数据结构有什么问题?

to get an adjecent of a number at i,j return [i-1][j],[i+1][j],[i][j+1],i[j-1] (you will have to deal with cases where i is zero etc)... 要在i,j处得到数字的邻接,请返回[i-1] [j],[i + 1] [j],[i] [j + 1],i [j-1](您必须处理我为零的情况等)...

as performance goes, its O(1), doesn't get any better than that... 随着性能的提高,其O(1)不会比这更好。

If you are talking about finding the location of the element. 如果您正在谈论查找元素的位置。 if the matrix is sorted you can simply do a binary search. 如果矩阵已排序,则只需执行二进制搜索即可。

A 2dim Array of shorts: 2dim短裤阵列:

-> short [][] matrix = new short[1000][1000];
|  Added variable matrix of type short[][] with initial value [[S@1794d431

Generate in a second, few MB in size. 只需几秒钟即可生成。 What could be better than that? 还有什么比那个更好呢?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM