Question
For each of the greedy algorithms that are given below for solving the wiring (i.e., connecting) black dots to white dots problem do the following:
For each of the greedy algorithms that are given below for solving the wiring (i.e., connecting) black dots to white dots problem do the following:
(i) write pseudo-code to implement the algorithm (as described), and
(ii) analyze the worst-case running time of the algorithm (i.e., O()).
For each algorithm:
Input: dots[1..2n] where dots[i] = B or W; assume the array contains n B dots and n W dots, n > 0
Output: pairs[1..n] where pairs[i] = (index position of a B in dots[], index position of a W in dots); these indices represent the B and W entries that youre connecting (e.g., (3, 5) means youre connecting the entry in dots[3] to the entry in dots[5])
a. Wire (i.e., connect) the ith black dot to the ith white dot, i = 1..n (i.e., working left to right, connect each black dot to the first unconnected white dot it finds).
b. Wire (i.e., connect) the black and white dots that are closest to each other. Then connect the next two closest unconnected black and white dots. Continue until all black and white dots are connected. That is, start by using the minimum amount of wire to get a valid connection made, then progressively use more wire (in the same fashion) as needed.
Please I want the solution I don't want note about it.
Thanks
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