Let
be a permutation of {1,2,……n}.Let
-1 be the (n-1)-tuple with one element from
missing.
Alice shows Bob
-1[i] one by one in the increasing order of i from 1 to
(n-1).bob’s task is to compute the missing element from
-1 that is in
with very limited – O(log n) bits – of memory.
Design an algorithm to compute the missing element in this
memory-limited and access-limited model, i.e Alice can only show
each number to Bob once, and Bob can only use O(log n) bits of
memory. Show that the algorithm is correct and give the time and
memory complexity for this algorithm.e a permutation of
{1,2,……n}.Let
-1 be the (n-1)-tuple with one element from pie
missing.
Alice shows Bob
-1[i] one by one in the increasing order of i from 1 to
(n-1).Bob’s task is to compute the missing element from
-1 that is in
with very limited
– O(log n) bits – of memory.
Design an algorithm to compute the missing element in this memory-limited and access-limited model, i.e Alice can only show each number to Bob once, and Bob can only use O(log n) bits of memory. Show that the algorithm is correct and give the time and memory complexity for this algorithm.
Considering n = 5.
Suppose is a perutation
of P1(1,2,3,4,5), lets assume P1(2,3,1,5,4)
Suppose Alice shows him numbers from -1 , i.e. P2(2, 3,
5,1).
Now as we can see, Both P1 and P2 are sorted.. Alice will give one
number at a time to Bob,
Now Notice that numbers range from 1 to n, to represent a number n in binary(which computer uses), we require log(n) bits.
Also, if we XOR the same numbers together, they will result in 0. While if we XOR number X with 0, result will be 0.
This gives us one clue, that if we combine both P1 and P2 together, there are 2n-1 numbers out of which 2n-2 numbers are in form of pairs(means two 1s, two 2s and so on.. ) there is just single number which is missing from P2 and that need to be find. So If XOR both P1 and P2 together, the pairs will eventually result in 0 (two 1s XOR together will result in 0) and 0 XORed with the number occurring just once in both P1 and P2 together and wil result in that same number, which will be our result..
Do notice that XOR will same amount of bits as any of the numbers itself.. and we already showed the maximum number can take log(n) bits..
So algorithm is to first find the XOR of all the numbers in
. Lets store it
in variable xor_result. Now as alice keeps giving the elements one
by one.. Keep Updating the xor_result as
xor_result = xor_result XOR new_number
Once Alice is done with all the numbers, whatever is remaining in variable xor_result, is our answer.
Complexity: O(N) for finding the XOR of first list, as we need to visit each element.
Memory: log(n) bits
Let be a permutation of {1,2,……n}.Let -1 be the (n-1)-tuple with one element from missing. Alice...
1, and let σ be a permutation of {1, , n). Recall that for each integer m a) Let n 1, we denote ơm--σ ο . . . o σ. Show that n times b) Let 21, and let be a permutation of..,n consisting of a unique cycle of length n. Deduce from the previous question that there exists i e (1,..., n) such that i +c() )+22(n1).
1, and let σ be a permutation of {1, , n). Recall...
Given X={1,2,....,n}, let us call a permutation τ of X an adjacency if it is a transposition of the form (i i+1) for i < n. If i<j prove that (i j) is a product of an odd number of adjacencies.
Let A = [A[1], A[2],…..,A[n]] be an array of n distinct integers. For 1 <= j <= n, the index j is a happy index if A[i] < A[j] for all 1 <= i < j. Describe an O(n)- time algorithm that finds all the happy indices in the array A. Partial credit will be given for an O(n log(n))-time algorithm and a minimal credit will be given for an O(n^2) –time algorithm. What is the running time of your...
(1) Let f : [n] [n] be a permutation. A fixed point of f is an element x e [n] such that f(x) - x. Now consider random permutations of [n] and let X be the random variable which represents the number of fixed points of a given permutation. (a) What is the probability that X 0? (b) What is the probability that X-n -2? (c) What is the probability that X-n-1? (d) What is the expectation of X? (Hint:...
An array A[1,2,... ,n is unimodal if its consists of an increasing sequence followed by sequence a decreasing sequence. More precisely, there exists an index k є {1,2,… ,n} such that there exists an indes . AlE]< Ali1 for all 1 i< k, and Ai]Ali 1 for all k< i< n A1,2,..,n] in O(logn) time the loop invariant (s) that your algorithm maintains and show why they lead to the correctness Give an algorithm to compute the maximum element of...
Alice, Bob, and Chris, in that order and starting with Alice, take turns drawing a random card from a 52 card deck and then returning it to the deck, continuing until an ace is drawn. The first one to draw an ace wins. (a) Explain why Ω = {0 i1 | i ≥ 0} ∪ {the infinite string 000 · · ·} is a reasonable definition of the sample space of this experiment. (b) What is the probability of each...
Let Q:= {1,2,...,q}. Let G be a graph with the elements of Q^n as vertices and an edge between (a1,a2,...,an) and (b1,b2,...bn) if and only if ai is not equal to bi for exactly one value of i. Show that G is Hamiltonian.
1. [5 marks Show the following hold using the definition of Big Oh: a) 2 mark 1729 is O(1) b) 3 marks 2n2-4n -3 is O(n2) 2. [3 marks] Using the definition of Big-Oh, prove that 2n2(n 1) is not O(n2) 3. 6 marks Let f(n),g(n), h(n) be complexity functions. Using the definition of Big-Oh, prove the following two claims a) 3 marks Let k be a positive real constant and f(n) is O(g(n)), then k f(n) is O(g(n)) b)...
Consider the following problem: Input: a list of n-1 integers and these integers are in the range of 1 to n. There are no duplicates in list. One of the integers from 1 to n is missing in the list. Output: find the missing integer Let the input array be [2, 4, 1, 6, 3, 7, 8]. Elements in this list are in the range of 1 to 8. There are no duplicates, and 5 is missing. Your algorithm needs...
Question3 10 pts Let A [L.n] be a max-heap with n > 1 and consider the index ị such that l 〈 i 〈 n . Assume that all the elements of A are distinct. Write the pseudocode of an algorithm which replaces A [i] by A i 100 and then re-arranges the elements of A into a max-heap. The running time of your algorithm must be O (log, n Upload Choose a File
Question3 10 pts Let A [L.n]...