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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:20:57+00:00 2026-06-01T15:20:57+00:00

I need to construct directed graph (at runtime) with cycles in Prolog and I

  • 0

I need to construct directed graph (at runtime) with cycles in Prolog and I am not sure know how to represent it. My requirement is that I need to get from one vertex to his neigbour in a constant time.

Is it possible to represent it as a tree, e.g.:

t(left_son,V,right_son)

but how to solve the cycles?

I can make a list of edges:

graph([a,b,c,d],[e(a,b),e(b,c),e(c,a),e(c,d)])

OR just

[a->[b],b->[c],c->[a,d],d->[]]

but how to avoid calling function ‘member’ on list while searching for neighbours, which cost linear time?

Thanks for your help

  • 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-01T15:20:59+00:00Added an answer on June 1, 2026 at 3:20 pm

    If your graph has less vertices than max arity allowed by your Prolog (for instance SWI-Prolog has unlimited arity), you could represent the edges as indices of arguments:

    could be this

    G = graph(a-[2],b-[3],c-[1,4],d-[2]).
    

    then use arg(Edge, G, Vert-Edges) to access neighbours.

    Of course any Prolog will let you describe the graph using facts. This is also the preferred way for very large graphs.

    :- dynamic edge/2.
    
    edge(a,b).
    edge(b,c).
    edge(c,a).
    edge(c,d).
    edge(d,b).
    

    edit The edge/2 relational representation also get the (potentially large) benefits of automatic indexing.

    more edit I totally forgot RDF and Semantic Web. Really powerful, we are going toward that.

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

Sidebar

Related Questions

I need to construct an if statement from the data coming from the client
I have the need to construct a LINQ To SQL statement at runtime based
I need to construct a DateTime from an integer Unix timestamp 1329272833 . The
I need to construct a huge treeview from a composite database table with Grouping
So we have the menu above. That I need to construct for a WordPress
In need to construct System.Single values (= IEEE 754 single precision 32-bit floats) from
I need to construct a DateTime object with the date coming from a calendar
I am a Spring newbie. I found that sometime we need to construct an
I need to construct a long SQL request to my database, but I'm not
The problem is that I need to construct the following SELECT statement: SELECT c.Animal/Dog,

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.