Answered step by step
Verified Expert Solution
Question
1 Approved Answer
A complete answer consists of three parts: a description of the algorithm, a proof of correctness, and a running time analysis No complicated code: English
A complete answer consists of three parts: a description of the algorithm, a proof of correctness, and a running time analysis No complicated code: English is the best way to express an algorithm combined with some simple pseudocode when needed. You are not writing a computer program so avoid unnecessary details in your algorithms. Problem 3. Given an array A[1 : n] of a combination of n positive and negative integers, our goal is to find whether there is a sub-array All :r] such that [i] = 0. i=1 Example. Given A = (13, 1, 2, 3, -4, -7,2,3,8,9), the elements in A2:8) add up to zero. Thus, in this case, your algorithm should output Yes. On the other hand, if the input array is A = [3, 2, 6, -7, -20, 2, 4], then no sub-array of A adds up to zero and thus your algorithm should output No. Hint: Observe that if [{= A[i] = 0, then [!= 1 A[i] = L1=1 A[i]; this may come handy! (b) Now suppose that there is no promise on the range of the entries of A. Design a randomized algorithm for this problem with expected worst-case runtime of O(n)
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