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
9
votes
4 answers

Maximum Subarray: Divide and Conquer

Disclaimer: this is for an assignment. I am not asking for explicit code, only enough help to understand the algorithm involved so that I might fix the errors in my code. Okay, so you're probably familiar with the maximum subarray problem: calculate…
idigyourpast
  • 714
  • 4
  • 12
  • 24
9
votes
1 answer

How to paralellize a divide and conquer algorithm in Clojure

First of all say I have a problem, calculating 1 Billion digits of Pi, calculating the factorial of a large number, or performing mergesort over a large list. I would like to divide the problem into smaller tasks and execute each of the tasks…
11Kilobytes
  • 451
  • 1
  • 6
  • 15
8
votes
3 answers

nth smallest number among two databases of size n each using divide and conquer

We have two databases of size n containing numbers without repeats. So, in total we have 2n elements. They can be accessed through a query to one database at a time. The query is such that you give it a k and it returns kth smallest entry in that…
urfriend
  • 163
  • 3
  • 5
8
votes
2 answers

How to efficiently compute the cosine similarity between millions of strings

I need to compute the cosine similarity between strings in a list. For example, I have a list of over 10 million strings, each string has to determine similarity between itself and every other string in the list. What is the best algorithm I can use…
Kennedy
  • 2,146
  • 6
  • 31
  • 44
7
votes
1 answer

Dynamic programming and Divide and conquer

I was reading notes on Dynamic programming, and I encountered the following comment. If the subproblems are not independent, i.e. subproblems share subsubproblems, then a divideand-conquer algorithm repeatedly solves the common subsubproblems. …
user2434
  • 6,339
  • 18
  • 63
  • 87
7
votes
4 answers

Divide-And-Conquer Algorithm for Trees

I am trying to write a divide & conquer algorithm for trees. For the divide step I need an algorithm that partitions a given undirected Graph G=(V,E) with n nodes and m edges into sub-trees by removing a node. All subgraphs should have the property…
Listing
  • 1,171
  • 2
  • 15
  • 31
7
votes
6 answers

Construct a binary tree from permutation in n log n time

The numbers 1 to n are inserted in a binary search tree in a specified order p_1, p_2,..., p_n. Describe an O(nlog n) time algorithm to construct the resulting final binary search tree. Note that :- I don't need average time n log n, but the worst…
7
votes
3 answers

Tricky algorithm question

Possible Duplicate: Quickest way to find missing number in an array of numbers Input: unsorted array A[1,..,n] which contains all but one of the integers in the range 0,..,n The problem is to determine the missing integer in O(n) time. Each…
7
votes
1 answer

Closest Pair of Points in 3+ Dimensions (Divide and Conquer)

I am struggling to wrap my head around how the divide and conquer algorithm works for dimensions greater than 2, specifically how to find the closest pair of points between two sub-problems. I know that I need to only consider points within a…
DonGato
  • 93
  • 1
  • 4
7
votes
2 answers

Why is the "divide and conquer" method of computing factorials so fast for large ints?

I recently decided to look at factorial algorithms for large integers, and this "divide and conquer" algorithm is faster than a simple iterative approach and the prime-factoring approach: def multiply_range(n, m): print n, m if n == m: …
Broseph
  • 1,655
  • 1
  • 18
  • 38
6
votes
1 answer

Permuting rows in an array to eliminate increasing subsequences

The following problem is taken from Problems on Algorithms (Problem 653): You are given a n x 2 matrix of numbers. Find an O(n log n) algorithm that permutes the rows in the array such that that neither column of the array contains an increasing…
GEP
  • 311
  • 3
  • 12
6
votes
2 answers

Find single number in pairs of unique numbers of a Python list in O(lg n)

I have a question for Divide and Conquering in programming algorithms. Suppose you are given a random integer list in Python which consists of: Unique contiguous pairs of integers A single integer somewhere in the list And the conditions are…
6
votes
1 answer

Peak finding algorithm in 2d-array with complexity O(n)

The question is as the title says. I am trying to figure out if there is a way of finding peak element in 2d-array in O(n) time where n is the length of each side in 2d-array i.e. n^2 total elements. By definition, "peak" in a 2-d array is an…
yStankevich
  • 63
  • 1
  • 5
6
votes
2 answers

Divide and Conquer Algorithm for Finding the Maximum Subarray - How to also provide the result subarray indexes?

Excuse me, I have an assignment to solve the Maximum Sub Array Problem using the Brute Force Algorithm O(n^2), Divide and Conquer O(nlogn) and Kadane's Algorithm O(n). (My code is different). "For example, for the sequence of values {−2, 1, −3, 4,…
Khalil Khalaf
  • 9,259
  • 11
  • 62
  • 104
6
votes
2 answers

Majority Element Python

I'm having trouble getting the right output on my "Majority Element" divide and conquer algorithm implementation in Python 3. This should be relatively correct; however, it would still appear that I'm missing something or it is slightly off and I…
execv3
  • 312
  • 1
  • 4
  • 14
1
2
3
47 48