Questions tagged [divide-and-conquer]

Divide-and-conquer is a top-down technique for designing algorithms that consists of dividing the problem into smaller subproblems hoping that the solutions of the subproblems are easier to find and then composing the partial solutions into the solution of the original problem.

The basic idea of divide-and-conquer technique is

1.Divide: Decompose problems into sub instances.
2.Conquer: Solve sub instances successively and independently.
3.Combine: Combine the sub solutions to obtain the solution to the original problem.

706 questions
3
votes
4 answers

Calculate the total resistance of a circuit given in a string

I have really been struggling to solve this problem. This is the problem: Given a string describing the circuit, calculate the total resistance of the circuit. Here is an example: input: 3 5 S expected output: 8 The operands in the string are…
3
votes
1 answer

Naive Divide-and-Conquer Approach to Polynomial Multiplication

Given two polynomials A(x) = a0 + a1x + a2x2 + ... + an-1xn-1, and B(x), defined similarly with coefficients b0, b1 ... bn-1, we seek A(x) * B(x). I'm examining a simple divide and conquer algorithm as a preface to learning Karatsuba's algorithm,…
rw435
  • 305
  • 2
  • 11
3
votes
1 answer

How does recursion work in a divide and conquer maxima set algorithm?

Here is a pseudo code algorithm from an algorithm textbook by Goodrich for finding the dominating 2D points in a set of points, known as finding maxima sets: Algorithm MaximaSet(S): Input: A set,S,of n points in the plane Output: The set, M, of…
Femke
  • 85
  • 8
3
votes
2 answers

Max Profits of Stock Prices

I am trying to figure out a divide and conquer algorithm with O(nlogn) time to solve the following real world problem - Suppose we have an array of stock prices. Come up with an algorithm that prints out an array with the max profit for every day i…
user4309564
3
votes
2 answers

Counting Inversions between 2 arrays

I am looking for an algorithm to solve this problem: Given 2 arrays, A and B which are both permutations of [1..n], what is the number of inversions between these 2? An inversion here would be when a pair elements (i,j) this holds: if A.indexOf(i) >…
van Leemhuyzen
  • 133
  • 1
  • 10
3
votes
3 answers

Finding max and min using divide and conquer approach

I know this is a silly question,but I'm not getting this at all. In this code taken from http://somnathkayal.blogspot.in/2012/08/finding-maximum-and-minimum-using.html public int[] maxMin(int[] a,int i,int j,int max,int min) { int…
Frosted Cupcake
  • 1,909
  • 2
  • 20
  • 42
3
votes
2 answers

Check if Sorted Array has A[i] = i using Divide and Conquer

I am given a sorted array having distinct elements. Return true if A[i] = i else return false; I am required to just return true or false, and not the position. I have implemented the code, but there is some minor bug. private static boolean…
Jay Patel
  • 1,266
  • 6
  • 20
  • 38
3
votes
1 answer

O(nlogn) divide and conquer algorithm to find visible lines

I am trying to solve the problem shown in the image attached. I got the divide part, where you would recursively divide the line sets into halves and the lines with the smallest and largest slope would be visible. I don't know how to do the merge…
user1869735
3
votes
1 answer

Divide and conquer strategy to merge multiple sorted arrays

Using divide and conquer strategy how can I merg k sorted arrays each with n elements into a single array of k*n elements? Understanding so far: I got some understanding about the steps to do Divide and conquer like : Divide the list of arrays in…
Ka Mal
  • 145
  • 3
  • 11
3
votes
2 answers

Coded UI testing: What is the reasoning behind creating multiple individual UIMap classes instead of just multiple partial UIMap classes?

I am working on a project which includes a "semi-big" application GUI. There are about 4-5 individual(complex) pages I want to perform Coded UI Tests on, and I have gotten the impression that creating multiple UIMaps is the way to go! Sources: UIMap…
Yakitawa
  • 169
  • 1
  • 8
3
votes
1 answer

The smallest free number - divide and conquer algorithm

I'm reading a book Pearls of Functional Algorithm Design. Tried implementing the divide and conquer solution for smallest free number problem. minfree xs = minfrom 0 (length xs) xs minfrom a 0 _ = a minfrom a n xs = if m == b - a …
Dulguun Otgon
  • 1,925
  • 1
  • 19
  • 38
3
votes
1 answer

Streaming big data while sorting

I have huge data and as a result I cannot hold all of it in memory and I always get out of memory errors; obviously one of the solutions would be using streaming in Node.JS; but streaming is not possible(as far as I know) with sorting which is one…
user385729
  • 1,924
  • 9
  • 29
  • 42
3
votes
2 answers

Finding a maximum sum contiguous sub array - another version

There are a lot of posts in this forum for finding largest sum contiguous subarray. However, a small variation of this problem is, the sub array should at least have two elements. For example, for the input [-2, 3, 4, -5, 9, -13, 100, -101, 7] the…
Hem
  • 619
  • 13
  • 26
3
votes
2 answers

difference of divide and conquer & fork and join

In C++, what's the difference between divide and conquer & fork and join? Is fork and join a specific case of divide and conquer because fork and join only applies in parallelism? Thanks!
3
votes
3 answers

Time Analysis of a divide-and-conquer strategy fo find the max value in a array of size N

I wrote this algorithm that finds the MAX number in a array of size N: find_max (s,e,A){ if (s != e){ mid = floor((e-s)/2) + s; a = find_max(s,mid,A); b = find_max(mid + 1, e,A); if (a > b){ return a; } return…