ResearchPaper On Tornament Tree, Binary Tree, 2-3 Tree
ResearchPaper On Tornament Tree, Binary Tree, 2-3 Tree
We, the students of group 4 of the esteemed CV Raman Global University , Bhubaneshwar,
branch of Computer Engineering (Software Engineering) , 4th Semester, do hereby
acknowledge our greatfulness towards the people associated in the project of experiential
learning.
First of all , We would like to pay our thanks to my respected associated Professor, Dr. Sukanta
Kishor0 Bisoy for giving us this opportunity. He helped us with his knowledge and sufficient
information without which we would not have been able to complete the experiential learning
project. Secondly , We are greatful for the library facility to gather information needed for the
project. Above all , the grace of God of all creations led me to complete the project successfully.
3|Page
CONTENT:
1. ABSTRACT
2. INTRODUCTION
3. OBJECTIVES OF 0/1 & FRACTIONAL KNAPSACK
4. OPERATIONS IN 0/1 & FRACTIONAL KNAPSACK
5. BENEFITS OF 0/1 & FRACTIONAL KNAPSACK
6. PROBLEM STATEMENT
7. ALGORITHM FOR THE CODE
8. CODE & TEXT FILE FOR 0/1 & FRACTIONAL KNAPSACK
9. OUTPUT OF THE CODE
10. TIME COMPLEXITY
11. SPACE COMPLEXITY
12.CONCLUSION
13.REFERENCES
4|Page
ABSTRACT
5|Page
INTRODUCTION
The Knapsack Problem is a fundamental problem in combinatorial optimization that has been
extensively studied and has numerous applications in various fields, including resource
allocation, cryptography, and scheduling. It is a optimization problem that deals with selecting
a subset of items from a given set, each with an associated weight and value, such that the total
weight does not exceed a specified capacity while maximizing the total value of the selected
items.
The 0/1 Knapsack Problem is a variant of the Knapsack Problem in which each item can either
be included entirely or excluded from the knapsack. In this problem, the decision variables are
binary, representing whether an item is included (1) or not (0) in the knapsack. The objective
is to find the subset of items that maximizes the total value while ensuring that the total weight
does not exceed the knapsack's capacity.
The 0/1 Knapsack Problem is an NP-complete problem, meaning that it is computationally
intractable to find an exact solution for large instances in polynomial time. However, numerous
algorithms have been proposed to solve the 0/1 Knapsack Problem, including dynamic
programming, branch-and-bound, and approximation algorithms. These algorithms trade off
between the optimality of the solution and the computational complexity, allowing for efficient
solutions to be found for various problem sizes and constraints.
The Fractional Knapsack Problem can be solved optimally using a greedy approach, which
sorts the items by their value-to-weight ratio and includes them in the knapsack in decreasing
order until the capacity is reached or no more items can be added. This approach provides an
efficient and optimal solution for the Fractional Knapsack Problem, making it a valuable tool
in various resource allocation and optimization scenarios.
Both the 0/1 Knapsack Problem and the Fractional Knapsack Problem have been extensively
studied in the literature, and researchers have explored various techniques to improve the
efficiency of existing algorithms, develop new algorithms, and adapt the problems to specific
application domains. These problems serve as fundamental building blocks for many real-
world optimization problems and continue to be actively researched in the field of
combinatorial optimization.
6|Page
OBJECTIVES OF 0/1 & FRACTIONAL KNAPSACK
The Knapsack Problem is a classic optimization challenge that comes in various forms,
each with unique complexities and applications. Here are some key points from the
sources provided:
- The Knapsack Problem includes variations like the 0/1 Knapsack, Fractional
Knapsack, and Multiple Knapsack scenarios, each with specific characteristics and
objectives.
- The 0/1 Knapsack Problem involves selecting items to maximize total value while
respecting weight constraints, commonly used in scenarios where items cannot be
divided.
- The Fractional Knapsack Problem allows items to be divided, enabling partial
inclusion based on weight or value, providing more flexible solutions for resource
allocation or inventory management.
- The Multiple Knapsack Problem arises when resources need to be distributed across
multiple containers, each with its capacity constraint, requiring optimization of item
allocation across these knapsacks.
- Various algorithms like dynamic programming, greedy algorithms, and evolutionary
approaches are used to tackle the Knapsack Problem, depending on the specific scenario
and constraints.
- The problem's scope extends to real-world applications like financial portfolio
optimization, logistics, and supply chain management, highlighting the relevance of
efficient algorithms in navigating complex resource allocation challenges.
7|Page
OPERATIONS IN 0/1 & FRACTIONAL KNAPSACK
1. Initialization: Initialize the problem by defining the set of items, their respective
weights and values, and the capacity of the knapsack.
2. Dynamic Programming: The 0/1 Knapsack Problem can be solved using a dynamic
programming approach, which involves building a table to store the maximum value
that can be achieved for each possible weight and subset of items.
3. Recursion: The dynamic programming solution involves recursively computing the
maximum value that can be achieved by including or excluding each item, based on the
remaining capacity and the values stored in the table.
4. Backtracking: Once the table is filled, backtracking is performed to determine the
actual subset of items that achieves the maximum value while respecting the capacity
constraint.
8|Page
BENEFITS OF 0/1 & FRACTIONAL KNAPSACK
Both the 0/1 Knapsack and Fractional Knapsack problems offer unique advantages tailored to
different optimization requirements, making them valuable tools in various decision-making
processes and resource allocation challenges.
9|Page
PROBLEM STATEMENT
The 0/1 Knapsack Problem and the Fractional Knapsack Problem are two variations of the
Knapsack Problem, which is a combinatorial optimization problem. The Knapsack Problem
deals with selecting a set of items from a given set, where each item has a certain weight and
value, to maximize the total value while ensuring that the total weight does not exceed a
specified capacity.
The 0/1 Knapsack Problem is a variant where items can only be taken in their entirety or not
taken at all. This problem is solved using dynamic programming, where the state space is
defined by the remaining capacity and the items taken so far. The optimal solution for a given
state is calculated by considering the optimal solutions for the previous states and the current
item.
The Fractional Knapsack Problem, on the other hand, allows items to be taken in fractions,
meaning that the items can be divided into smaller parts. This problem is solved using the
greedy approach, where the items are sorted according to their value-to-weight ratio, and the
items are added to the knapsack in that order until the knapsack is full.
1. Item Selection: In the 0/1 Knapsack Problem, items are selected in their entirety, while in
the Fractional Knapsack Problem, items can be divided into smaller parts.
2. Solution Approach: The 0/1 Knapsack Problem is solved using dynamic programming, while
the Fractional Knapsack Problem is solved using the greedy approach.
3. Complexity: The 0/1 Knapsack Problem has a time complexity of O(N*W), where N is the
number of items and W is the capacity, while the Fractional Knapsack Problem can be solved
in O(NlogN) time using sorting.
10 | P a g e
ALGORITHM FOR THE CODE
11 | P a g e
CODE FOR 0/1 & FRACTIONAL KNAPSACK
12 | P a g e
13 | P a g e
TEXT FILE
14 | P a g e
15 | P a g e
OUTPUT
TERMINAL OUTPUT :
16 | P a g e
TIME COMPLEXITY
17 | P a g e
SPACE COMPLEXITY
3. Other variables:
- The code uses a few other variables like `total_cost`, `total_weight`, `num_selected_items`,
etc.
- The space complexity of these variables is constant, O(1).
The overall space complexity of the code is O(n), where n is the maximum of the number of
items and the number of selected items.
18 | P a g e
CONCLUSION
- Each item can be selected either completely (0) or not at all (1).
- The goal is to maximize the total value of the selected items while not exceeding the capacity
of the knapsack.
- It is typically solved using dynamic programming or greedy algorithms.
- Dynamic programming ensures an optimal solution but has a higher time complexity,
especially for large instances.
- Greedy algorithms, such as sorting items based on their value-to-weight ratio and selecting
them greedily, provide a fast but not always optimal solution.
- The problem is NP-hard, meaning there is no known polynomial-time algorithm that solves
it optimally for all instances.
19 | P a g e
REFERENCES
1. Martello, Silvano, and Paolo Toth. "Knapsack problems: algorithms and computer
implementations." John Wiley & Sons, 1990.
2. Hochbaum, Dorit S. "Approximation algorithms for the subset-sum and knapsack problems."
SIAM Journal on Computing 15.2 (1986): 396-410.
3. Resende, Mauricio GC, and Celso CR Lyra. "A GRASP for the multiple knapsack problem."
INFORMS Journal on Computing 15.4 (2003): 349-365.
4. Orlova, Olga, et al. "On knapsack problems with two dimensional vectors." European
Journal of Operational Research 270.3 (2018): 918-930.
5. Kellerer, Hans, Ulrich Pferschy, and David Pisinger. "Knapsack problems." Springer Berlin
Heidelberg, 2004.
6. Vazirani, Vijay V. "Approximation algorithms." Springer Science & Business Media, 2013.
7. Garey, Michael R., and David S. Johnson. "Computers and intractability: A guide to the
theory of NP-completeness." W. H. Freeman, 1979.
8. Nair, Radhakrishnan, and Sunitha C. R. "Greedy algorithms for the knapsack problems–a
survey." Proceedings of the International Conference on Computing, Communication and
Automation (ICCCA). IEEE, 2016.
9. Liu, Li, and Mengqi Liu. "A hybrid differential evolution algorithm for solving 0-1 knapsack
problems." Proceedings of the 2010 International Conference on E-product E-service and E-
entertainment (ICEEE). IEEE, 2010.
10. Iori, Manuel, et al. "An exact approach for the capacitated vehicle routing problem based
on a two-commodity network flow formulation." Networks 56.1 (2010): 43-59.
20 | P a g e