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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:48:19+00:00 2026-06-15T15:48:19+00:00

for an assignment I am asked by to find find an algorithm that calculates

  • 0

for an assignment I am asked by to find find an algorithm that calculates the transitive closure of a directed graph using O(n 4 ) time. We already learned about the floyd warshall algorithm, which is a lot better, so can someone help me create one that runs in O(n4) time? is there such an algorithm?

I know it seems dumb of a question. I dont really understand why we are being asked to find the slower way to do it.

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

    Floyd Warshall is O(n^3), and since O(n^3) is a subset of O(n^4), it is also O(n^4).

    Thus, by setting a new graph G'=(V,E',w') where E' = V x V (clique, complete graph) and w'(u,v) = 1 if (u,v) is in E, otherwise INFINITY – by using Floyd-Warshall algorithm, each pair (u,v) that ends up with a value less then infinity is in the closure.


    A Theta(n^4) solution:

    Q <- E (init) #(Q is a set)
    for i from 1 to n:
       for each v in V:
         for each w in V:
            for each u in V:
                if (v,w) is in Q and (w,u) is in E:
                   Q <- Q U {(v,u)}  #add (v,u) to Q
    

    Complexity is trivially Theta(n^4), we only need to show it indeed finds the transitive closure.

    By induction:

    1. For shortest path of length 1 from u to v it is the base clause,
      since (u,v) is in E.
    2. For each k:

      Each pair (u,v) with shortest path of length k>1 – there is w such that there is a path u -> ... -> w, and an edge (w,v). From induction hypothesis, in previous iterations we added (u,w) to Q, and thus the condition will yield true, and we will add (u,v) to the resulting set Q.

    Similary show that if some pair (u,v) was added to Q, then there is a path u->..->w->v, and thus it was rightfully added.


    A second Theta(n^4) solution:

    Set G' as described above, and for each vertex v in V run Bellman Ford from v.

    Each run of BF is Theta(n^3)1, running it n times is Theta(n^4)


    (1) Technically it is O(VE), but for none sparse graphs E is in Theta(V^2)

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

Sidebar

Related Questions

I have an assignment that has asked me to copy a file using buffered
A friend asked me a question today about an assignment problem. I found a
I have been asked to write a program using python for an assignment. I
My assignment is to create a simple graph that has both Nodes and Edges.
During an assignment, I was asked to show that a hash table of size
I asked this question about overloading the copy constructor and assignment operator with template
I find it surprising that this has not been asked yet, so I am
I had a homework assignment that asked for a function that uses direct recursion
For an assignment we were asked to create a function that would reverse all
For an assignment we are asked to write a predicate route/3 that succeeds if

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.