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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:47:48+00:00 2026-06-12T16:47:48+00:00

I am using adjacency list representation. basically A:[B,C,D] means A is connected to B,C

  • 0

I am using adjacency list representation.

basically

     A:[B,C,D] means A is connected to B,C and D

now I am trying to add a method (in python) to add edge in graph.

But before I add an edge. I want to check whether two edges are connected or not.
So for example I want to add an edge between two nodes D and A ( ignorant of the fact taht A and D are connected).

So, since there is no key “D” in the hash/dictionary, it will return false.

Now, very naively, I can check for D and A and then A and D as well.. but thats very scruff.
Or whenever I connect two nodes, I can always duplicate..

I.e when connecting A and E.. A:[E] create E:[A]

but this is not very space efficient.

Basically I want to make this graph direction independent.

Is there any data structure that can help me solve this.

I am hoping that my question makes sense.

  • 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-12T16:47:49+00:00Added an answer on June 12, 2026 at 4:47 pm

    For an undirected graph you could use a simple edge list in which you store all the pairs of edges. This will save space and worsen performance but you should know that you can’t have both at the same time so you always have to decide for a tradeoff.

    Otherwise you could use a triangular adjacency matrix but, to avoid wasting half of the space, you will have to store it in a particular way (by developing an efficient way to retrieve edge existence without wasting space). Are you sure it is worth it and it’s not just premature optimization?

    Adjacency lists are mostly fine, even if you have to store every undirected edge twice, how big is your graph?

    Take a look at this my answer: Graph representation benchmarking, so you can choose which one you prefer.

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

Sidebar

Related Questions

I am trying to implement depth first search algorithm using adjacency list representation of
I have designed a weighted graph using a normalized adjacency list in mysql. Now
I'm trying to program a graph class using an adjacent list from an example
I have a table relating records using the adjacency list method (table A ),
I am using trying to use the toString(int[]) method, but I think I am
UPDATE Some answers so far have suggested using an adjacency list. How would an
In mysql, I have a tree that is represented using the adjacency list model.
I am using adjacency lists to represent a directed weighted graph and based on
I'm using the Adjacency List Model to create categories, and it works perfectly. When
Anyone know where I can obtain generic sample code for using an adjacency list

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.