Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please help with kruskal alogrithm, providing wrong output, Im not sure what I did wrong. def kruskal ( edges ) : if parent [ i

please help with kruskal alogrithm, providing wrong output, Im not sure what I did wrong. def kruskal(edges): if parent[i]== i: else:def union(parent, rank, x, y): yroot = find(parent, y) parent[xroot]= yroot parent[yroot]= xroot parent[yroot]= xroot# Extract vertices from edgesfor edge in edges:s =[]rank ={} parent[node]= nodeedges = sorted(edges, key=lambda item: item[2]) u, v, w = edge y = find(parent, v) s.append(edge)return sorted(s, key=1ambda x: (x[0], x[1], x[2]))Finding the most likely mutation tree
You're given a list of bacteria RNA fragments, all from related bacteria which have mutated into separate strains over time. Your goal is to come up with the most likely sequence of mutations that led to this state of affairs.
The chance that one bacteria mutated into another depends on the number of differences in their RNA strings. The more differences in their RNA strings, the more unlikely it is that the bacteria mutated into each other. (In fact, exponentially more unlikely -- the probability that k locations changed at the same time is 2
).
If we construct a fully connected graph whose nodes represent RNA fragments and each edge has weight 2
, where k is the number of differences between RNA strings, then a spanning tree which maximizes the product of edge weights will be the most likely mutation tree. (Each mututation is assumed to be independent, so the chance that all the mutations in the spanning tree happen is the product of their respective probabilities)
Write a function that takes a list of RNA fragments, constructs an edge list with weights, then returns the most likely mutation tree, along with its probability.
Note: your algorithm should construct a graph and then run your implementation of Kruskal's algorithm on it. The difficulty lies in determining the correct graph, so that a minimum sum spanning tree in your graph corresponds to a maximum product spanning tree in the graph described above.
Input: ["adad","adac","acad", "cdac","addd"]
Output: ([('adad', 'adac', 0.5),('adad', 'acad', 0.5),('adad', 'addd', 0.5),('adac', 'cdac', 0.5)],0.0625)
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

13th Edition Global Edition

1292263350, 978-1292263359

More Books

Students also viewed these Databases questions

Question

What are the goals?

Answered: 1 week ago

Question

Are there other relevant characteristics about your key public?

Answered: 1 week ago

Question

What information remains to be obtained?

Answered: 1 week ago