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
2
votes
2 answers

Reduce the array to 0 in minimum moves with given constraints

You are given a city which lies on the x-axis. It has n buildings. The first building lies in x = 1 and has height h1, the second building lies on x = 2 and has height h2 and so on. You are a gigantic monster with a sword who wants to destroy the…
2
votes
1 answer

Merge sort on linked lists

I was trying a merge sort on linked lists. I was keeping my head variable global and applied the basic algorithm i.e. divide and conquer. I am not understanding why I am getting a segmentation fault. I know I could do it by passing head as a…
2
votes
0 answers

Traveling Salesman Divide and Conquer C++

I am trying to implement the Divide and Conquer Algorithm to solve the Traveling Salesman problem. I divided the problem into smaller parts, but I have no idea what to do next. Here is my code: struct coordinate { float x; float…
Utkan
  • 129
  • 12
2
votes
2 answers

How do I solve this tromino tiling problem?

I am trying to solve this tromino tiling problem for n x n board. Given Missing square co-ordinate(MS) x and y in n x n board, we have to fill the rest of the board with 'L' shaped tile. I have managed to get the output for 2 x 2 board. But, I am…
user9043303
2
votes
3 answers

Check if a vector is ordered using divide et impera algorithm

I am trying to check if a vector is ordered using the divide and conquer algorithm, here's the code I wrote so far: #include #include using namespace std; bool isOrdered(std::vector v, int left, int right) { int mid =…
2
votes
2 answers

What are this java while loops doing in merge sort?

Step one and step two (step three) seem like repeatedly running to me. Why is it programmed like this? int i = 0, j = 0; int k = l; while (i < n1 && j < n2) { ----step one if (L[i] <= R[j]){ arr[k] = L[i]; …
TIGUZI
  • 231
  • 1
  • 3
  • 12
2
votes
2 answers

What is the sublist array that can give us maximum 'flip-flop' sum?

my problem is that I'm given an array of with length l. let's say this is my array: [1,5,4,2,9,3,6] let's call this A. This array can have multiple sub arrays with nodes being adjacent to each other. so we can have [1,5,4] or [2,9,3,6] and so on.…
2
votes
1 answer

How to efficiently traverse Bitmap?

I need to iterate through each pixel of the Bitmap image, this is my code, but it's too slow Bitmap img=......; int imgWidth = img.getWidth(); int imgHeight = img.getHeight(); for (int i = 0; i < imgWidth; i++) { for (int j =…
2
votes
1 answer

Can I compute closest split pair of points where distance is strictly less than delta

The Closest Pair of Points Problem has been intriguing me lately. More specifically, the divide and conquer algorithm. This recursive algorithm requires me to split a set of points into two chunks, a and b and compute the closest pair of points for…
Danilo Souza Morães
  • 1,481
  • 13
  • 18
2
votes
1 answer

Java - Comparing a long list of integers

My code is timing out as it is inefficient. Program takes in a line of n integers. Each consecutive pair of integers represents a single point (x, y) this is an example of input : -5 -10 20 25 30 2 -1…
Jay Jay
  • 57
  • 1
  • 11
2
votes
0 answers

0-1 Knapsack, with 1 constraint! (can only have even number of items in knapsack) (3d array)

I am struggling to come up with a thorough algorithm to the following problem. Similar to the original (or famous) 0-1 Knapsack problem, given a capacity, C, and items (v,w) where each item has a value, v, and a weight, w, we want to obtain the…
2
votes
1 answer

Use Divide and Conquer for find a number into matrix sorted

I need to implement a method/function to determine if a number is present in a matrix. The given matrix is sorted in descending order both in rows and columns. Here there are three examples of the defined matrix: private static int[][] matrix1= { …
Kat
  • 23
  • 1
  • 5
2
votes
1 answer

Divide and Conquer-Returning an array

I'm Recently going through Divide and Conquer Algorithm. I'm able to solve the problems if the return value supposes to be some single integer. Ex:1. Binary Search, here I just need to return 1 if found, else -1. Ex:2. Maximum Number in an array,…
SanQA
  • 233
  • 3
  • 9
2
votes
2 answers

maximum recursion depth exceeded in comparison?

Started learning python, this is maximum sum subarray i have tried. Ending up with "maximum recursion depth exceeded in comparison". My algorithm seems ok to me. Please help me if im doing anything wrong. import sys import math def…
Sivabushan
  • 71
  • 1
  • 8
2
votes
1 answer

Sorting in Java with "Divide and Conquer"

Merge sorting, sorting by dividing a random array in half and then putting them in numeric order. Concept is called "Divide and Conquer." The output is out of order and I don't see anything wrong with this code. Main just outputs all the numbers in…
Stack Over
  • 21
  • 3