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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:43:53+00:00 2026-05-13T20:43:53+00:00

I’m looking for an algorithm to check whether a given graph is subgraph of

  • 0

I’m looking for an algorithm to check whether a given graph is subgraph of another given graph.

I have few conditions to make this NP complete problem bit more feasible..

  • The graphs have approx <20 vertices.
  • The graphs are DAG.
  • All vertices are non-uniquely labeled, and the corresponding vertices in the main graph and the subgraph should have same label. I don’t know if I’m using the correct terminologies (because I haven’t taken a graph theory course…). It will be something like:

The line graph A–B is subgraph of A–B–A but A–A is not a subgraph of A–B–A.

Any suggestions are fine. This is not a homework question btw. 😀

  • 1 1 Answer
  • 1 View
  • 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-13T20:43:54+00:00Added an answer on May 13, 2026 at 8:43 pm

    If the labels are unique, for a graph of size N, there are O(N^2) edges, assuming there are no self loops or multiple edges between each pair of vertices. Let’s use E for the number of edges.

    If you hash the set edges in the parent graph, you can go through the subgraph’s edges, checking if each one is in the hash table (and in the correct amount, if desired). You’re doing this once for each edge, therefore, O(E).

    Let’s call the graph G (with N vertices) and the possible subgraph G_1 (with M vertices), and you want to find G_1 is in G.

    Since the labels are not unique, you can, with Dynamic Programming, build the subproblems as such instead – instead of having O(2^N) subproblems, one for each subgraph, you have O(M 2^N) subproblems – one for each vertex in G_1 (with M vertices) with each of the possible subgraphs.

    G_1 is in G = isSubgraph( 0, empty bitmask)

    and the states are set up as such:

    isSubgraph( index, bitmask ) =
       for all vertex in G
           if G[vertex] is not used (check bitmask)
              and G[vertex]'s label is equal to G_1[index]'s label
              and isSubgraph( index + 1, (add vertex to bitmask) )
                   return true
       return false
    

    with the base case being index = M, and you can check for the edges equality, given the bitmask (and an implicit label-mapping). Alternatively, you can also do the checking within the if statement – just check that given current index, the current subgraph G_1[0..index] is equal to G[bitmask] (with the same implicit label mapping) before recursing.

    For N = 20, this should be fast enough.

    (add your memo, or you can rewrite this using bottoms up DP).

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

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.