The pseudocode listed below is for the unbounded knapsack problem.
operation ub-ks (n, K)
// n is the total number of items, K is the capacity of the knapsack
{
for (int h = 0; h < K; h++)
V[0, h] = 0; // initializes the bottom row of the table
for (int i = 0; i < n; i++) {
for (int kp = 0; kp < K; kp++) {
ans = V[i-1, kp]; // case 1: item i not included
if (size[i] <= kp) { // if the ith item's size is less than kp...
other = val[i] + V[i-1, kp - size[i]];
// ...then case 2: item i is included
if (other > ans) // case 3: both are possible, so take the max
ans = other;
V[i, kp] = ans;
}
}
}
return V[n, K];
} // end ub-ks
Merkle-Hellman's Knapsack algorithm is based on the NP-class "knapsack" problem, in which a series of items with different weights are put into a knapsack capable of holding a certain weight S. As an example, take the objects of weight 1, 4, 6, 11, 17, and 29 where the S can be equal to 11 (1+4+6, or just 11) and not 13. The time necessary to solve this problem increases exponentially as the number of items increase, as the only conventional method being exhaustive search, and is easily solvable with 5 objects but not 1000.
yes
the number of steps of an algorithm will be countable and finite.
Here is the algorithm of the algorithm to write an algorithm to access a pointer in a variable. Algorithmically.name_of_the_structure dot name_of_the _field,eg:mystruct.pointerfield
By preparing test cases we can test an algorithm. The algorithm is tested with each test case.
a write the algorithm to concatenate two given string
yes
if the objects in the knapsack are already being sorted then it requires only O(n) times to arrange the objects...so total time require by the knapsack problem is T(n)=(nlogn) because sorting the objects require O(nlogn) time...Remaining is to run for n objects O(n). Hence, bounded by O(nlogn)
Algarithm: Algorithm is process to solve the problem in a step by step order Algorithm is used to write the program in a computer language. thrinath.sachin@gmail.com
An "algorithm" is a method to solve a problem. These methods are more or less independent of the language. First you think about how you will solve a certain problem, step by step. Then you translate this into a computer program.
pls soon answer my query....
1 Define the problem 2 Analyze the problem 3 Develop an algorithm/method of solution 4 Write a computer program corresponding to the algorithm 5 Test and debug the program 6 Document the program (how it works and how to use it)
the number of steps of an algorithm will be countable and finite.
Here is the algorithm of the algorithm to write an algorithm to access a pointer in a variable. Algorithmically.name_of_the_structure dot name_of_the _field,eg:mystruct.pointerfield
By preparing test cases we can test an algorithm. The algorithm is tested with each test case.
Write an algorithm to find the root of quadratic equation
There is no specific Hard and Fast rule for writing algorithm. The normal method is the following: 1. get a problem 2. find or invent an algorithm to solve it 3. implement the algorithm in a programming language (C, for example)
a write the algorithm to concatenate two given string