Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For simplicity, assume that n is a power of 2 (but, it is not needed in general). Suppose we are given a two dimensional integer

image text in transcribed
For simplicity, assume that n is a power of 2 (but, it is not needed in general). Suppose we are given a two dimensional integer array A[1n,1n] in which every row is in nondecreasing order (from left to right) and also every column is in nondecreasing order (from top to bottom). Given such an A and an integer x, the problem is to determine if x is present in A : If x is present in A, the algorithm returns true; otherwise, it returns false. By comparing x to every entry in A, we can easily solve the problem in O(n2) time. We want to design a better algorithm using divide and conquer (even faster algorithms than the ones proposed here are possible, but the homework is about divide and conquer). (1) Let T(n) be the complexity of your algorithm when the input array A has n rows and n columns. Consider A divided into four quadrants as shown below: A=A1A3A2A4 Clearly, looking for x in A reduces to looking for x in each of A1,A2, A3, and A4 (each of which is a smaller and similar problem). Let us give names to these subproblems so that we can refer to them later: problem A1 : look for x in AI problem A2 : look for x in A2 problem A3 : look for x in A3 problem A4: look for x in A4 (a) ( 5 pts) Suppose we solve all the four smaller problems (recursively; by dividing into 4 subproblems, until we find x or we are left with problems of size one, and those are the base cases). Do you think this approach will give an algerithm with better complexity than O(n2) ? Justify your answer. There is no need to provide any algorithm

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Be prepared to address excessive absenteeism

Answered: 1 week ago