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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:03:37+00:00 2026-06-12T13:03:37+00:00

Suppose we want to represent molecules in terms of graphs, where each node is

  • 0

Suppose we want to represent molecules in terms of graphs, where each node is an atom, and each edge is a connection between atoms. What would be an algorithm to decide whether two graphs (representing molecules) are equivalent. Since molecules are being represented, each node would need an attribute defining which molecule it is (Carbon, Nitrogen, Oxygen etc).

To make it easier, suppose each graph branches off from the same root atom, Nitrogen, which we can use as the starting node of our algorithm.

eg. N-X, N-Y, N-Z. Where N is the root Nitrogen node and X,Y,Z are the rest of the 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-12T13:03:38+00:00Added an answer on June 12, 2026 at 1:03 pm

    I agree with Joachim Isaksson’s answer that the general case — heck, even a less-than-general case — is hard to solve. But I’d like to propose a strategy for solving the relatively narrow case of a molecular tree graph with a specified starting element. [Note that this is the equivalent of Peter de Rivaz’s answer which was posted while I was working on this answer.]


    First let’s define a form or a language to describe a molecular graph that is unique to that graph — only one string can be formed by the graph. This will allow us to compare two strings to determine whether two graphs are the same so that your problem is reduced down to creating two correct strings to compare. (This approach also has the benefit of being easier to debug visually than an outright graph-comparing algorithm.) I usually see molecules described in forms like H2O and H2SO4, but this approach doesn’t preserve the graphy-ness of the molecules and so can’t be used for comparison (H2O could be water or some other very weird arrangement of its elements). So let’s use something Lisp-like to describe the molecule according to these rules:

    1. Each graph (including subgraphs) begins with ( and ends with )
    2. Any node A that has children is the first node listed in a new graph, and this graph is listed in its parent graph in a particular order (to be determined later)
    3. Any node A that has no children is listed in its parent graph in a particular order (to be determined later)

    With these starting rules, we can now describe H2O in more graph-like terms:

    1. O is the root of the graph so it starts a new graph: (O)
    2. H is the first child of O, but it has no children, so it’s listed in its parent as-is, not as the start of a subgraph: (OH)
    3. H is the second child of O, but is has no children, so it’s listed in its parent as-is, not as the start of a subgraph: (OHH)

    So

    graph of H2O

    becomes (OHH).

    Ordering in this case doesn’t matter, since the two Hs are childless and elementally equivalent.

    Let’s try a weird, irrational form of H2O to test out this approach:

    graph of O-H-H

    1. O is the root of the graph so it starts a new graph: (O)
    2. H is the first child of O. It has a child so it starts a new graph: (O(H))
    3. H is the first child of H, but is has no children, so it’s listed in its parent as-is, not as the start of a subgraph: (O(HH))

    We know that our approach so far can handle simple cases like H2O where ordering isn’t a concern, but H2SO4 won’t work without consistently ordering the O elements coming off of the S. It’s not possible to give a meaningful order to a child until its subgraph (if it has one) has been calculated, so we’ll add a final rule to execute:

    1. Each graph (including subgraphs) begins with ( and ends with )
    2. Any node A that has children is the first node listed in a new graph, and this graph is listed in its parent graph in a particular order (see step 4)
    3. Any node A that has no children is listed in its parent graph in a particular order (see step 4)
    4. After all child nodes have been visited and their subgraphs (if any) have been created, arrange the child nodes / child subgraphs in the parent node alphabetically

    Revisiting H2O with this new rule produces the same output because the two Hs are alphabetically equivalent and they have no children. So let’s try H2SO4:

    graph of h2so4

    1. S is the root of the graph so it starts a new graph: (S)
    2. O is the first child of S. It has children, so it starts a new graph: (S[unsorted:](O))
    3. ‘H’ is the first child of O. It has no children. There are no other children to process, so sorting at this level isn’t needed: (S[unsorted:](OH))

    4. O is the second child of S. This one has no children: (S[unsorted:](OH)O)

    5. O is the third child of S. It has children, so it starts a new graph: (S[unsorted:](OH)O(O))

    6. ‘H’ is the first child of O. It has no children. There are no other children to process, so sorting at this level isn’t needed: (S[unsorted:](OH)O(OH))

    7. O is the fourth child of S. This one has no children: (S[unsorted:](OH)O(OH)O)

    8. Finally, sort the children of S alphabetically: (S(OH)(OH)OO) (Note that I’m giving subgraphs special treatment in alphabetical comparison, but that’s not a requirement.)

    The final result is (S(OH)(OH)OO)

    Let’s try a variation of H2SO4 to see what it produces. Please note that this isn’t a proof that the approach is good, just a demonstration of how a variation in the graph produces a different result.

    graph of some weird H2SO4

    1. S is the root of the graph so it starts a new graph: (S)
    2. O is the first child of S. It has children, so it starts a new graph: (S[unsorted:](O))
    3. O is the first child. It has no children. (S[unsorted:](O[unsorted:]O))
    4. H is the second child, with no children. (S[unsorted:](O[unsorted:]OH))
    5. Now sort the children of O: (S[unsorted:](OHO)
    6. O is the second child of S. It has children, so it starts a new graph: (S[unsorted:](O))
    7. H is the first child. It has no children. (S[unsorted:](OHO)(O[unsorted:]H))
    8. O is the second child, with no children. (S[unsorted:](OHO)(O[unsorted:]HO))
    9. Now sort the children of O: (S[unsorted:](OHO)(OHO))
    10. Finally, sort the children of S alphabetically: (S(OHO)(OHO))

    This H2SO4 ((S(OHO)(OHO))) is different than the previous one ((S(OH)(OH)OO)).


    I made no attempt to formally prove that this approach is guaranteed to work or even to describe it formally, or to account for the broad range of molecular minutia out there, like bond counts and the like. At the very least, though, I hope this encourages you to try solving your graph comparison problem. I think it’s doable.

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

Sidebar

Related Questions

Suppose I want to store N samples (each sample takes up a significant portion
Suppose I want to implement an interpreter for a functional language. I would like
I want to create a two-way stream between a Node.JS client and a Node.JS
Suppose I want to add two buffers and store the result. Both buffers are
Suppose I want to have a blog with Rails 3 on my website and
Suppose I want to put objects that identify a server into a stl set
Suppose I want to execute code, for example value += 5 inside a namespace
Suppose I want to make a Web application which uses a fixed width and
Suppose you want to dynamically add to a HTML menu, where the menu HTML
Suppose we want to find out what will be the color property of particular

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.