Why is divide and conquer algorithms so painful to implement?

So there are plenty of other difficult algorithms to implement. I am sure Dynamic programming tops the list when it comes to competitive programming. But after you do a few questions, it sort of becomes less painful. There are like 5 ~ 6 standard DP problems. More or less every DP question that is asked in a 45-minute interview is a variation of that.

But! D&C! I have never been able to "conquer" anything that is "divide and conquerish", be it binary search or merge sort. Those off by 1 error are so painful to debug. Like all of my array sorts fine, but the middle two elements are out of order. Or I am trying to find a 0 in an array, and it finds the left most zero instead of the rightmost zero. I've spent nearly 10 hours on an easy binary search question in Leetcode and I still managed to get to 40/44 case passing. And I am pretty sure if someone asks me to implement Binary search/Quicksort in an interview, I won't be able to. The only thing I can do is mug up the code and type it out exactly in the interview and pray that it works. Why is this so freaking hard?

πŸ‘︎ 46
πŸ“°︎ r/algorithms
πŸ’¬︎
πŸ“…︎ May 03 2020
🚨︎ report
Divide and Conquer - An Algorithm Design Paradigm youtu.be/Pu2KeAy8BGY
πŸ‘︎ 4
πŸ“°︎ r/developer
πŸ’¬︎
πŸ‘€︎ u/leooister
πŸ“…︎ Jun 03 2020
🚨︎ report
Divide And Conquer Algorithms In Python skerritt.blog/divide-and-…
πŸ‘︎ 22
πŸ“°︎ r/Python
πŸ’¬︎
πŸ‘€︎ u/bbno3
πŸ“…︎ Oct 15 2019
🚨︎ report
A Gentle Introduction to Divide and Conquer Algorithms skerritt.blog/divide-and-…
πŸ‘︎ 8
πŸ“°︎ r/programming
πŸ’¬︎
πŸ‘€︎ u/bbno3
πŸ“…︎ Apr 01 2019
🚨︎ report
Is quick-sort a "divide and conquer" algorithm?

In my opinion, it isn't. In fact, you get the solution for the current problem before performing the division in two subproblems. You don't conquer at the end of the algorithm

πŸ‘︎ 2
πŸ“°︎ r/algorithms
πŸ’¬︎
πŸ‘€︎ u/f_andreuzzi
πŸ“…︎ May 20 2019
🚨︎ report
This is the last Efficient sort algorithm I did, Pixel Merge sort. Merge is a divide and conquer algorithm invented by John von Neumann in 1945. Because genius can create one of the most efficient sorting methods ever until quicksort arrives. v.redd.it/u5jfbsgtqmv21
πŸ‘︎ 43
πŸ“°︎ r/pixelsorting
πŸ’¬︎
πŸ‘€︎ u/Volfegan
πŸ“…︎ May 01 2019
🚨︎ report
Divide and Conquer Algorithms and Recursion

I'm currently studying for an exam and I have a question I can't find an answer to.

- Why would I not use a recursive divide and conquer algorithm on a small data set?

πŸ‘︎ 2
πŸ“°︎ r/AskProgrammers
πŸ’¬︎
πŸ‘€︎ u/Orkwyte
πŸ“…︎ Jun 12 2019
🚨︎ report
A Gentle Introduction to Divide and Conquer Algorithms skerritt.blog/divide-and-…
πŸ‘︎ 5
πŸ“°︎ r/coding
πŸ’¬︎
πŸ‘€︎ u/bbno3
πŸ“…︎ Apr 11 2019
🚨︎ report
Divide and Conquer Algorithm question

My friend has a question they came across while studying and don't know the answer to. (The question is looking at running times of algorithms.) There isn't anything in the book to see how to work this question out. Their guess, when it says find the best case or worst case, plug either of the values 0 or ((n/2)-1) into k. Zero seems to be slower.

But the question asks for /any/ value, so that's why I'm posting this.

I posted the question on IMGUR and I'll link it here: https://imgur.com/a/KP2o10y

πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/aifae
πŸ“…︎ Feb 18 2019
🚨︎ report
Computing Convex Hulls: Divide and Conquer Algorithm youtu.be/582Bayt9Teg
πŸ‘︎ 5
πŸ“°︎ r/programming
πŸ’¬︎
πŸ‘€︎ u/BlackSpade741
πŸ“…︎ Oct 23 2018
🚨︎ report
Divide and Conquer Algorithm
def merge (A , B):
i = 0
j = 0
C = []
while i < len(A) and j < len(B):
    if A [i] <= B [j]:
        C.append(A[i])
        i += 1
    else:
        C.append(B[j])
        j += 1

return C + A[i:] + B[j:]

Lets say we have [[1],[2],[3],[4]]

I want [1,2,3,4]

Given merge takes in 2 lists at a time and sorts AND merges them.

