Unit 2 of 4 · BCA Sem 4

Unit 2: Divide and Conquer

Design and Analysis of Algorithm notes · PTU syllabus (UGCC2519)

3 min read5 topics9 exam questions
On this page
  1. Unit summary
  2. The divide-and-conquer strategy
  3. Binary search and max-min
  4. Merge sort
  5. Quick sort
  6. Strassen's matrix multiplication and the sorting lower bound
  7. Key terms
  8. Quick revision
  9. Important questions

Unit summary

Divide and conquer solves a problem by splitting it into smaller subproblems, solving them recursively and combining the results. This unit applies it to binary search, finding maximum and minimum, merge sort, quick sort and Strassen's matrix multiplication, and proves the lower bound for comparison-based sorting.

After this unit you can

  • Explain the divide-and-conquer strategy
  • Analyse binary search and max-min
  • Analyse merge sort and quick sort in the best and worst cases
  • Explain Strassen's method and the Ω(n log n) sorting lower bound

PTU syllabus topics

  • General concept
  • binary search
  • finding maximum and minimum
  • merge sort
  • quick sort
  • best/worst case analysis
  • Strassen's matrix multiplication
  • lower bound for comparison-based sorting
ProcessDivide and conquer
  1. 1Divide

    Split the problem into smaller parts

  2. 2Conquer

    Solve each part recursively

  3. 3Combine

    Merge the partial solutions

1

Topic 1

The divide-and-conquer strategy

ProcessDivide and conquer
  1. 1Divide

    Split the problem into smaller subproblems

  2. 2Conquer

    Solve each subproblem recursively

  3. 3Combine

    Merge the sub-solutions into the final answer

General recurrence: T(n) = a·T(n/b) + D(n) + C(n), where D and C are the divide and combine costs.

2

Topic 2

Binary search and max-min

  • Binary search compares the key with the middle element and recurses on one half: T(n) = T(n/2) + 1 = O(log n).
  • Max-min (divide and conquer): split the array into halves, find the max and min of each, then compare the two results. It needs 3n/2 − 2 comparisons, fewer than the 2n − 2 of the straightforward method.
3

Topic 3

Merge sort

Divide the array into two halves, sort each recursively, then merge the two sorted halves.

Example

38, 27, 43, 3 → split into (38, 27) and (43, 3) → sorted (27, 38) and (3, 43) → merged 3, 27, 38, 43.

  • T(n) = 2T(n/2) + n = Θ(n log n) in all cases.
  • Stable, but needs O(n) extra space for merging.
4

Topic 4

Quick sort

Choose a pivot, partition the array so smaller elements are on its left and larger on its right, then recursively sort both parts.

ComparisonQuick sort cases
When it happens
Complexity

Best

Pivot splits the array into equal halves

O(n log n)

Average

Random splits

O(n log n)

Worst

Pivot is always the smallest or largest (e.g. sorted input with first element as pivot)

O(n²)

Quick sort sorts in place and is usually faster in practice than merge sort; randomised or median-of-three pivots avoid the worst case.

5

Topic 5

Strassen's matrix multiplication and the sorting lower bound

Ordinary divide and conquer multiplies n × n matrices with 8 multiplications of n/2 × n/2 blocks: T(n) = 8T(n/2) + n² = O(n³). Strassen's method uses only 7 multiplications (with extra additions): T(n) = 7T(n/2) + n² = O(n^2.81). Lower bound for comparison sorting: any comparison-based sort can be modelled as a decision tree with at least n! leaves; its height is at least log₂(n!) = Ω(n log n). So no comparison sort can beat n log n in the worst case — merge sort and heap sort are optimal.

Key terms

Divide and conquer
Split, solve recursively, combine
Merge
Combining two sorted lists into one sorted list
Pivot
The element used to partition in quick sort
Strassen's algorithm
Matrix multiplication with 7 recursive products
Decision tree
A model of comparison-based algorithms

Quick revision

  • Binary search O(log n); max-min 3n/2 − 2 comparisons.
  • Merge sort Θ(n log n), extra space O(n).
  • Quick sort: average O(n log n), worst O(n²).
  • Strassen O(n^2.81); comparison sorting lower bound Ω(n log n).

Important exam questions

Practice questions written to the PTU exam pattern for this unit's syllabus: short answers (Section A style) and long answers (Sections B and C style).

Short-answer questions

  1. Q1.What are the three steps of divide and conquer?
  2. Q2.How many comparisons does the divide-and-conquer max-min algorithm need?
  3. Q3.What is the worst case of quick sort and when does it occur?
  4. Q4.Why is merge sort stable?
  5. Q5.How many multiplications does Strassen's method use?

Long-answer questions

  1. Q1.Explain merge sort with an example and derive its time complexity.
  2. Q2.Explain quick sort, the partition procedure and its best and worst case analysis.
  3. Q3.Explain Strassen's matrix multiplication and its complexity.
  4. Q4.Prove that any comparison-based sorting algorithm needs Ω(n log n) comparisons.

Stuck on this unit?

Message SBS on WhatsApp for help with Design and Analysis of Algorithm, or to ask about studying BCA at Synetic.

WhatsApp us