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
6
votes
3 answers

does using divide & conquer improve the time complexity to find max and min in an array

This was the question, I was asked in interview. What is the best time complexity you can get to find a min and max of array? I replied: O(n). Iterate through the array, keeping track of the max and min found so far. very simple and…
brain storm
  • 30,124
  • 69
  • 225
  • 393
6
votes
3 answers

Master's theorem with f(n)=log n

For master's theorem T(n) = a*T(n/b) + f(n) I am using 3 cases: If a*f(n/b) = c*f(n) for some constant c > 1 then T(n) = (n^log(b) a) If a*f(n/b) = f(n) then T(n) = (f(n) log(b) n) If a*f(n/b) = c*f(n) for some constant c < 1 then T(n) =…
amir shadaab
  • 469
  • 3
  • 9
  • 23
6
votes
6 answers

Why should Insertion Sort be used after threshold crossover in Merge Sort

I have read everywhere that for divide and conquer sorting algorithms like Merge-Sort and Quicksort, instead of recursing until only a single element is left, it is better to shift to Insertion-Sort when a certain threshold, say 30 elements, is…
SexyBeast
  • 7,913
  • 28
  • 108
  • 196
5
votes
2 answers

solving T(n) = 2T(n/2) + log n

I am trying to solve T(n) = 2T(n/2) + log n substituted n = 2^k T(2^k) = 2T(2^(k-1)) + k T(2^k) = 2^2 T(2^(k-1)) + 2(k-1) + k after k steps T(2^k) = 2^k T(1) + 2^(k-1) + 2 * (2^(k-2)) +....+k So basically I need to sum a term of i*2^i where i =…
ocwirk
  • 1,079
  • 1
  • 15
  • 35
5
votes
4 answers

Find the least element in an array, which has a pattern

An array is given such that its element's value increases from 0th index through some (k-1) index. At k the value is minimum, and than it starts increasing again through the nth element. Find the minimum element. Essentially, its one sorted list…
ocwirk
  • 1,079
  • 1
  • 15
  • 35
5
votes
1 answer

What are overlapping subproblems in Dynamic Programming (DP)?

There are two key attributes that a problem must have in order for dynamic programming to be applicable: optimal substructure and overlapping subproblems [1]. For this question, we going to focus on the latter property only. There are various…
5
votes
3 answers

divide and conquer approach for exponentiation?

As homework, I should implement a divide and conquer approach for exponentiation of big integers. I know Karatsuba's algorithm for multiplication, what divide and conquer algorithm could I apply to get the result of x^y, both being large integers?.
andandandand
  • 21,946
  • 60
  • 170
  • 271
5
votes
2 answers

An × chessboard is to be cut into its · unit squares

An × chessboard is to be cut into its · unit squares. At each step, you can make either one horizontal cut or one vertical cut. The first cut will split the board into two sub-boards; after that each cut splits one remaining sub-board into two.…
5
votes
3 answers

Most Element in Array Divide-And-Conquer O(N.log(N))

An array a [], with N elements, admitting repeated, is said to "contain a v element mostly" if more than half of its content equals v. Given the array a [], it is intended to draw an efficient algorithm (at time N.log (N) and using…
CodeOnce
  • 79
  • 1
  • 9
5
votes
1 answer

Why is the input size divided by 2 and not 4 in the recurrence of square matrix multiplication?

When analyzing square matrix multiplication runtimes, I understand that the runtimes are for the naive divide-and-conquer method, and for Strassen's method. Why is N divided by 2 and not 4? How I understand it, the coefficient of (8 for naive, 7…
5
votes
1 answer

What is the difference between divide and conquer, and branch and reduce?

What is the difference between divide and conquer, and branch and reduce. From Exact Exponential Algorithms by Fomin and Kratsch, branch and reduce algorithms uses two types of rules: A reduction rule is used to simplify a problem instance or halt…
Henk
  • 369
  • 3
  • 9
5
votes
3 answers

Matrix Multiplication using Divide and Conquer, Time Complexity

I understand that the algorithm uses 8 multiplications and 4 additions with time-complexity: The multiplication is done on every n/2 * n/2 matrices. I have few questions on this : Does every n * nmatrix finally gets reduced to n=1 size by…
5
votes
2 answers

Count number of intervals containing another interval?

Given two lists each containing N intervals (subset of the number line), each interval with form of a start point and endpoint. How many pairs of these intervals from one list contains intervals from another list? For example: If list A is {(1,7),…
5
votes
3 answers

Finding a majority of unorderable items

I have this one problem with finding solution to this task. You have N students and N courses. Student can attend only one course and one course can be attended by many students. Two students are classmates if they are attending same course.…
5
votes
6 answers

Divide and conquer algorithm for sum of integer array

I'm having a bit of trouble with divide and conquer algorithms and was looking for some help. I am attempting to write a function called sumArray that computes the sum of an array of integers. This function must be done by dividing the array in…
Nea
  • 181
  • 2
  • 3
  • 10
1 2
3
47 48