我相信有一种方法可以在O(n)中找到长度为n的未排序数组中的第k个最大元素.或许它是"预期的"O(n)或其他东西.我们应该怎么做?
我有这个Java代码,它带有一组Point in输入,返回一组代表Delaunay三角剖分的图形边缘.
我想知道使用什么策略,如果存在,使用的算法名称.
在此代码中,GraphEdge包含两个awt Point并表示三角剖分中的边,GraphPoint扩展Awt Point,并在TreeSet对象中返回最终三角剖分的边.
我的目的是了解这种方法的工作原理:
public TreeSet getEdges(int n, int[] x, int[] y, int[] z)
Run Code Online (Sandbox Code Playgroud)
在这个三角测量的完整源代码下面:
import java.awt.Point;
import java.util.Iterator;
import java.util.TreeSet;
public class DelaunayTriangulation
{
int[][] adjMatrix;
DelaunayTriangulation(int size)
{
this.adjMatrix = new int[size][size];
}
public int[][] getAdj() {
return this.adjMatrix;
}
public TreeSet getEdges(int n, int[] x, int[] y, int[] z)
{
TreeSet result = new TreeSet();
if (n == 2)
{
this.adjMatrix[0][1] = 1;
this.adjMatrix[1][0] = 1;
result.add(new GraphEdge(new GraphPoint(x[0], y[0]), new GraphPoint(x[1], y[1])));
return …Run Code Online (Sandbox Code Playgroud)