Jump to content

time complexity

Featured Replies

time complexity of-

for i:= 1 to n do

for j:= i+1 to n do

for k:= j+1 to n do



if P1/W1 is less than P2/W2...less than Pn/Wn, prove greedy generate optimal solution to knapsack prob.

You haven't explained what i, j an k represent. I assume they are subscripts of three different kinds of things that may be put into the knapsack. Suppose there are M things that may be put in the knapsack, and there are differing amounts of each of the M things, i.e., nM. When M > 3, you need subscripts i, j, k, l, ..., and loops for each one.

 

If M and nM are large enough, not even the fastest super computers can solve the problem quickly.

Edited by EdEarl

 

time complexity of-
for i:= 1 to n do
for j:= i+1 to n do
for k:= j+1 to n do
if P1/W1 is less than P2/W2...less than Pn/Wn, prove greedy generate optimal solution to knapsack prob.

Is this one question or two? It looks like two separate questions to me, one about the time complexity of that loop construct, the other about the knapsack problem. If that's the case, the first question is easy. How many times is the body (not shown) of the innermost loop going to be executed?

 

Regarding the second question, if it is a second question: You need to give us a lot more to go on.

 

 

Note very well: We do notdo your homework for you at this site. Instead we help you do your own homework. This means you need to show some work, and also show some respect by not writing so vaguely.

Archived

This topic is now archived and is closed to further replies.

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.