-2

I am weak in math

n<=8logn How to solve this equation to get the value of n,

The question was from algorith " For inputs of size n, insertion sort runs in 8n^2 steps while merge sort runs in 64n lg n steps; for which values of n does insertion sort beat merge sort?

so i figured until..

8n^2<=64nlogn

n^2<=8nlogn n<=8logn

but how to get value of n from here , full math would be helpful and any link to learn basic logarith math is appreciated. Thanks

Mansur Ahamed
  • 53
  • 1
  • 2
  • 7

1 Answers1

2

To figure out for which value of n, 8n^2 and 64nlogn has the same value:

8n2 < 64nlogn
8n.n < 8n.8.logn
n < 8.logn
n/8 < logn

We know m = logaX hence a^m = x, therefore

2^n/8 < n

Analysis of algorithms are done to the base of 2, a = 2. To solve this in Python:

n = 2
while 2 ** (n / 8.0) < n:
   n +=1
print("Maximum value of n for which insertion sort beats merge sort is", n - 1)

References for help on this and other quizzes:

  1. http://atekihcan.github.io/CLRS/
  2. https://github.com/gzc/CLRS
Brayoni
  • 696
  • 7
  • 14