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

  • SEARCH
  • Home
  • 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 8144071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:16:23+00:00 2026-06-06T13:16:23+00:00

I have an unweighted directed graph that may or may not have cycles in

  • 0

I have an unweighted directed graph that may or may not have cycles in it. Now given a set of nodes, I need to return a graph that has the given nodes and the minimum amount of nodes such that they are connected. I cannot create new edges, so I need to use the existing ones.

Hopefully these pictures makes it clear. Starting with a graph,

enter image description here

Lets say we want the graph that has nodes c,f, and g, the function would return this graph
enter image description here

However, there is one more condition. Each of the edges has a boolean variable called required. If this is set to true, this edge and the corresponding nodes also need to be included in the graph.

Here is another picture to illustrate
The black edges are not required, but the red one is required
Let’s say we are given a and c as the nodes to include.

enter image description here

So instead of returning a graph that is A->C,
it will return this

enter image description here

To make the point even clearer, if we wanted a graph with b and c, it would also return that graph, because that edge is required.

How does one go about returning this graph? I would prefer not to have a graph with cycles returned, but I realize that isn’t always possible because the edges of a cycle might all be marked as required.

My initial thought was to make a copy of the graph keeping on the required edges and then attempt to piece the disjoint graphs back together. But during all my attempts to piece the graphs back together, I was able to find a counter example showing that wouldn’t be the minimal graph.

  • 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-06-06T13:16:25+00:00Added an answer on June 6, 2026 at 1:16 pm

    Does your intended output in the first example include the node e, from which all others are reachable? Or do you mean weak connectedness (meaning that the direction of the edges does not matter)? I guess the second is the case (judging from your A, B, C example), and then you can

    1. just ignore that edges are directed (linear time),
    2. contract the “required” edges (linear time),
    3. calculate pairwise shortest paths on the subset of required points (O(|V|³) but I guess you could push that down to O(r|V|²) something with r being the number of required points), and then
    4. find a minimum spanning tree on the required points (O(r²))

    Is that what you wanted?

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

Sidebar

Related Questions

I have a data set which is a large unweighted cyclic graph The cycles
Let G be an unweighted directed graph containing cycles. I'm looking for an algorithm
I have been given a question on an assignment that has got me stumped.
I have an unweighted, connected graph. I want to find a connected subgraph that
Given an directed unweighted acylic graph, I am trying to adapt Floyd-Warshall algorithm to
I have an undirected unweighted graph G = (V, E) and a randomly chosen
I have a undirected and unweighted (or all edges are weighted 1) acyclic graph
Have a network location that shows paths in the 8.3 short format. I need
Have data that has this kind of structure. Will be in ascending order by
Have data that has this kind of structure: $input = [ { animal: 'cat',

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.