Docsity

DIVIDE and CONQUER technique, Exercises of Algorithms and Programming

Partial preview of the text

Download DIVIDE and CONQUER technique and more Exercises Algorithms and Programming in PDF only on Docsity!

Module 2 Divide and Conquer Prof. Hemachander N, Dept. of Computer Science & Engineering Cauvery Institute of Technology, Mandya

Contents

  1. General method
  2. Recurrence equation
  3. Algorithm: Binary search
  4. Algorithm: Finding the maximum and minimum
  5. Algorithm: Merge sort
  6. Algorithm: Quick sort
  7. Algorithm: Strassen’s matrix multiplication
  8. Advantages and Disadvantages
  9. Decrease and Conquer Approach
  10. Algorithm: Topological Sort

Divide and Conquer

Control Abstraction for Divide &Conquer

General Time functionm of DandC

Technique:

where f(n) is a function that accounts for the time spent on dividing the problem into smaller ones and on combining their solutions.

  • (^) T(n)=

Finding Time Complexity of DandC

Algorithms

  • (^) Substitution Method
  • (^) Masters Theorem

Master Theorem

  • (^) It states that, in recurrence equation T(n)=aT(n/b) + f(n) Time complexity can be computed based on how the value of a & bd^ relates to each other. Here d is power of n in f(n)

Example

Find the time complexity of the following equation using substitution method and master theorm [assume T(1)= 0 ]

Excercise

  1. T(n)=T(n-1)+n T(1)=
  2. Solve Recurrence Relation a=2, b=2, f(n)=cn
  3. Solve T(n)=T(n/2)+n, T(1)=
  4. T(n)=2 T(n/2)+1, T(1)=