We consider the following problem: Suppose that you are given a 0/1 string S of kind 1m0n, that is, it has m01 's at the beginning, followed by n00 's. Note that m and n are unknown to the algorithm, only k=m+n is known. Also note, that either m or n can be equal to zero, but not both. (a) [14 marks] Design a divide-and-conquer algorithm that finds the number of zeroes in S in time O(logk), where k=m+n. Assume that the input string S is given in an array S[1,,k]. Give a brief argument showing that your algorithm is correct. (b) [12 marks] Give an argument that your algorithm indeed has O(logk) running time, by formulating, explaining and solving an appropriate recurrence equation. Assume that each comparison or arithmetic operation takes constant time..
We consider the following problem: Suppose that you are given a 0/1 string S of kind 1m0n, that is, it has m01 's at the beginning, followed by n00 's. Note that m and n are unknown to the algorithm, only k=m+n is known. Also note, that either m or n can be equal to zero, but not both. (a) [14 marks] Design a divide-and-conquer algorithm that finds the number of zeroes in S in time O(logk), where k=m+n. Assume that the input string S is given in an array S[1,,k]. Give a brief argument showing that your algorithm is correct. (b) [12 marks] Give an argument that your algorithm indeed has O(logk) running time, by formulating, explaining and solving an appropriate recurrence equation. Assume that each comparison or arithmetic operation takes constant time..