Question

In: Computer Science

xxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxx In this year’s runner's competition, there are x contestants participating in the women's  100m freestyle....

xxxxxxxxxxxxxxxxxxxxxxxxxxxxx

xxx In this year’s runner's competition, there are x contestants participating in the women's  100m freestyle. They are divided into y equal-size groups before the first round, each containing n runners.

xxx Imagine we obtained a list containing all of the times by each runner for the first round.  Construct a divide-and-conquer algorithm with Θ(mlogm) worst-case runtime complexity to generate a complete list of ascending time performances. HINT: You may need to use two functions.

xxxa) Provide the pseudocode for your algorithm.

xxx(b) Worst case runtime complexity for your algorithm? Use the Master Theorem.

Solutions

Expert Solution

Divide and Conquer is a strategy used to recursively split the data contents into individual data units, so that those individual data units can be easily solved and those individual solutions can be combined together to form the final solution.

  • We have X number of contestants
  • We have Y number of groups having equal number of runners
  • Each group has N number of runners
  • Therefore X = Y x N
  • The list contains the time performances of all the athletes, (i.e) the list contains x number of time performances.
  • Now we construct a divide and conquer algorithm to generate a list that contains the time performances of all the athletes sorted in ascending order.

a) Pseudocode for the algorithm:

Procedure divide(list)

    mid length(list) / 2

    left[] list[0] to list[mid]

    right[] list[mid+1] to list[length(list) -1]

    divide(left)

    divide(right)

    Display conquer(left,right)

end procedure

Procedure conquer(left,right)

    i 0

    while (left and right is not empty)

        if (left[i] < right[i]) then

      temp[i] left[i]

increment i

              remove left[i]

        else

              temp[i] right[i]

              increment i

              remove right[i]

          end if

    end while

     p length(temp)

    while (left is not empty)

         temp[p] left[]

     end while

     while (right is not empty)

         temp[p] right[]

     end while

    return temp[]

end procedure

Explanation of the pseudocode:

  • In Procedure divide(list), the list contains all the time performances
  • We divide the list into two equal halves by finding the mid element
  • We defined two arrays named as left and right to store the divided arrays
  • The process is a recursive one until we store a single data into an array, i.e each array contains one value
  • We recursively called the function divide(left) and divide(right) to achieve that.
  • Next we called the Conquer function to sort the individual values.
  • If the left array value is lesser than the right array value, then that value gets stored to a temporary array.
  • If the right array value is lesser than the left array value, then that value gets stored to a temporary array.
  • Each and every value will be stored to the temporary array, if any values did not get stored in the temporary array, we use the while loop to store the remaining values {temp[] left[] and temp[] right[]}

Finally we are returning the temporary array to display/print the values in ascending order.

b) Masters method to find the worst time complexity:

If we have a divide and conquer recurrence of the form

T(n) = aT(n/b) + f(n)

where a ≥ 1, b > 1, and f(n) > 0 is asymptotically positive,

then we can apply the master method, which is based on the master theorem. We compare f(n) to nlogba under asymptotic (in)equality:

Case 1: f(n) = O(nlogba - ε) for some constant ε > 0.
(That is, f(n) is polynomially smaller than nlogba.)
Solution: T(n) = Θ(nlogba).
Intuitively: the cost is dominated by the leaves.

Case 2: f(n) = Θ(nlogba), or more generally (exercise 4.6-2): f(n) = Θ(nlogbalgkn), where k ≥ 0.
(That is, f(n) is within a polylog factor of nlogba, but not smaller.)
Solution: T(n) = Θ(nlogbalgn), or T(n) = Θ(nlogbalgk+1n) in the more general case.
Intuitively: the cost is nlogbalgk at each level and there are Θ(lgn) levels.

Case 3: f(n)= Ω(nlogba + ε) for some constant ε > 0, and f(n) satisfies the regularity condition af(n/b) ≤ cf(n) for some constant c<1 and all sufficiently large n.
(That is, f(n) is polynomially greater than nlogba.)
Solution: T(n) = Θ(f(n)),
Intuitively: the cost is dominated by the root.

        

   


Related Solutions

