Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6835817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:16:41+00:00 2026-05-26T23:16:41+00:00

I have problem designing pseudo-code for these problems. It is not an assignment problem.

  • 0

I have problem designing pseudo-code for these problems.
It is not an assignment problem.
All I know about them is they have something to do with GRAPH data structure.

  1. Describe an O(n+m)-time algorithm for computing all the connected components of an undirected graph G with n vertices and m edges.

    (I am guessing this has something to do with traversal Breadth First Search (BFS), but correct me if I am wrong.).

    Input Graph G
    Output sequence of connected vertices with edges
    
    List = empty list
    
    for all u in G.vertices
        setLabel(u, UNEXPLORED)
    
    for all e in G.edges
        setLabel(e, UNEXPLORED)
    
    For all v in G.vertices
        if getLabel(v) = UNEXPLORED
            BFS (G,v,List)
    
    BFS(G,s,List)
    
    Object A = vertex1, vertex2, edge
    
    L0 = new empty sequence
    L0.addLast(s)
    setLabel(s,VISITED)
    
    i=0
    
    while Li is not Empty
        L(i+1) = new empty sequence
        for all v in L(i).elements
            for all incidentEdges(v)
                if getLabel(e) = UNEXPLORED
                    w = opposite(v,e)
                    if getLabel(w) = UNEXPLORED
                        setLabel(e,DISCOVERY)
                        setLabel(w,VISITED)
                        setVertex1(A,v)
                        setVertex2(A,w)
                        setEdge(A,e)
                        List.addLast(A)
                        L(i+1).addLast(w)
                    else
                        setLabel(e,CROSS)
        i = i + 1
    
  2. Say that an n-vertex directed acyclic graph G is compact.
    If there is some way of numbering the vertices of G with integers from 0 to n-1 such that G contains the edge (i,j) if and only if i < j, for all (i , j) in [0,n-1], Give an O(n^2)-time algorithm for detecting if G is compact.

    (Again, I am guessing this has something to do with topological ordering, but I am not sure how to implement it).

  3. Say a connected graph G is biconnected if it contains no vertex whose removal would divide G into 2 or more connected components.

    Give an O(n+m)-time algorithm for adding at most n edges to a connected graph G, with n>= 3 vertices and m>=(n-1) edges, to guarantee that G is biconnected. (Probably spanning forest?).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:16:41+00:00Added an answer on May 26, 2026 at 11:16 pm

    I had fun with these problems! At least, 2 and 3.

    1)
    I’m not sure I fully understand, but I figure by “compute the connected components” you mean “build subsets of the vertices such that each subset is a connected component”. If so, I think BFS or DFS would work depending on how you manage memory (ie. how you mark vertices you’ve already visited).

    2)
    [Edited]Here’s an algorithm which, used on any acyclic directed graph, should number the vertices according to the “compact” definition and detect if the graph is in fact compact (ie. contains all edges (i, j) such that i < j for all (i, j) in [0, n-1]).

    1. Find all vertices with no incoming edges (since the graph is acyclic, we know there will be at least one of these).
      1a. If there are more than one, terminate algorithm: the graph is not compact.
    2. Assign a number to it, starting from the lowest number available (0, for the first iteration).
    3. Remove this vertex from the graph, along with all edges outgoing from it.
    4. Go back to step 1, and repeat until all vertices are gone. If we reach that point without the algorithm terminating, then the graph is compact.

    (This is also O(n^2), btw – n searches over n vertices to find vertices without incoming edges – although this is only worst-case)
    At the end of this, all vertices will be numbered such that if it has incoming edges, the nodes from which they come will have a lower number than itself.

    3)
    Assuming the graph is already connected, here is an algorithm to make it biconnected:

    1. Find all vertices with only one edge (ie. endpoints).
    2. Arbitrarily select one of these.
    3. Draw edges from this selected vertex to all the other endpoint vertices.
      (I think this actually fits O(n). One search over n vertices to find endpoints, and we add less than n edges, since you can’t have a connected graph consisting entirely of endpoints.)

    Voila! A biconnected graph! Remove any endpoint vertex, and the original connected graph is still intact; remove any other vertex, and we know that each segment is still connected through the endpoints.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem about designing my application. I have a webservice with methods.
I have a problem about designing. I should use class or struct in this
I'm re-designing a Web site and I have a problem with the existing data
I have problem with return statment >.< I want to store all magazine names
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
This may be subjective, I don't know: I have this problem, which I'm kind
i'm now starting designing with proper mark-up and organization. and now, i have problem
I have a problem with designing an UI Android activity. There are two blocks
I have this problem that is really causing me headeches whenever i'm designing my
I have a issue designing am asp.net site. The problem is that I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.