Statistics

Problem Statement for "SortEstimate"

Problem Statement

You have implemented a sorting algorithm that requires exactly c*n*lg(n) nanoseconds to sort n integers. Here lg denotes the base-2 logarithm. Given time nanoseconds, return the largest double n such that c*n*lg(n) <= time.

Definition

Class:
SortEstimate
Method:
howMany
Parameters:
int, int
Returns:
double
Method signature:
double howMany(int c, int time)
(be sure your method is public)

Notes

  • lg(n) = ln(n)/ln(2) where ln denotes the natural log.
  • Your return value must have a relative or absolute error less than 1e-9.

Constraints

  • c will be between 1 and 100 inclusive.
  • time will be between 1 and 2000000000 inclusive.

Examples

  1. 1

    8

    Returns: 4.0

    Given 8 nanoseconds we can sort 4 integers since 1*4*lg(4) = 4*2 = 8

  2. 1

    1073741824

    Returns: 4.237868701779632E7

  3. 1

    20971520

    Returns: 1048576.0

  4. 1

    1744830463

    Returns: 6.7108863963560425E7

  5. 2

    16

    Returns: 4.0

    Now that c = 2 we need twice as many nanoseconds to sort 4 integers.

  6. 37

    12392342

    Returns: 23104.999312341137

    We can almost sort 23105 integers, but not quite.

  7. 1

    2000000000

    Returns: 7.637495090348122E7

    Largest possible return.

  8. 15

    183518033

    Returns: 634711.5366691528

  9. 94

    528002855

    Returns: 308072.16281298193

  10. 22

    1891962415

    Returns: 3926030.802208677

  11. 19

    21449736

    Returns: 70129.92471231497

  12. 41

    251000508

    Returns: 333658.1565933969

  13. 41

    682091086

    Returns: 844976.7106648742

  14. 15

    324891869

    Returns: 1080626.000222133

  15. 100

    269939035

    Returns: 156438.87972686428

  16. 65

    150597632

    Returns: 135872.67212630875

  17. 82

    1668460444

    Returns: 1019427.0794480281

  18. 94

    698125302

    Returns: 399152.58894443273

  19. 73

    537393400

    Returns: 395894.080674982

  20. 61

    952343733

    Returns: 796412.1957200351

  21. 62

    1668728800

    Returns: 1323517.520513234

  22. 67

    1422724322

    Returns: 1060844.4313069163

  23. 50

    1302510048

    Returns: 1283769.883887477

  24. 72

    1240983207

    Returns: 873315.4015855292

  25. 61

    1668868721

    Returns: 1343872.2486778102

  26. 70

    672611577

    Returns: 507012.8623876511

  27. 41

    844981191

    Returns: 1031674.1952518377

  28. 69

    346799919

    Returns: 277924.8297328659

  29. 96

    1650394599

    Returns: 871225.0564874781

  30. 41

    800275356

    Returns: 980681.0457517206

  31. 47

    1751439252

    Returns: 1793764.4273233637

  32. 72

    1034087829

    Returns: 736868.1134626163

  33. 65

    1405206580

    Returns: 1078722.5591509202

  34. 97

    698397013

    Returns: 387824.0070168886

  35. 45

    1345840599

    Returns: 1460472.8429022175

  36. 92

    1248825953

    Returns: 699151.35947252

  37. 22

    1200654528

    Returns: 2563460.5078692725

  38. 1

    1999999999

    Returns: 7.637495086728776E7

  39. 1

    2000000000

    Returns: 7.637495090348122E7

  40. 2

    1999999997

    Returns: 3.962007767021034E7

  41. 1

    1

    Returns: 1.5596104694623691

  42. 43

    2000000000

    Returns: 2207091.972283502

  43. 100

    1

    Returns: 1.0069076686081029

  44. 1

    3

    Returns: 2.3884234844993384

  45. 100

    2523526

    Returns: 2264.2982128022004

  46. 5

    100

    Returns: 7.081840920218569

  47. 1

    2

    Returns: 2.0

  48. 2

    2000000000

    Returns: 3.962007772642713E7


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: