Kruskal's Algorithm using Priority Queues

106 views
Skip to first unread message

Adarsh Kishore

unread,
Apr 10, 2022, 5:03:41 AM4/10/22
to sage-devel
Hi everyone,

I was going through Sage's codebase, and I came across the file
```
SAGE_ROOT/src/sage/graphs/spanning_tree.pyx
```
Screenshot from 2022-04-10 14-27-45.png

In the TODO section, it is mentioned that 
```
    - Rewrite: func:`kruskal` to use priority queues.
```

I looked it up on Google and StackOverFlow, but I didn't come across any such implementation. The standard implementations all prefer to use the DisjointSet data structure. I would like to contribute to Sage and if someone can point me to a good resource which discusses this concept, preferably with a better time complexity than by using Disjoint Sets, that would be really great

David Coudert

unread,
Apr 11, 2022, 3:01:02 AM4/11/22
to sage-devel
This query has been added in https://trac.sagemath.org/ticket/10433.
I don't think that priority queue can be of any help to speed up the current code.

Adarsh Kishore

unread,
Apr 11, 2022, 3:23:30 AM4/11/22
to sage-devel
Okay, then I think that line should be removed right? It can be misleading to potential contributors

Adarsh Kishore

unread,
Apr 11, 2022, 10:18:38 AM4/11/22
to sage-devel
I can open a ticket to correct this if you want

David Coudert

unread,
Apr 12, 2022, 2:50:19 AM4/12/22
to sage-devel
Sure, feel free to open a ticket to correct this.

Adarsh Kishore

unread,
Apr 12, 2022, 3:43:25 AM4/12/22
to sage-devel

Enjeck Cleopatra

unread,
Apr 12, 2022, 1:56:20 PM4/12/22
to sage-devel
Just wondering if the third TODO (Randomized spanning tree construction) should be removed as well, since I see a function called "random_spanning_tree" exists already.

David Coudert

unread,
Apr 13, 2022, 3:14:36 AM4/13/22
to sage-devel
You are right, this can be removed too.
And I'm not sure a parallel version of Boruvka's algorithm is needed. We already have a large number of spanning tree algorithms.

Adarsh Kishore

unread,
Apr 13, 2022, 3:54:33 AM4/13/22
to sage-devel
Can I make these changes in https://trac.sagemath.org/ticket/33688 as discussed? The ticket has not been closed yet

Adarsh Kishore

unread,
Apr 13, 2022, 3:57:12 AM4/13/22
to sage-devel
By the way, I opened https://trac.sagemath.org/ticket/33703 after a discussion on https://groups.google.com/g/sage-devel/c/R3r3G_Qrllo.
If I am successful, we will test it to see if there are any performance improvements over the sequential version, else we can remove that line.
Is that fine?

davida...@gmail.com

unread,
Apr 13, 2022, 9:29:27 AM4/13/22
to sage-devel
Yes, you just need to change it back to "need review" so that it can be reviewed.
Reply all
Reply to author
Forward
0 new messages