Example: [[2],[1]] after merge = [1,2]

since here [[1],[2],[3],[4]], p=4 and number of elements in each sublist=1

Using D&C we want p/2 calls

so how can I get [[1],[2],[3],[4]] into [1,2,3,4] in just two merge calls?

πŸ‘︎ 3
πŸ“°︎ r/learnpython
πŸ’¬︎
πŸ‘€︎ u/Heskinammo
πŸ“…︎ Oct 29 2017
🚨︎ report
Can divide-and-conquer algorithms be parallelized well?

Think for example of the Cooley-Turkey FFT, or Merge Sort. Say we have an input size of N, with M processors/compute-units available for multithreading.

For a simple O(N^2) DFT, which does N dot products of vectors of length N, we can make parallel the output of every element of the vector X, where X = Wx (W is the Vandermonde matrix). So our running time can become: O(N^2 / M). One of those simple "throw more CPUs at the problem".

But for those more complicated divide-conquer-merge algorithms, I'm wondering how throwing more CPUs at the problem can help. These algorithms will have run times looking like O(NlogN), but I don't see clearly that we can improve this to O(NlogN / M) like in the simpler algorithm.

Assuming we can't parallelize, then this would suggest sticking with the NlogN algorithms until M approaches N/logN, right? ;)

Would love to know what you guys think, cheers.

πŸ‘︎ 13
πŸ“°︎ r/compsci
πŸ’¬︎
πŸ‘€︎ u/vcxzzxcv
πŸ“…︎ Dec 20 2012
🚨︎ report
Is there a paralleled algorithm version of the divide and conquer version of the maximum single sell profit algorithm?

http://keithschwarz.com/interesting/code/?dir=single-sell-profit

πŸ‘︎ 4
πŸ“°︎ r/compsci
πŸ’¬︎
πŸ‘€︎ u/daf121
πŸ“…︎ Oct 09 2014
🚨︎ report
Review of MIT's "Introduction to Algorithms" course. Part two: Divide and Conquer catonmat.net/blog/mit-int…
πŸ‘︎ 24
πŸ“°︎ r/programming
πŸ’¬︎
πŸ‘€︎ u/pkrumins
πŸ“…︎ Aug 21 2008
🚨︎ report
[Discrete Math] Divide and conquer algorithm for voting

Suppose that each person in a group of n people votes for exactly two people from a slate of candidates to fill two positions on a committee. The top three finishers both win positions as long as each receives more than n / 2 votes.

Devise a divide and conquer algorithm that determines whether the three candidates who received the most votes each received n / 2 votes, and if so, determine who these three candidates are.

πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/fromageVert
πŸ“…︎ May 01 2012
🚨︎ report
Divide and Conquer is something more than just a class of algorithms imgur.com/cnfZrmW
πŸ‘︎ 3
πŸ“°︎ r/peace
πŸ’¬︎
πŸ‘€︎ u/soczewka
πŸ“…︎ Sep 11 2013
🚨︎ report
Learning to Divide-and-Conquer: Applying the L* Algorithm to Automate Assume-Guarantee Reasoning by C. S. Pasareanu, D. Giannakopoulou, M. Gheorghiu Bobaru, J. M. Cobleigh, and H. Barringer [PDF] sp09.pbworks.com/f/Learni…
πŸ‘︎ 3
πŸ“°︎ r/REMath
πŸ’¬︎
πŸ‘€︎ u/turnersr
πŸ“…︎ Dec 25 2012
🚨︎ report
Expanding divide and conquer algorithm of closest pair calculation to 3D

I have previously calculated closest pair by brute force iterating through my matrix of points (n-by-3), which was 'ok', but slow and required some simple parallelisation-I am in Matlab so this constituted using a parfor loop.

However, the problem I now face is I have a new data set where n is ~2e6, so brute force isn't an option.

I have found a recursive option, divide and conquer for closest pair and even a code for Matlab. But these are for 2D cases and I cannot understand the change to higher dimensions.

Anyone have advice or a suggestion? I would love to get this working and prove my post-doc wrong, who said letting me loose on using a recursive was like giving a monkey a hand grenade! ΰ² _ΰ² 

Apologies if this is the wrong place to post.

πŸ‘︎ 2
πŸ“°︎ r/learnprogramming
πŸ’¬︎
πŸ‘€︎ u/notverynovelname
πŸ“…︎ Dec 03 2012
🚨︎ report
MIT's Introduction to Algorithms, Lecture 3: Divide and Conquer catonmat.net/blog/mit-int…
πŸ‘︎ 17
πŸ“°︎ r/lectures
πŸ’¬︎
πŸ‘€︎ u/pkrumins
πŸ“…︎ Sep 08 2008
🚨︎ report

Please note that this site uses cookies to personalise content and adverts, to provide social media features, and to analyse web traffic. Click here for more information.