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

Divide et impera on a data frame in R

As we all know R isn't the most efficient platform to run large analyses. If I had a large data frame containing three parameters: GROUP X Y A 1 2 A 2 2 A 2 3 ... B 1 1 B 2 3 B 1 4 ... millions of…
Mulone
  • 3,603
  • 9
  • 47
  • 69
-1
votes
1 answer

Find the missing value in an unsorted array using divide and conquer with O(n) complexity

We have an unsorted array size of n-1, that has the numbers from 1 to n excluding one number. We need to find that missing number. Like if we have as input [8,1,5,4,2,7,6], then it should return 3. Constraints I got: Try to collect smaller patient…
-1
votes
1 answer

convert to divide and conquer algorithm. Kotlin

convert method "FINAL" to divide and conquer algorithm the task sounded like this: The buyer has n coins of H1,...,Hn. The seller has m coins in denominations of B1,...,Bm. Can the buyer purchase the item the cost S so that the seller has an exact…
-1
votes
1 answer

Difference of memory usage of divide and conquer and normal linear functions to find max element of a vector

I was curious about how much difference occured when if I implement a code to find max elelment of a vector and I've used two functions: one of them uses divide and conquer algorithm and other uses normal recursion. At the first glance, I thought…
MyZeths
  • 1
  • 2
-1
votes
1 answer

TSP using divide and conquer

I'm solving traveling salesman problem in different ways. I've already solved it using backtracking and greedy algorithms. Now I have to solve it using divide and conquer. I understand how divide and conquer works but I can't understand how I can…
-1
votes
2 answers

what's the growth order of "find a peak" algorithm

hello i need to apply an algorithm similar to this but the problem is that i need the complexity to be O(logn). the complexity of the code below is said to be O(logn) but from what i understand a recursive method has the growth order of O(n). so the…
-1
votes
1 answer

How to Solve this task ()=4(/4)+√n?

I'm new to Divide and Conquer. I would like to know how to find out the running time of this calculation? What exactly do I have to pay attention to and how do I proceed? n=1 runningtime = O(1)
-1
votes
1 answer

karatsuba algorithm error on very long numbers

I learnt about Karatsuba algorithm which allows me to multiply very big numbers using divide and conquer method. Here's my code. I wrote a function which returns the length of a number then I write the multiply function and I used the method with 4…
varo111
  • 307
  • 1
  • 3
  • 8
-1
votes
2 answers

Find the number of intersections of n line segments with endpoints on two parallel lines

Finding the number of intersections of n line segments with endpoints on two parallel lines. Let there be two sets of n points: A={p1,p2,…,pn} on y=0 B={q1,q2,…,qn} on y=1 Each point pi is connected to its corresponding point qi to form a line…
Lily
  • 142
  • 9
-1
votes
1 answer

An Divide and conquer algorithm with complexity O(n log n)

I have two sequences of numbers (a1, a2, ... , an) and (b1, b2, ... , bn). For any i, j ∈ [n] we say (ai, bi) and (aj, bj ) agree if either ai < aj ∧ bi < bj or ai > aj ∧ bi > bj I can assume that all numbers are different.) Otherwise they disagree.…
-1
votes
1 answer

Is a polynomial time algorithm possible for this question or is it a NP-hard problem? If yes, can someone help me with it?

We have been given tree lets say T with vertices set V, now try giving an algorithm to find the minimum cardinality subset of vertices W. Given every vertex in the set V has an edge with at least one vertex in set W.
-1
votes
1 answer

Return 3 elements from function C++

I want to solve a problem, which needs the largest sum of the subarray and it's position. The program's solution is in pseudocode from the book Introductions to algorithms, however it contains a returning which contains 3 elements (low,high,sum).…
Dani Suba
  • 27
  • 6
-1
votes
1 answer

Divide and Conquer Longest Run Recursively

I want to implement an algorithm that finds the longest run of integers in an array recursively, using divide and conquer. I made a sequential algorithm that makes sense, and I think I could do it using recursion. However, I am confused about how I…
chris
  • 1
  • 1
-1
votes
1 answer

Counting inversions in an array of 2D pair

Problem Description: Let there be an array of 2D pairs ((x1, y1), . . . ,(xn, yn)) . With a fixed constant y' a pair (i, j) is called half-inverted if i < j, xi > xj , and yi ≥ y' > yj . Devise an algorithm that counts the number of half-inverted…
codeMike
  • 65
  • 7
-1
votes
1 answer

How to print all subsequences of size m, given number n?

For the below problem: A subsequence of a number is a series of (not necessarily contiguous) digits of the number. For example, 12345 has subsequences that include 123, 234, 124, 245, etc. Your task is to generate subsequence below a certain…
overexchange
  • 15,768
  • 30
  • 152
  • 347