Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
U

User 12657536

@User 12657536
About
Posts
3
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Time Complexity of following method?
    U User 12657536

    Tried to update and make simpler to understand

    Algorithms algorithms data-structures json question

  • Time Complexity of following method?
    U User 12657536

    Thanks for advise. I am not a computer science grad, Let me have a look at an Algo book to study to update my question. Perhaps I may not need this forum to answer this question in the process.

    Algorithms algorithms data-structures json question

  • Time Complexity of following method?
    U User 12657536

    Here edges is a String array representing a set of space separated integer pair elements e.g. "e1 e2" where 0 < e1!=e2 <= n n is an integer, let's say ranging 0 < n <= 100000

    public int sumSqrtCeil(int n, String[] edges){
    ...

        List\> edgeSetList = "converted first edges element to set of Integer"
    
        // iterate rest of edges elements -A
        for(int i=1;i nodeDuo = "converted this edges element to set of Integer"
    
            boolean found = false;
            //search for nodeDuo in set elements of edgeSetList
    
            //iterate the nodeDuo 2 element set -B
            for(Integer e : nodeDuo){
                //iterate the edgeSetList containing a linked set collection -C
                for (Set edgeSet : edgeSetList) {
                    found = edgeSet.contains(e);
                    if (found) {
                        break;
                    }
                }
                if(found) break;
            }
    
            if(!found){
    
                //if nodeDuo has no element common to any element of edgeSetList then add a new set
    
                indexOfEdgeSetList++;
                edgeSetList.add(nodeDuo);
            }
            else{
                //else add nodeDuo to the existing set element of edgeSetList in which any of nodeDuo elements were found.
                edgeSetList.get(indexOfEdgeSetList).addAll(nodeDuo);
            }
        }
    
    
        Set linkedNodes =         //identify a set of all nodes which are linked to a different node(s)
    
        //Add 1 for each unit nodes (the nodes which are no linked to any other nodes) -D
        for(int i=1;i<=n;i++){
            if(!linkedNodes.contains(i)) output+=1;
        }
    
        // Add ceil of square root of 'node count' of each linked set in linked nodes set collection -E
        output += edgeSetList.stream().mapToInt(integers -> (int) Math.ceil(Math.sqrt(integers.size()))).sum();
        return output;
    }
    

    As per my understanding (updated) complexity should be- O( O(A) * O(B) * O(C) + O(D) + O(E) ) O( O(edges.length) * O(2) * O(n/2) + O(n) + O(edges.length) ) O( O(edges.length) * O(n) + O(n) + O(edges.length) ) //constant removed O( O(n*edges.length) + O(n) + O(edges.length) ) //evaluate O( O(n^3) + O(n) + O(n^2) ) //evaluate O( O(n^3) ) //taking biggest factor O(n^3) - Final Time Complexity. where, O(edges.len

    Algorithms algorithms data-structures json question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups