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

Merging k sorted arrays - Priority Queue vs Traditional Merge-sort merge, when to use which?

Assuming we are given k sorted arrays (each of size n), in which case is using a priority heap better than a traditional merge (similar to the one used in merge-sort) and vice-versa? Priority Queue Approach: In this approach, we have a min heap of…
4
votes
1 answer

Implementing a real "forall" on a list of scala futures

I am using scala (2.12) futures to apply a concurrent divide and conquer approach for a complex problem. Here is some (simplified) context: def solve(list: List[Int], constraints: Con): Future[Boolean] = Future.unit.flatMap{ _ => //positive…
H.Leger
  • 83
  • 6
4
votes
1 answer

Is Quick Sort a Divide & Conquer approach?

I consider Merge sort as divide and conquer because, Divide - Array is literally divided into sub arrays without any processing(compare/swap), and the problem sized is halved/Quartered/.... Conquer - merge() those sub arrays by…
4
votes
3 answers

How do I find the largest value smaller than or equal to X and the smallest value greater than or equal to X?

I am trying to use lower_bound and upper_bound functions from the algorithm library in C++ to find the following things: The largest value smaller than or equal to a number X. The smallest value greater than or equal to a number X. I wrote the…
Deepam Sarmah
  • 155
  • 1
  • 8
4
votes
2 answers

Given a file containing 4.30 billion 32-bit integers, how can we find a number, which has appeared at least twice?

I have come up with divide and conquer algorithm for this. Just wanted to know if this would work or not? First mid is calculated from the integer range i.e. (0+(1<<32-1))>>1 and then this idea is applied: range of number from start to mid or from…
4
votes
2 answers

Finding a dip in a list. Can this be done in O(log n)?

I have a list of integers and I am trying to achieve O(log n) by using a recursive algorithm to identify a dip in a list of integers. A dip is any number which is immediately followed by and follows a number equal than or greater than itself, and…
4
votes
2 answers

Divide and Conquer Algorithms (Application of Binary Search?!)

I am new here. Being a grad student, I have been brainstorming on algorithms for a while now. I appreciate any help that can be extended regarding the problem below. I have searched enough and I couldn't find any close solution to this problem. We…
whyme
  • 101
  • 5
4
votes
5 answers

Is `log(n)` base 10?

Still getting a grip on logarithms being the opposite of exponentials. (Would it also be correct to describe them as the inversion of exponentials?) There are lots of great SO entries already on Big-O notation including O(log n) and QuickSort n(log…
MikeiLL
  • 6,282
  • 5
  • 37
  • 68
4
votes
1 answer

In-place implementation of Strassen algorithm?

I managed to implement an in-place solution though index manipulations for naive Divide & Conquer algorithm for matrix multiplication which requires 8 recursive calls in each recurrence. However, when trying to implement Strassen algorithm, I…
Xing Hu
  • 128
  • 10
4
votes
3 answers

Recursive unsorted array search algorithm in C?

Let's say we want to write a function in C that finds a specified target value in an unsorted array of ints. In general, this is simple and runs in O(n) time: int search(int *data, int len, int target) { int i; for(i = 0; i < len; i++) …
Govind Parmar
  • 20,656
  • 7
  • 53
  • 85
4
votes
3 answers

Complexity of inefficient divide and conquer algorithm

An instance of size n is divided into p≥2 instances each of size n-a where a is a small integer and p is a constant. The computation cost of this operation (i.e. dividing into instances) is a unit, with C(0)=1. I am trying to find the complexity of…
4
votes
1 answer

Reverse a linked list as big as having 7 million nodes efficiently using Threads

I was asked this question to reverse a singly linked list as big as having 7 million nodes by using threads efficiently. Using recursion doesn't look feasible if there are so many nodes so I opted for divide and conquer where in each thread be given…
Vihaan Verma
  • 12,815
  • 19
  • 97
  • 126
4
votes
1 answer

closest to zero [absolute value] sum of consecutive subsequence of a sequence of real values

this is an algorithmic playground for me! I've seen variations of this problem tackling maximum consecutive subsequence but this is another variation as well. the formal def: given A[1..n] find i and j so that abs(A[i]+A[i+1]+...+A[j]) is closest to…
4
votes
2 answers

shortest distance in a series of xy coordinates

I have an assignment which compares 2 different algorithms for a problem. Here's the problem: Suppose I have a series of xy coords like this : A(2,3), B(5,6), C(7,8), D(6,2), E(5,5), etc.. And I want to find 2 coords which have the shortest…
Jason
  • 452
  • 2
  • 10
  • 27
4
votes
1 answer

What is wrong with my logic for the divide and conquer algorithm for Closest Pair Problem?

I have been following Coursera's course on Algorithms and came up with a thought about the divide/conquer algorithm for the closest pair problem, that I want clarified. As per Prof Roughgarden's algorithm (which you can see here if you're…
Programming Noob
  • 1,755
  • 5
  • 19
  • 28