Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Algorithm 求向量集的最小元素_Algorithm_Sorting - Fatal编程技术网

Algorithm 求向量集的最小元素

Algorithm 求向量集的最小元素,algorithm,sorting,Algorithm,Sorting,我有一组向量,我需要用java编写算法,以找到这个向量集的最小元素。问题是,有些元素是无法比拟的。例如,minset{(1,4,6)、(3,2,5)、(2,3,4)、(5,4,6)}={(1,4,6)、(3,2,5)、(2,3,4)}。对于最小元素“minset”集合,以下情况成立:原始集合中的每个向量要么在“minset”中,要么在每个分量中大于新集合中的某个向量。例如,minset{(2,3,4),(2,3,5)}={(2,3,4)}。我已经有了这方面的算法,但我认为它可以用更好的计算复杂度

我有一组向量,我需要用java编写算法,以找到这个向量集的最小元素。问题是,有些元素是无法比拟的。例如,minset{(1,4,6)、(3,2,5)、(2,3,4)、(5,4,6)}={(1,4,6)、(3,2,5)、(2,3,4)}。对于最小元素“minset”集合,以下情况成立:原始集合中的每个向量要么在“minset”中,要么在每个分量中大于新集合中的某个向量。例如,minset{(2,3,4),(2,3,5)}={(2,3,4)}。我已经有了这方面的算法,但我认为它可以用更好的计算复杂度来完成。我的算法取一个元素,将其标记为最小值,然后取另一个元素,比较它们,如果有不可比较的元素,则将两者标记为最小值,如果第二个元素较小,则仅将其标记为最小值,等等。。。是否可以使用mergesort或heapsort来优化此算法?感谢所有回复。

我创建了一个。它使用Java的内置
array.sort()
和一个
比较器
,它比较两个大小为
L
的向量。如果您更喜欢使用
List
数据结构而不是数组,则可以使用
Collections.sort()
执行类似的操作

从:

import java.util.*;
导入java.lang.*;
班长
{
公共静态void main(字符串[]args)引发java.lang.Exception
{
最终int L=3;
int[][]向量={
{1, 4, 6},
{3, 2, 5},
{2, 3, 4},
{5, 4, 6},
{7, 7, 7},
{3, 3, 5},
{8, 8, 8},
};
比较器cmp=新比较器(){
公共整数比较(int[]v1,int[]v2){
int cmp0=Integer.signum(v1[0]-v2[0]);
对于(int i=0;i
伪代码:

foreach inputVector in vectors
    foreach minVector in minSet
        if (all components of inputVector <= components of minVector
            delete minVector
        elseif (all components of inputVector >= components of minVector)       
            skip to next inputVector
    if inputVector made it through the entire minSet, then add it to minSet
foreach inputVector in vectors
minSet中的foreach-minVector
if(inputVector的所有组件=minVector的组件)
跳到下一个inputVector
如果inputVector通过了整个minSet,则将其添加到minSet

我在文章中找到了我的问题的解决方案,其中是找到向量集最大元素的算法,这是一个类似的问题。它的计算复杂度比我的第一个直观算法要好得多。

你用什么方法来比较向量?哪些元素被认为是“不可比的”?我不明白为什么minset{(1,4,6)、(3,2,5)、(2,3,4)、(5,4,6)}={(1,4,6)、(3,2,5)、(2,3,4)}。你能更清楚地定义这个问题吗?哦,我明白你的意思了。您希望得到向量的子集,以便原始集合中的每个向量要么在新集合中,要么在每个组件中大于新集合中的某个向量。我会考虑一下。你能估计一下这个算法的复杂度吗?
Arrays.sort()
n*log(n)
。很抱歉,但我意识到,这个算法并不能满足我的需要,对于你使用的集合,它会返回得到(3,2,5)和(3,3,5)的集合。这是不直接的,因为(3,2,5)你的意思是(3,2,5)<(3,3,5)?这取决于你如何定义不平等。。。很明显,对于任何i->[vforeach inputVector in vectors foreach minVector in minSet if (all components of inputVector <= components of minVector delete minVector elseif (all components of inputVector >= components of minVector) skip to next inputVector if inputVector made it through the entire minSet, then add it to minSet