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

Java mergesort doesn't work

I have wriiten a code for mergesort(recursive) in java. I tried debugging it in IntelliJ but it didn't do anything public class Main { public static void main(String[] args) { int[] ar = {20, 35, -15, 7, 55, 1, -22}; …
-1
votes
5 answers

Finding the most Repetitive number using Divide and Conquer approach?

I have an integer arrayList which is 5, 12, 5, 17, 5, 5, 5, 39 and I tried to find the most repeating number and it works which will print 5. However, I want to write it by using divide and conquer approach. Any tips would be helpful (pseudocode,…
-1
votes
1 answer

C++ template argument deduction/substitution failed:

I am quite new to C++ and I am experiencing some of its features. In particular, I would like to implement a generic Divide and Conquer procedure that takes as parameter the 'functional code' to solve the problem. Actually what I have in mind is…
Francesco
  • 29
  • 4
-1
votes
1 answer

Time complexity for a divide and conquer algorithm that creates two uneven subproblems.

I am working with a very specific divide and conquer algorithm that always divides a problem with n elements into two subproblems with n/2 - 1 and n/2 + 1 elements. I am pretty sure the time complexity remains O(n log n), but I wonder how could I…
-1
votes
2 answers

How does recursion of Quick sort work?

The functions below are an implementation of Quick sort. Here we take the last element as a pivot. I understood the partition function(where the pivot comes to its sorted position) but I can't understand the recursive function qs. The function qs…
-1
votes
1 answer

Karatsuba multiplication improvement

I have implemented Karatsuba multiplication algorithm for my educational goals. Now I am looking for further improvments. I have implemented some kind of long arithmetic and it works well whether I do not use the base of integer representation more…
vpetrigo
  • 325
  • 2
  • 9
-1
votes
2 answers

Count of an element in a matrix using Divide & Conquer

I'm starting to learn how to implement divide and conquer algorithms, but I'm having some trouble with this exercise. I have written an algorithm but unfortunately it returns a 0 value. I need to count how many times a number finds in the matrix…
Ruben P
  • 191
  • 1
  • 1
  • 9
-1
votes
3 answers

Out of memory [divide and conquer algorithm]

So I have a foo table, which is huge and whenever I try to read all data from that table Node.JS gives me out of memory error! However still you can get chuncks of data by having offset and limit; but again I cannot merge all of the chuncks and have…
user385729
  • 1,924
  • 9
  • 29
  • 42
-1
votes
1 answer

1D Peak, on execution says an error has caused the code to be stop working

I am trying to find the 1D peak through Divide and Conquer technique in this particular question, my program even though it runs, but at the time of giving the final output it says that there has been some problem with the execution, I have got the…
Dhruv K
  • 55
  • 4
-1
votes
1 answer

Calculating optimal division for each element in array

Suppose I have array of positive integers, each standing for a length of a rod, e.g.: [26, 103, 59] I want to find some positive integer size into which I will cut each of these rods. I will be penalized by the total number of cuts I make and by…
-1
votes
2 answers

Couple of points that are closer to each other in a list

I have to do an algorithm, aprop, using divide and conquer to calculate the couple of points that are closer to each other in a list and also I have to calculate the complexity. def aprop(a): longitudlista = len(a) if longitudlista <= 2: …
Cristiano
  • 11
  • 3
-1
votes
1 answer

Find Min Length Substring Containing All Given Strings

Given a large document and a short pattern consisting of a few words (eg. W1 W2 W3), find the shortest string that has all the words in any order (for eg. W2 foo bar dog W1 cat W3 -- is a valid pattern) I structured the "large document" as a…
John Roberts
  • 5,885
  • 21
  • 70
  • 124
-1
votes
1 answer

counting number of inversions using merge sort

i wrote the following code for counting the number of inversions in c++ using divide and conquer but it's not working can someone tell me what is going wrong here? Can someone explain what is wrong with my code and not post a link to any other…
arrhhh
  • 99
  • 2
  • 16
-2
votes
0 answers

In a two-dimensional space how do i find the three closest pair points in O(n log n) time? is the same as closest pair point but the three smallest?

There are no repetition of points and the logic is the logic same as in the case of closest pair points? Do I only have to return the 3 shortest distances? I cant properly understand if the questions wants that or something else
-2
votes
1 answer

Divide and Conquer algorithm to count appearances of an Element in an array without sorting it

Me and Friend were discussing if we can count how many a certain Element k appears in the array A[1....n] using Divide and Conquer algorithm without sorting the Array? We reached a Blockade that if we use Binary search it will stop once it finds the…