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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:40:20+00:00 2026-05-13T07:40:20+00:00

I was wondering what would be the best way to implement undirected graphs (and

  • 0

I was wondering what would be the best way to implement undirected graphs (and hence graph traversal) on Google App Engine. I’m currently storing edges in the database as a list, i.e.

class Relation(db.Model):
    connect = db.ListProperty(str, required=True)

but this is notoriously inefficient.

I’m aware of the directed graph question as posed here, but I find that it would not be so suitable for an undirected 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-05-13T07:40:20+00:00Added an answer on May 13, 2026 at 7:40 am

    I would store the graph as a directed graph, which allows you to use queries more effectively. Obviously you need to have the constraint that all directed edges must have a partnering edge going in the opposite direction.

    Class Vertex(db.Model):
       #Vertex specific stuff
    
    Class Edge(db.Model):
       Start = db.ReferenceProperty(Vertex)
       End = db.ReferenceProperty(Vertex)
    

    You can then pull out all of the edges relating to a specific vertex with a simple query:

    #getting all neighbours of a vertex called "foo"
    Neighbours = Edge.all()
    Neighbours.filter("Start = ", foo)
    #neighbours now contains a set of all edges leading from foo
    

    Nice and simple, taking advantage of the fact you’re using appengine so you can let indexing do a lot of the work for you 😉

    If you want to make sure that directed constraint remains true, obviously use a method to create edges like so:

    LinkVertices(A, B) #A and B are vertices
       edgeOne = Edge()
       edgeOne.Start = A
       edgeOne.End = B
       edgeOne.put()
    
       edgeTwo = Edge()
       edgeTwo.Start = B
       edgeTwo.End = A
       edgeTwo.put()
    

    Addressing roffles concerns about storing all the edges twice, you could try something like this:

    Class Edge(db.Model):
        A = db.ReferenceProperty(Vertex)
        B = db.ReferenceProperty(Vertex)
    
    #getting all neighbours of a vertex called "foo"
    Neighbours = Edge.all()
    Neighbours.filter("A = ", foo)
    OtherNeighbours = Edge.all()
    OtherNeighbours.filter("B = ", foo)
    #these two queries now contains all edges leading from foo.
    

    This approach basically saves you storage space (every edge is only stored once) at the cost of slightly higher query times and much messier code. In my opinion that’s not a very good tradeoff, since you’re saving yourself about 64 bytes storage per edge.

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

Sidebar

Related Questions

I'm wondering what the best way to implement this would be. Basically our project
I was wondering what would be the best way to implement a morse code
i was wondering what would be the best way to code a browser plugin
I was wondering, what would be the best way to validate an integer. I'd
I've been wondering what the best way to do this would be. I've got
I'm wondering what would be the best way to group contacts by their company.
I was wondering what the best way is to implement a tag system, like
I was wondering what is the best way to implement an ellipsis abbreviation with
I was wondering what is the best way to implement a renderer in JavaScript.
I wondering what the best practice way (in C#) is to implement this xpath

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.