Computer Sciences > Gate 2015 Set-3 > Sorting Algorithm
Assume that a mergesort algorithm in the worst case takes 30 seconds for an input of size 64. Which of the following most closely approximates the maximum input size of a problem that can be solved in 6 minutes?
A
256
B
512
C
1024
D
2048

Correct : a

Mergesort Time Complexity:
• The worst-case time complexity of Mergesort is Θ(n log n).
• This means that the running time T(n) can be expressed as T(n) = c · n log2 n, where c is a constant and n is the input size.

Calculate the Constant 'c':
We are given that T(64) = 30 seconds.
• Substitute n = 64 into the formula:
    T(64) = c · 64 log2 64
• We know that log2 64 = 6 (since 26 = 64).
    30 = c · 64 · 6
    30 = c · 384
• Solve for c:
    c = 30 / 384

Convert Target Time to Seconds:
The new time limit is 6 minutes.
• 6 minutes = 6 · 60 seconds = 360 seconds.

Set Up Equation for New Input Size:
Let nnew be the maximum input size we can solve in 360 seconds.
• T(nnew) = c · nnew log2 nnew
• Substitute the values for T(nnew) and c:
    360 = (30 / 384) · nnew log2 nnew

Solve for nnew log2 nnew:
• Multiply both sides by 384/30:
    360 · (384 / 30) = nnew log2 nnew
• Simplify the left side:
    (360 / 30) · 384 = nnew log2 nnew
    12 · 384 = nnew log2 nnew
    4608 = nnew log2 nnew

Check the Given Options:
We need to find an nnew such that nnew log2 nnew is approximately 4608.
• For n = 256:
    256 log2 256 = 256 · 8 = 2048
• For n = 512:
    512 log2 512 = 512 · 9 = 4608
• For n = 1024:
    1024 log2 1024 = 1024 · 10 = 10240
• For n = 2048:
    2048 log2 2048 = 2048 · 11 = 22528

Comparing the calculated values with 4608, n = 512 yields an exact match.
Therefore, the maximum input size that can be solved in 6 minutes is 512.

Similar Questions

Let P be a QuickSort Program to sort numbers in ascending order using the first element as pivot. Let t1 and t2 be the number of comparisons made by P for the i...
#15 MCQ
A palindrome is a word that reads the same forwards and backwards. In a game of words, a player has the following two plates painted with letters. From...
#1 MCQ
Which number does not belong in the series below? 2, 5, 10, 17, 26, 37, 50, 64
#4 MCQ

Related Topics

mergesort algorithm worst case time complexity algorithm analysis GATE CS 2015 Set-3 Q3 mergesort input size computer sciences algorithms GATE computer science algorithm problem solving

Unique Visitor Count

Total Unique Visitors

Loading......