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
8 answers

Given a rotated sorted array, how can I find the largest value in that array?

I have given this a lot of thought and was unable to find the most optimal solution. I am preparing for technical interviews, but I haven't found very much stuff related to this question. My first step was to implement a naive O(n) algorithm that…
user2351234
  • 965
  • 2
  • 12
  • 20
3
votes
1 answer

Grouping Symbols Maximum Length Balanced Subsequence

Consider B to be a sequence of grouping symbols (, ), [, ], {, and }. B is called a Balanced sequence if it is of length 0 or B is of one of the following forms: { X } Y or [ X ] Y or { X } Y where X and Y are Balanced themselves. Example for…
3
votes
4 answers

Divide and Conquer Algo to find maximum difference between two ordered elements

Given an array arr[] of integers, find out the difference between any two elements such that larger element appears after the smaller number in arr[]. Max Difference = Max { arr[x] - arr[y] | x > y } Examples: If array is [2, 3, 10, 6, 4, 8, 1, 7]…
instance
  • 1,366
  • 15
  • 23
3
votes
2 answers

C implementation for D&C is faster than Naive solution for matrix multiplication?

Both the Divide & Conquer (D&C) solution and the Naive solution for matrix multiplication are implemented "in-place" with C programming language. So no dynamic memory allocation at all. As we have learned for both solutions, they actually have the…
Xing Hu
  • 128
  • 10
3
votes
1 answer

Dominant set of points in O(n)

So, if two points A(x1,y1) and B(x2,y2) are given, and if x1 <= x2 and y1<= y2, then we say B dominates A. Now, given a lot of points, I wish to find out all the non-dominated points. Trivial approach is compare every point with others and get all…
3
votes
1 answer

How to get rid of sentinels in merge sort?

I understand that the use of sentinel is somewhat equivalent to zero padding(in the sense of complexity). For those who don't know what zero-padding is: we append a number of zeros(or some other values,doesn't matter) to make the size as the power…
Cancan
  • 691
  • 3
  • 14
  • 23
3
votes
3 answers

Difference between Divide and Conquer & Subtract and Conquer?

I have been reading about recursion and solving recurrence equations. Came across a term "subtract and conquer". How is it different from the "Divide and Conquer" technique? Can I solve these kind of problems using the same techniques used for…
Rahul Kurup
  • 693
  • 3
  • 9
  • 22
3
votes
2 answers

What is Order Statistics and ith smallest?

I have an Algorithm course this semester. Everything is fine until I reached the lecture about Order Statistics. Here is the first slide of that lecture: Order Statistics Select the ith smallest of n elements (the element with rank i). • i = 1:…
malhobayyeb
  • 2,725
  • 11
  • 57
  • 91
3
votes
1 answer

Parallel delaunay triangulation

I am trying to parallelize the Guibas Stolfi delaunay triangulation using openmp. There are two things to parallelize here- the mergesort(),which i did and the divide() where I am stuck. I have tried all possible approaches but in vain. The…
2
votes
1 answer

Compare divide and conquer with recursion

When we are talking about divide and conquer ,we always use recursion .I've already known divide and conquer is a technique of algorithm design,but I got one question: Are all divide and conquer algorithms recursion ,or put it another way ,is the…
Gary Gauh
  • 4,984
  • 5
  • 30
  • 43
2
votes
1 answer

Describing the divide, conquer, combining parts of a divide-and-conquer algorithm

I'm solving a practice quiz and came across the following question Write down the recurrence corresponding to the below divide and conquer algorithm, labeling exactly the components for each of: dividing, conquering, and combining. 1. Foo (p,…
ayh
  • 21
  • 2
2
votes
3 answers

In an array find a subarray whose sum of elements multiplied by the smallest element in that subarray yields the greatest value

I need to create an algorithm that takes an array A as an argument and finds a subarray of A whose sum of elements multiplied by the smallest element in that subarray yields the greatest value. Values in A are positive and we cannot change the order…
2
votes
1 answer

Is there a way to cover n elements and make sure they are connected?

I'm trying to create a game but I am having some difficulties in coming up with a suitable algorithm for my problem. I have elements from 1 to n and I am trying to cover all of the elements using the minimum amount of elements as possible. Each…
2
votes
2 answers

Is there a faster way to solve the following problem?

A is a mn matrix B is a nn matrix I want to return matrix C of size m*n such that: In python it could be like below for i in range(m): for j in range(n): C[i][j] = 0 for k in range(n): C[i][j] += max(0, A[i][j] -…
Macosso
  • 1,352
  • 5
  • 22
2
votes
0 answers

Delaunay triangulation, divide and conquer algorithm

I've read about the algorithm in "Two algorithms for constructing a Delaunay triangulation" by D. T. Lee and B. J. Schachter, International Journal of Computer and Information Sciences, Vol. 9, No. 3, 1980. I don't quite understand how to implement…