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
1 answer

Recursive - stack overflow error

Given an unsorted array find the max and min values. I'm trying to do this in a recursive, divide and conquer way but I keep getting a stack overflow error. I debugged and i keep getting the error in my recursive calls but do not know what is wrong…
md05062
  • 3
  • 2
  • 6
-3
votes
1 answer

Dynamic Programming to Divide and Conquer

I am working on this program converting a divide and conquer algorithm to a dynamic programming algorithm. The algorithm is for sequencing (like DNA) and finding the cost to do so. Just to reiterate the dynamic programming algorithm is working and…
-3
votes
2 answers

Divide and Conquer Closest Pair Algorithm

I'm trying to create an algorithm that returns the closest pair from randomly generated points. I have finished the algorithm, however the divide and conquer method of the algorithm is not much faster than the brute-force method. What can I do to…
-3
votes
4 answers

Java program to compute the value of (2^n); the program should run with Big-O(2^n)

Is this java program runs with Big-O(2^n)? if not, any suggestions on how to modify it? This program calculates the value of 2^n: public static int exponent(int n) { if (n == 0) return 1; else return 2 * exponent(n -…
Mike
  • 91
  • 2
  • 10
-3
votes
1 answer

Find the 'pits' in a list of integers. Fast

I'm attempting to write a program which finds the 'pits' in a list of integers. A pit is any integer x where x is less than or equal to the integers immediately preceding and following it. If the integer is at the start or end of the list it…
MapReduceFilter
  • 227
  • 2
  • 10
-3
votes
1 answer

Closest pair of points using divide and conquer algorithm to calculate only 6 points during combine phase

This is a question present in Introduction to Algos by Cormen based on the topic of finding closest pair of points where Y' belongs to the vertical strip containing points which are at least some "delta" distance far away from a line "l". d is the…
-3
votes
1 answer

and conquer algorithm - search for pattern in string

I am trying to write a divide divide-and-conquer algorithm in pseudocode that finds how many occurrences of a 3-letter pattern there are in a given string of n letters. Something like this in pseudocode: the pattern is fixed: XXY int…
-3
votes
1 answer

need character to print in output lines

I need these lines to output when a letter is typed instead of a whole number. I am not sure how to get it to do this: I have the code and what I need posted below if you can help me solve this issue, thank you. This is what I am getting: Input a…
-4
votes
1 answer

Divide and conquer solution for finding the majority element in the given input

I am using a divide and conquer strategy to solve the majority problem. An element in said to be in the majority if repeats more than n/2 times where n is the number of elements given in the input. Return 1 if a majority element in present, return 0…
-4
votes
2 answers

Finding minimum and maximum in a array c++

I have to find the minimum and maximum value of elements in a array using divide and conquer. I have written a code but it is not working for more then 6 elements in array. I don't know whats the problem #include using namespace std; int…
-4
votes
1 answer

To reduce the time complexity

I have a question in which I am given a set of values SET A, and a set of values SET B. I am supposed to find the maximum number of pairs possible taking one value from set A and one value with set B. Condition- The difference between the two values…
Kunal Sehegal
  • 63
  • 1
  • 5
-4
votes
1 answer

Worst-case running time of divide and conquer algorithm

I am a student who is taking the programming class data structures and algorithms and I am in need of help with a exam question I cant seem to get a grip off. Here is the problem: Consider the following algorithm func on a given array A = {a1, a2,…
Shaggy
  • 13
  • 3
-5
votes
1 answer

Implement pow(x,n)%d with integers only. (without making use of library functions)

Basically I used the classic divide and conquer whenever the exponent is even and came up with this. int mymod(int a,int b){ //returns only positive value between 0 to b-1 return a%b<0 ? (a%b)+b : a%b; } int Solution::pow(int x, int n, int d) { …
not_again_stackoverflow
  • 1,285
  • 1
  • 13
  • 27
-6
votes
1 answer

Recursions: How recursion works when called twice in a program?

What would be the Output of this program and how it would be? public class Recursion { static int p=100; public static void main(String args[]) { divide(20); } public static void divide(int x) { …
-6
votes
1 answer

Time complexity max min

Simple linear search to find max min algo maxmin(a,n,max,min){ max=min=a[1]; for i=2 to n do{ if a[i]>max then max:=a[i]; else if a[i]
Kris
  • 518
  • 3
  • 13
1 2 3
47
48