Suppose that we have a divide and conquer algorithm f(n) such that O(f(n))=O(min(a, b)+f(a)+f(b)) where a+b=n, then what is the worst time complexity of f(n) (explicitly)?

# | User | Rating |
---|---|---|

1 | tourist | 3581 |

2 | OO0OOO00O0OOO0O0…O | 3264 |

3 | mnbvmar | 3246 |

4 | Um_nik | 3194 |

5 | LHiC | 3190 |

6 | Petr | 3161 |

7 | V--o_o--V | 3133 |

8 | CongLingDanPaiSh…5 | 3116 |

9 | ko_osaga | 3115 |

10 | Benq | 3098 |

# | User | Contrib. |
---|---|---|

1 | Radewoosh | 185 |

2 | Errichto | 164 |

3 | rng_58 | 161 |

4 | tourist | 158 |

5 | Vovuh | 150 |

5 | Um_nik | 150 |

7 | Swistakk | 149 |

7 | Petr | 149 |

9 | PikMike | 148 |

10 | 300iq | 147 |

10 | neal | 147 |

Suppose that we have a divide and conquer algorithm f(n) such that O(f(n))=O(min(a, b)+f(a)+f(b)) where a+b=n, then what is the worst time complexity of f(n) (explicitly)?

↑

↓

Codeforces (c) Copyright 2010-2018 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Oct/19/2018 19:46:12 (f1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

The worst case running time is . I'll provide a situation with this exact time complexity and prove the running time:

Suppose a line of length

N. We will consider it as "connected" and as colored with 1 color. You will be given queries, in each query you are given some positionP. with each query, what you will do is you need to look at the current line segment containing positionP. You must break this line at positionPand color only one side of the now-broken line with a new color. You will color the shorter part that you got. The queries will keep coming until you end with single "points" you can't break. This is the exact time complexity you gave: with each query I have a line of some lengthX, then I divide it at some random point and operate on the shorter part, and now I have 2 segments with length summed up toX.Proof of running time being : For each position, let's count the amount of times we colored it (the coloring is the only process we're actually putting time into in the problem). Note that if the current position had some color, and after an operation it had a different color, it means we colored it, and we colored it because when we broke its line, it came out on the smaller part. This smaller part is

at leasttwice as small as the previous segment it was in. Therefor, for each of theNpositions we do at most , so we proved the running time.If you wonder about the specific case when this happens, it's when

a=b, and the recurrence becomes:T(n) =O(n) + 2T(n/ 2), which is a well known recurrence that ends up on .