有向图和复杂性

时间:2011-11-02 17:34:02

标签: complexity-theory

我在找到程序的复杂性时遇到了问题。 它由一个有向图组成,其中每个节点都有一个边缘的arraylist。

有人知道通过这个有向图搜索的复杂性吗?

我的代码:

class Project{
    ArrayList<Task> subProject = null;
    int manpower, maxNr;



    Project(int maxNr, int manpower){
          this.maxNr = maxNr;
          this.manpower = manpower;
          subProject = new ArrayList<Task>();
     }
}

class Task {
    int id, time, staff, slack;
    String name;
    int earliestStart, latestStart, finished;
    ArrayList<Edge> outEdges = null;
    int cntPredecessors;
    Boolean rund;

    Task(int n){
        id = n;
        cntPredecessors = 0;
        outEdges = new ArrayList<Edge>();
        rund = false;
    }
}

class Edge {
    int edges;

    Edge(int edges){
        this.edges = edges;
    }
}

public void run(){
        while(runTasks == false){
            System.out.println("Time: " + runT);
            for(Task t: subProject){
                if(t.cntPredecessors == 0 && t.rund == false){ // Checks if there is no edges to the task and if the task hasen't started
                    System.out.println("        Starting: " + t.id);
                    ferdige.add(t);
                    t.rund = true;
                    t.earliestStart = runT;
                    t.finished = runT + t.time;
                    if(cirdep < t.finished){
                        cirdep = t.finished;
                    }
                    tId = t.id;
                    workers += t.staff;
                    System.out.println("        Current staff: " + workers);
                }
                if(t.cntPredecessors == 0 && t.finished == runT){
                    maxNr--;
                    System.out.println("        Finished: " + t.id);
                    minPre(t.id);
                    workers -= t.staff;
                }
                if((t.cntPredecessors == 0 && t.rund == false) || (t.cntPredecessors == 0 && t.finished == runT)){
                    System.out.println("        Current staff: " + workers);
                }
            }

1 个答案:

答案 0 :(得分:1)

随着更多信息的继续发展,你至少可以通过深度优先搜索来说它是$ O(| V |)$。但是你必须做一些事情来处理孤立的组件,因为如果没有路径,DFS就无法到达节点。