In the 2016 Olympics in Rio, after the 50 m freestyle competition, a problem with the...
In the 2016 Olympics in Rio, after the 50 m freestyle competition, a problem with the pool was found. In lane 1 there was a gentle 1.2 cm/s current flowing in the direction that the swimmers were going, while in lane 8 there was a current of the same speed but directed opposite to the swimmers' direction. Suppose a swimmer could swim the 50.0 m in 25.0 s in the absence of any current. Part A: How would the time...
Fill in the ??? cells using the information presented. Use $(X,XXX) for credits and $X,XXX for...
Fill in the ??? cells using the information presented. Use $(X,XXX) for credits and $X,XXX for debits MCD (Shares in Millions; $ in Millions) Total Common Stock APIC Retained Earnings AOCI Treasury Stock Beginning balance (shares) 1660.6 -893.5 Ending Balance at Dec. 31, 2018 ????? $17 $7,376 $ 50,487 $(2,610) $(61,529) Comprehensive Income $ 6,152 ????? $ 127 Common stock cash dividends ????? $ (3,582) Treasury stock purchases (shares) -25 Treasury stock purchases $(4,981) $ (4,981) Share-based compensation ????? ?????...
Among the contestants in a competition are 49 women and 29 men. If 5 winners are...
Among the contestants in a competition are 49 women and 29 men. If 5 winners are selected, what is the probability that they are all women?
Twenty percent of the contestants in a scholarship competition come from Pylesville High School, 40% come...
Twenty percent of the contestants in a scholarship competition come from Pylesville High School, 40% come from Millerville High School, and the remaining come from Lakeside High School. Two percent of the Pylesville students are among the scholarship winners; 3% of the Millerville contestants and 5% of the Lakeside contestants win. a) If a winner is chosen at random, what is the probability that they are from Lakeside? b) What percentage of the winners are from Pylesville?
1.Jack Strong has $50,000 of wealth. He is participating in a Jujitsu competition. The prize is...
1.Jack Strong has $50,000 of wealth. He is participating in a Jujitsu competition. The prize is $10,000. He is guaranteed to win it (hehasblack belt) unless he breaks his arm. If his arm is broken, he will lose the tournament and he will have to pay $5,000 in medical expenses. Jack thinks that the probability of him breaking his arm during a tournament is 5 percent. He can get a medicalinsurance at a price of $.3 dollars for each $1...
A point charge q1q1q_1 = 4.35 nCnC is located on the x-axis at xxx = 2.10...
A point charge q1q1q_1 = 4.35 nCnC is located on the x-axis at xxx = 2.10 mm , and a second point charge q2q2q_2 = -6.25 nCnC is on the y-axis at yyy = 1.00 mm . a) What is the total electric flux due to these two point charges through a spherical surface centered at the origin and with radius r1r1r_1 = 0.385 mm ? b) What is the total electric flux due to these two point charges through...
a. If the Brand X, makes the following marketing claim: "Discover our range of women's sustainable...
a. If the Brand X, makes the following marketing claim: "Discover our range of women's sustainable clothing and fashion from the Conscious Collection Online". You should be able to assume: Brand X is evidently sustainable because they are promoting the new Conscious Collection Clothing Line. In other words marketing information regarding sustainability is sufficient evidence of sustainability efforts.(T/F) b. The main principles of the Circular Economy involve a fundamental rethinking of products, materials, and systems of commerce. Circular economy represents...
C++ recursive function that draws the following shape. X XXX XXXXX XXXXXXX XXXXXXXXX XXXXXXXXX XXXXXXX XXXXX...
C++ recursive function that draws the following shape. X XXX XXXXX XXXXXXX XXXXXXXXX XXXXXXXXX XXXXXXX XXXXX XXX X The length of the longest row in the shape and the shape's character are function parameters. In above shape the longest row is 9 and the pattern's character is "X".
plot on a graph, men's times as X column and Y column being women's times Men’s...
plot on a graph, men's times as X column and Y column being women's times Men’s 2015 World Championship – Final Results (top 17 finishers) Rank Name Nationality Time (seconds) 1 Mo Farah Great Britain (GBR) 1621.13 2 Geoffrey Kipsang Kenya (KEN) 1621.76 3 Paul Tanui Kenya (KEN) 1622.83 4 Bedan Karoki Kenya (KEN) 1624.77 5 Galen Rupp United States (USA) 1628.91 6 Abrar Osman Eritrea (ERI) 1663.21 7 Ali Kaya Turkey (TUR) 1663.69 8 Timothy Toroitich Uganda (UGA) 1664.90...
Data of a perfect competition market for good X is given by the following supply and...
Data of a perfect competition market for good X is given by the following supply and demand equation: (D) : P = -1/2*Q + 600 (S): P = 1/2*Q + 350 The world price; Pw = 450$ Assume that the country is small and there is free trade. a. Calculate the imported amount of good X, domestic quantity supplied and quantity demanded at the world price. b. Now the government imposes a tax of t = 10$/ imported unit, identify...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT