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 679971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:19:08+00:00 2026-05-14T01:19:08+00:00

Given a directed graph, the goal is to combine the node with the nodes

  • 0

Given a directed graph, the goal is to combine the node with the nodes it is pointing to and come up with minimum number of these [lets give the name] super nodes.

The catch is once you combine the nodes you can’t use those nodes again. [first node as well as all the combined nodes – that is all the members of one super node]

The greedy approach would be to pick the node with maximum out degree and combine that node with nodes it is pointing to and remove all of them. Do this every time with the nodes which are not removed yet from graph.

The greedy is O(V), but this won’t necessarily output minimum number super nodes.
So what is the best algorithm to do this?

  • 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-14T01:19:09+00:00Added an answer on May 14, 2026 at 1:19 am

    20! is rather large, larger than 2^61. Fortunately there’s a better way to solve small instances: (EDIT) dynamic programming. By saving the optimal solutions to each subproblem, we pay some memory to obtain a very large savings in time.

    Here’s some sample code in Python. In implementing the code below in another language, you’ll probably want to number the vertices 0, …, n-1 and implement the sets as bit vectors.

    # find a smallest node closure of G
    # G is a graph in adjacency-list format: G[v] is the set of neighbors of v
    def node_closure(G):
        # maps subsets of vertices to their smallest node closure
        smallest = {frozenset(): []}
        def find_smallest(S):
            if S in smallest:
                return smallest[S]
            else:
                candidates = [[v] + find_smallest(S - frozenset([v]) - G[v]) for v in S]
                return min(candidates, key=len)
        return find_smallest(frozenset(G))
    

    This problem has an NP-hardness reduction from set cover that preserves the objective value. This means that unless P = NP, the best guarantee you can obtain for a polynomial-time algorithm is that it always outputs a solution that is at most O(log n) times larger than optimal.

    If x1, ..., xm are the elements to be covered and S1, ..., Sn are the sets, then the goal of set cover is to choose the minimum number of sets whose union is {x1, ..., xm}. Assuming that each element appears in at least one set, make a graph with nodes x1, ..., xm, S1, ..., Sn, R where there are arcs from R to all Si and for all i, j, an arc from Si to xj if and only if xj belongs to Si. There’s a straightforward correspondence between node closures and set covers: to obtain a node closure from a set cover, remove the vertices corresponding to the sets chosen and then R; to obtain a set cover from a node closure, take all sets whose vertices were chosen plus sets containing each xj whose vertex was chosen.

    (Note, for set cover, the greedy algorithm achieves the optimal approximation ratio! Something similar might be true for your problem.)

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

Sidebar

Ask A Question

Stats

  • Questions 367k
  • Answers 367k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer May have discovered the solution. Was catching up on my… May 14, 2026 at 4:59 pm
  • Editorial Team
    Editorial Team added an answer You need to make an asynchronous AJAX request by passing… May 14, 2026 at 4:59 pm
  • Editorial Team
    Editorial Team added an answer You could setup logging* on the machine to find out… May 14, 2026 at 4:59 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.