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

  • Home
  • SEARCH
  • 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 892787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:06:55+00:00 2026-05-15T14:06:55+00:00

I use the JUNG API to calculate shortest paths between several nodes in medium

  • 0

I use the JUNG API to calculate shortest paths between several nodes in medium large graphs (20 to 100 nodes). Right now I’m iterating over my nodes and use the simple ‘ShortetsPath’ function to calculate the shortest path for two nodes. All the shortest paths are put in an ArrayList.

UnweightedShortestPath<Vertex, SEdge> dist = new UnweightedShortestPath<Vertex, SEdge>(undir);
ArrayList<Vertex> tv = new ArrayList<Vertex>(); // contains nodes for shortestpath
ArrayList<Integer> distances = new ArrayList<Integer>(); // for the distances

for (int j = 0; j <tv.size()-1;j++){ //iterate over nodes
Vertex one = tv.get(j);

for (int k = j+1; k<tv.size();k++){ //iterate over next nodes
    Vertex two = tv.get(k);
    Number n = dist.getDistance(one, two);
    int d;
    if (n == null) {
        d = 5000000;
    }
    else {
        d = n.intValue();
    }
    distances.add(d);
}

}

I would like to speed up the calculation because I have to calculate this for many graphs and nodes. As far as I know, only Dijkstra is available in the JUNG API. So my questions are: Can I use Dijkstra to boost performance? Are other algorithms available in the JUNG API? Would it make sense to use another graph implementation which offers more different methods for shortest paths?

Thanks so far 🙂

  • 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-15T14:06:55+00:00Added an answer on May 15, 2026 at 2:06 pm

    The UnweightedShortestPath class in JUNG uses a Breadth-First-Search Algorithm, which has O(n^2) runtime. The Dijkstra algorithm works essentially the same, just for weighted graphs instead of unweighted graphs, so it’s runtime is also O(n^2).

    However, it looks like you’re interested in the distances between all possible pairs of nodes in your graph, but you’re using a pairwise approach. So your total runtime is O(n * n^2) = O(n^3). Instead you could use a global shortest path algorithm like the Johnson’s algorithm (http://en.wikipedia.org/wiki/Johnson‘s_algorithm). That’s runtime O(n^2 * log(n+ne)). So a bit faster overall.

    It’s not implemented in JUNG as far as I know, but you might be able to grab it off google code search.

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

Sidebar

Related Questions

I use Jung to draw graphs. Below is a simple graph with tree layout
How to use custom vertex labels in JUNG graph visualization? I am following Jung
I am looking for a way to persist jung graphs in a database or
Use of Unassigned local variable 'model'. Is what error message I'm getting. Its right
Use Case Show a photo uploaded by the user in a square box with
use C#,want to upload excel file on google doc. bellow syntax use to upload
use Text::Table; my $tb = Text::Table->new(Planet,Radius\nkm,Density\ng/cm^3); $tb->load( [ Mercury,2360,3.7], [ Mercury,2360,3.7], [ Mercury,2360,3.7], );
use strict; use warnings; use Time::HiRes qw(sleep); use Test::WWW::Selenium; use Test::More no_plan; use Test::Exception;
use the [] symbol in the name of the form field you are submitting
Use of gradient images is very common among developers for styling a page. Gradient

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.