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

Matrix Multiplication - Divide & Conquer vs Strassen, Divide & Conquer is faster?

From what I understand, Strassen's method for multiplying Matrices should be the fastest... but the Divide & Conquer method is clearly the fastest in my testing... Am I doing something wrong? Or is this correct? The instructions were: "The total…
3
votes
2 answers

How to create node set from values

How can we create a node set from values.... I have n numbers 1,2,3.......n. I want to create a node set 1 2 3 4 .... N
Oong
3
votes
1 answer

How to print a fraction in latex form?

I have a fraction and I want to print the latex form of it. The fraction is like this for n == 3: How can I print the latex for this fraction using divide and conquer: 1+\frac{2+\frac{4}{5}}{3+\frac{6}{7}} And for n == 4 the fraction is: And the…
HosseinSedghian
  • 383
  • 2
  • 15
3
votes
1 answer

Implement Divide and Conquer strategy to apply transformation for a large matrix

I want to apply Arnold's cat map to my matrix. Here is my implementation: import numpy as np def cat_mapping(matrix, MAX): width, height = matrix.shape transformed_matrix = np.empty([width, height]).astype(np.uint8) counter = 1 x =…
falamiw
  • 426
  • 4
  • 16
3
votes
0 answers

How can I check if an algorithmic paradigm can solve a certain type of problem or can not?

Well, I know that algorithmic paradigms are the templates to create algorithms to solve certain type of computational problems. (correct me if I am wrong) But what I don't understand is, "How do I check if the algorithmic paradigm is suitable for…
3
votes
3 answers

How can I make my python program run faster?

I am reading in a .csv file and creating a pandas dataframe. The file is a file of stocks. I am only interested in the date, the company, and the closing cost. I want my program to find the max profit with the starting date, the ending date and the…
Anonomous
  • 31
  • 2
3
votes
1 answer

Defective chessboard problem - looking for pseudocode algorithm (divide&conquer)

I should use the divide-and-conquer paradigm to design a recursive algorithm "CBCover", which determines a coverage (as seen in the image below) in runtime O(n^2) (n = 2^k). The entry/ input of CBCover should be (k, a, b), where k defines the size…
R0MAN
  • 43
  • 5
3
votes
2 answers

Does Divide an Conquer always get better performance?

I'm currently testing some divide and conquer algorithms versus their normal implementations. I'm quite new at this and I'm not sure if I should always get a better performance when using divide and conquer. For example, I've implemented an…
Adrisui3
  • 94
  • 1
  • 7
3
votes
2 answers

Divide and Conquer strategy to determine if more than 1/3 same element in list

I am working an a divide and conquer algorithm to determine if more than 1/3 elements in list are the same. For example: [1,2,3,4] No, all element are unique. [1,1,2,4,5] Yes, 2 of them are the same. Without sorting, is there a divide and conquer…
chen
  • 341
  • 1
  • 3
  • 11
3
votes
1 answer

Divide and Conquer to solve the power of a number, runtime analysis with master theorem

I implemented a divide and conquer algorithm to calculate the power of a number: public static void main(String[] args) { System.out.println("Result: " + pow(2, 1)); System.out.println("Result: " + pow(2, 9)); System.out.println("Result:…
Moritz Schmidt
  • 2,635
  • 3
  • 27
  • 51
3
votes
2 answers

divide and conquer algorithm for finding a 3-colored triangle in an undirected graph with the following properties?

In an undirected Graph G=(V,E) the vertices are colored either red, yellow or green. Furthermore there exist a way to partition the graph into two subsets so that |V1|=|V2| or |V1|=|V2|+1 where the following conditions apply: either every vertex of…
3
votes
0 answers

recursive call on QuickSort algorithm

I have an array as A[] = { 10, 5, 3, 9, 22, 24, 28, 27, 15 }, I wanted to sort this Array using QuickSort. I have a method for quick sort as QuickSort(int[] num, int start, int end) { if(start < end) { int pIndex = Partition(num, start,…
User_4373
  • 379
  • 1
  • 3
  • 17
3
votes
2 answers

Having trouble with divide and conquer algorithm for adding consecutive pairs of ints in an array

So I am attempting to get my head around the divide and conquer principle and multiple recursive calls in a single method. It's going ok but I have a problem with the output of the method I am writing. The purpose of the method is to return the sum…
PumpkinBreath
  • 831
  • 1
  • 9
  • 22
3
votes
2 answers

How to compare each element in two arrays with time complexity less than O(n^2)

Suppose we have two arrays A[n] and b[n], the goal is to compare every element in A to elements in B. Then return a list result[n] that records the number of each element in A that is larger than the elements in B. For example, A = [38, 24, 43,…
Zack
  • 147
  • 2
  • 10
3
votes
1 answer

convert β-bit integer to array of digits using only O(lg β) multiplications and divisions

(edit: the question that my question has been flagged a duplicate of was already linked in my original post, even before the flagging, and I did not consider it sufficient to answer my specific question, why was how to get a certain complexity…
xdavidliu
  • 2,411
  • 14
  • 33