Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Question 4 A software developer needs to solve the following problem: given the adjacency matrix of an undirected weighted graph, find the value of the
Question
A software developer needs to solve the following problem: given the adjacency
matrix of an undirected weighted graph, find the value of the kth minimum cost
edge. Assume that all edge weights are different, nonnegative integer numbers,
and not greater than The number one thousand signals the absence of
and edge.
For example, for the graph represented by the following adjacency matrix M:
The minimum that is is the second minimum is the third
minimum is and so on
The algorithm to design must take as input arguments the adjacency matrix M its
number of nodes and the value of It must return the value of the th minimum cost edge.
The software developer came up with these two algorithms to solve the problem:
Algorithm :
Make a copy of the adjacency matrix. Call the copy Mcopy.
Create a variable, called min, where the minimum value is recorded
Create a variable, called count. Initialise its value to
Visit every element of Mcopy, from top to bottom, from left to right and
record the minimum value in min
Once the minimum value is found, increase the variable count by one unit
If the condition countk is true, return the value of min. Otherwise, delete
the minimum value from Mcopy write number in the corresponding
positions and repeat steps
Algorithm :
Create a minheap storing the values of all edges
Perform EXTRACTMIN k times. The value last extracted is the kth
minimum.
UL Page of
a Write the pseudocode of Algorithm
b Write the pseudocode of Algorithm Assume you already have
implemented the minheap functions:
INSERTheapx:insert number x into the heap. Worstcase ThetalogN
BUILDHEAPA: build a min heap in place. Worstcase ThetaN
EXTRACTMINheap: return the minimum value stored in the minheap.
Worstcase ThetalogN
That is you can use these functions with no need to write the pseudocode for
them.
c What are the worstcase time complexities of A and A Use Theta
notation. Justify your findings.
d What algorithm do you recommend for implementation? Justify in terms of
worstcase time complexity.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started