-1

Given 2 Algorithms for a graph G=(V,E):

One:

  1. Sort edges from lowest to highest weight.
  2. Set T = {}
  3. for each edge e in the previous order, check if e Union T doesn't have any cycles. If yes, Add e to T.
  4. Return T if it's a spanning Tree.

Two:

  1. Sort edges from highest to lowest weight.
  2. Set T = E
  3. for each edge e in the previous order, check if T{e} is connected graph. If yes, Remove e from T.
  4. Return T if it's a spanning Tree.

Do both algorithms return Minimum Spanning Tree for sure? If not I would like to see a counter example.

5
  • 1
    Your first looks like Kruskal's algorithm; the second looks like reverse-delete. Neither is linear time. Commented Jul 31, 2022 at 8:17
  • The title and the body of the question are different. Fix. Commented Jul 31, 2022 at 8:40
  • What do you call linear time ? There are two independent input sizes. Commented Jul 31, 2022 at 8:41
  • Surely O(|V| + |E|), as always. Commented Jul 31, 2022 at 11:55
  • OP, these algorithms are not linear-time in the models where computer scientists care about the open problem of finding a linear-time MST algorithm because in those models, sorting is Omega(n log n). Commented Jul 31, 2022 at 11:57

2 Answers 2

1

Both of these algorithms will find an MST if it exists. The first is Kruskal's algorithm, and the second can be proven equivalent pretty easily.

Neither of them are linear time unless the weights are constrained somehow, because they start with an O(N log N) edge sort.

Disregarding the sort, the remainder of Kruskal's algorithm is very close to linear time, because it uses a disjoint set data structure to check for connectivity.

The second algorithm doesn't have a similarly quick and straightforward implementation -- anything fast is going to be more difficult than using Kruskal's algorithm instead.

Sign up to request clarification or add additional context in comments.

Comments

0

None of the algorithms is guaranteed to build a tree because E might not be simply connected.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.