GATE CSE
First time here? Checkout the FAQ!
x
0 votes
331 views
i know time complexity is O(nlogn) but can upper bound given in question consider as TRUE..
asked in Algorithms by Junior (877 points)   | 331 views
Yes, it is nlogn, bcz we sort them in nlogn. If we not consider the sorting it may take n^2. Or if we take sorting with algo who give complexity of n^2.
Whenever we apply sorting in any problem, we use the best sorting algorithm available. Since merge sort or heap sort take O(nlogn) for best, average and worst case, which is the optimal time among all sorting algorithms, we use merge/heap sort to sort the profits of the objects in fractional knapsack. Hence, time taken will be O(nlogn) in any case. So, O(n^2) is false.

3 Answers

0 votes
time complexity of fractional knapsack is θ(nlogn)
in worst,best or average case
answered by Veteran (10.6k points)  
for 0/1 knapsack is it O(2^n)
@anjana only if weight is not constant then it can be exponential
@saurabh rai  ...should we consider O(n^2) as correct as it is upper bound of O(nlogn).
^  0/1 knapsack is np-complete problem
@saurab rai

there is no fix upper bound exist for any algorithm
what is fix is tightest upper bound it is best to use nlogn here
but it may also true nbcoz it belongs to class O(nlogn)

@saurabh rai..but made easy gave it as wrong in ALGO Advance test....
ll u plzz post a screenshot f that.... so that is easy 2 understand
0 votes
SEE, it can be O(n^2),O(n^3) anything greater than O(nlogn)
BUT we usually consider the tightest upper bound that is O(nlogn)
answered by (361 points)  
0 votes

First sort according to profit to weight ratio time req : nlogn
Then we need one scan to find out max take of profit to weight ratio time needed is: n
Overall Time complexity : nlogn + n = O(nlogn)

answered by Junior (751 points)  

Related questions

0 votes
1 answer
2
asked in Algorithms by Sarvottam Patel Junior (929 points)   | 73 views


Top Users May 2017
  1. akash.dinkar12

    3598 Points

  2. pawan kumarln

    2314 Points

  3. Bikram

    1958 Points

  4. Arjun

    1942 Points

  5. sh!va

    1682 Points

  6. Debashish Deka

    1296 Points

  7. Devshree Dubey

    1282 Points

  8. Arunav Khare

    1122 Points

  9. Angkit

    1072 Points

  10. LeenSharma

    1028 Points

Monthly Topper: Rs. 500 gift card
Top Users 2017 May 29 - Jun 04
  1. Arjun

    292 Points

  2. Arunav Khare

    246 Points

  3. Arnab Bhadra

    122 Points

  4. Rupendra Choudhary

    116 Points

  5. pC

    110 Points


22,912 questions
29,253 answers
65,411 comments
27,750 users