Welche Regeln gelten für die "Ω (n log n) Barriere" für Sortieralgorithmen?

Schrieb ich ein einfaches Programm, sortiert in O(n). Es ist sehr Speicher ineffizient, aber das ist nicht der Punkt.

Es nutzt das Prinzip hinter einem HashMap für die Sortierung:

public class NLogNBreak {
    public static class LinkedListBack {
        public LinkedListBack(int val){
            first = new Node();
            first.val = val;
        }
        public Node first = null;
        public void insert(int i){
            Node n = new Node();
            n.val = i;
            n.next = first;
            first = n;
        }
    }

    private static class Node {
        public Node next = null;
        public int val;
    }

    //max > in[i] > 0
    public static LinkedListBack[] sorted(int[] in, int max){
        LinkedListBack[] ar = new LinkedListBack[max + 1];
        for (int i = 0; i < in.length; i++) {
            int val = in[i];
            if(ar[val] == null){
                ar[val] = new LinkedListBack(val);
            } else {
                ar[val].insert(val);
            }
        }
        return ar;
    }
}

So gilt das als eine Art von O(n), obwohl es gibt das Ergebnis in einer funky-format?

InformationsquelleAutor der Frage Ryan Amos | 2011-08-23

Schreibe einen Kommentar