Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

?Create an algorithm for the following and give its running time. Further Explan

ID: 3669274 • Letter: #

Question

?Create an algorithm for the following and give its running time.

Further Explanation:

Let f(s) be a function from a finite set S into itself. Define for all s S, f^(0)(s) = s and f^(n)(s) = f(f^(n - 1)(s)) for n>0. Give an efficient algorithm to identify for each x the smallest n and k such that f^(n)(x) = f^(n+k)(x). Analyse the running time of your algorithm as a function of n and k. How much space does your algorithm use as a function of n and k. You are asked to find, for each x, the lowest numbers n and k such that f^(n)(x) = f^(n+k)(x). You are looking for an algorithm that will find the first "cycle" of length k. Since f maps from S to S, f^(n) (x) S, for all n. Fix any x. If we repeatedly apply f to x (as in f(X), f(f(x)), f(f(f(x))),..,f^(k)(x)), one of these f^(i)(x), where 0 lessthanorequalto i e k, is equal to an element f^(j)(x), where 0 lessthanorequalto j lessthanorequalto i lessthanorequalto n, that we have already mapped to, since S is finite. You need to find an efficient algorithm to find these indices i and j.

Explanation / Answer

As per question, would prefer Randomized Selection Algorithm. In the randomized selection algorithm to select the ith smallest element of a set S, we randomly choose a pivot element n in S, divide the rest of S into those elements that come before n (in the underlying order of S) and those that come after, put the pivot into the smaller set, and then recursively apply the randomized selection algorithm to find the appropriate element of the appropriate set.


As per Algorithm: RANDOMIZED-SELECT(A,i)
1. We pick an element x A uniformly at random.
2. Partition around x. Let k = rank(x).
3. If i = k, then return x.
If i < k, then recursively call RANDOMIZED-SELECT(A[1,...,k 1], i).
If i > k, then recursively call RANDOMIZED-SELECT(A[k +1,...,i], i k).

RANDOMIZED-SELECT makes several random choices one in each recursive call. This will help us find the first cycle of length k too.

Hope this provides inputs to your query.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote