2

an array a[1..n] of elements of some ordered type (i.e. x < y is always defined) and i want to find the smallest value in the array using a "divide and conquer" algorithm.

What does the assignment really mean?

1
  • It means that you're supposed to implement a "divide and conquer" algorithm (probably a recursive one) -- one that breaks the problem down into smaller and smaller pieces until a solution is found (reference). The array definition a[1..n] just says there is an array with n elements in it that are sortable. Commented Apr 20, 2012 at 20:03

6 Answers 6

6

Divide-and-conquer is an algorithmic technique that solves a problem by splitting the problem into smaller pieces, solving the problem in each piece, and combining the results together to form an overall answer. When the problem becomes sufficiently simple, it can be solved directly.

In this case, think about what would happen if you split the array in half. If you knew the minimum value in each half, could you figure out the minimum value overall? And when there's just one element left in the array, what's the minimum value in the array? If you answer this question, you can directly come up with a recursive divide-and-conquer algorithm for the problem.

Hope this helps!

Sign up to request clarification or add additional context in comments.

3 Comments

i know the meaning of divide and conquer... but what does the line an array a[1..n] of elements of some ordered type (i.e. x < y is always defined) mean? Does it mean an unsorted array?
@user1253637- Ah, sorry! I misinterpreted your question. Yes, it means that it's an unsorted array of elements. You don't know what those elements are (strings, integers, widgets, etc.), but any two elements are comparable, so it makes sense to find the minimum. You might want to clarify your question, since it seems like everyone is misinterpreting what you're asking. :-)
It means unsorted list, but operations like x<y is defined, so you'll be able to compare two elements.
1

The divide-and-conquer strategy solves a problem by:

  1. Breaking it into subproblems that are themselves smaller instances of the same type of problem

  2. Recursively solving these subproblems

  3. Appropriately combining their answers

A good example is merge-sort!

http://en.wikipedia.org/wiki/Merge_sort

2 Comments

Suggesting merge sort for this problem is weird. Finding the smallest element is an O(n) linear scan; merge sort is O(n log n).
@TedHopp yeah but merge sort does divide and conqure
0

In general, "divide and conquer" means to divide a problem into smaller (and often simpler) problems, solve each one separately, and then combine the solutions in some way.

In your specific example, you should divide the array into smaller arrays in some manner (e.g., divide it in half), find the smallest value in each smaller array, and then pick the smallest solution of these sub-problems as the solution to the overall problem. Each sub-problem can be solved using the same divide-and-conquer approach, with the limiting case being an array of sufficiently small size (e.g., 1 or 2) that you can solve the problem directly.

Comments

0
  1. If the contents of an array are random, that means you have to search each element until you find the one you're looking for. The longer the array, the longer the search time. This is called a "linear search".

  2. If the contents of an array are already in some kind of order, you can take advantage of this order to optimize your search (and reduce your search time). For example, names in a phone book are sorted alphabetically. You can open the phone book in the middle: if you name you're looking for is "lower than" the name in the middle, then continue searching in the left side of the book. If it's higher, then search the right half. This is called a "binary search", or "Divide and Conquer".

  3. It's possible to quantify how efficient or inefficient a given search algorithm is. This is called "Asymptotic", or "Big O-Notation":

    
    Class                         Search algorithm
    -----                         ----------------
    Data structure                Array
    Worst case performance        O(log n)
    Best case performance         O(1)
    Average case performance      O(log n)
    Worst case space complexity   O(1)

Comments

0

U can go with the following algorithm.

getSmallest(int a[])
{
  int n=a.length;
  if(n==1)
    return a[0];
  else
   {
        x=remove first element from a;
        create another array b with a size smaller by 1 than array a
        if(x<getSmallest(b))
            return x;
        else
           return the smallest returned by the recursive call 
   }
}

Comments

0

http://ankzcode.blogspot.in/2012/11/find-minimum-without-linear-search.html

Code at the link implements the same.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.