Department of ISE Vidhya Vikas Institute of Technology
Department of ISE Vidhya Vikas Institute of Technology
1 Introduction 1-78
[Type here]
4 Dynamic Programming 188-257
5 Backtracking 258-317
[Type here]
MODULE – 1
INTRODUCTION
Course Outcomes(COs):
At the end of the course, the students will be able to attain the following
skills.
CO1 Gain knowledge on various algorithmic concepts to solve
problems.
Department of ISE Vidhya Vikas Institute of Technology 1
CO2 Apply the basic knowledge of mathematical fundamentals for
finding time complexity of recursive and non-recursive
algorithms.
CO3 Analyse various problems and choose appropriate algorithmic
technique to use for solving real time problems.
Agenda
What is an Algorithm?
Algorithm Specification
Department of ISE Vidhya Vikas Institute of Technology 2
Analysis Framework
Performance Analysis: Space complexity, Time complexity
Asymptotic Notations: Big-Oh notation (O), Omega notation (Ω),
Theta notation (Θ), and Little-oh notation (o)
Mathematical analysis of Non-Recursive Recursive Algorithms with
Examples .
Important Problem Types: Sorting, Searching, String processing, Graph
Problems, Combinatorial Problems.
Fundamental Data Structures: Stacks, Queues, Graphs, Trees, Sets and Dictionaries.
What is an algorithm?
Algorithmic: The sprit of computing – David Harel.
What is an algorithm?
Recipe, process, method, technique, procedure,
routine,… with the following requirements:
1. Finiteness
Department of ISE Vidhya Vikas Institute of Technology 5
terminates after a finite number of steps
2. Definiteness
rigorously and unambiguously specified
5. Effectiveness
steps are sufficiently simple and basic
Algorithm
Department of ISE Vidhya Vikas Institute of Technology 6
• Can be represented in various forms
• Unambiguity/clearness
• Effectiveness
• Finiteness/termination
• Correctness
What is an algorithm?
An algorithm is a sequence of unambiguous instructions
for solving a problem, i.e., for obtaining a required
output for any legitimate input in a finite amount of
time.
Department of ISE Vidhya Vikas Institute of Technology 7
Problem
Algorithm
Input Output
“Computer”
Why study
algorithms?
• Theoretical importance
Department of ISE Vidhya Vikas Institute of Technology 8
– the core of computer science
• Practical importance
– A practitioner’s toolkit of known algorithms
Euclid’s Algorithm
Problem: Find gcd(m,n), the greatest common divisor of two
nonnegative, not both zero integers m and n
Is this an algorithm?
Sieve of Eratosthenes
Input: Integer n ≥ 2
Output: List of primes less than or equal to n for p ← 2 to n do
A[p] ← p for p ← 2 to sqrt(n) do if A[p] 0 //p hasn’t
been eliminated on previous passes j ← p* p
while j ≤ n do
Example: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Output: 2 3 5 7 11 13 17 19
• Informal definition
– A graph is a collection of points called vertices, some of
which are connected by line segments called edges.
• Modeling real-life problems – Modeling WWW
– Communication networks
– Project scheduling …
• Examples of graph algorithms
– Graph traversal algorithms
– Shortest-path algorithms
– Topological sorting
Department of ISE Vidhya Vikas Institute of Technology 19
Linear Data Structures
• Arrays
– Doubly linked list (next +
– A sequence of n items of the same data previous pointers)
type that are stored contiguously in Arrays
computer memory and made fixed length (need preliminary
• Stacks
– A stack of plates
• insertion/deletion can be done only at the top.
• LIFO
968523
Graphs
• Formal definition
23
Department of ISE Vidhya Vikas Institute of Technology
– A graph G = <V, E> is defined by a pair of two sets: a finite set V of items
called vertices and a set E of vertex pairs called edges.
1 2
3 4
24
Department of ISE Vidhya Vikas Institute of Technology
Graph Representation
• Adjacency matrix
– n x n boolean matrix if |V| is n.
– The element on the ith row and jth column is 1 if there’s an edge from ith vertex
to the jth vertex; otherwise 0.
– The adjacency matrix of an undirected graph is symmetric.
• Adjacency linked lists
– A collection of linked lists, one for each vertex, that contain all the vertices
adjacent to the list’s vertex.
• Which data structure would you use if the graph is a 100 -node star shape?
25
Department of ISE Vidhya Vikas Institute of Technology
0111 2 3 4
0001 4
0001 4
0000
Weighted Graphs
• Weighted graphs
– Graphs or digraphs with numbers assigned to the edges.
5
26
Department of ISE Vidhya Vikas Institute of Technology
1 2
6 9 7
3 4
8
Graph Properties -- Paths and Connectivity
• Paths
– A path from vertex u to v of a graph G is defined as a sequence of
adjacent (connected by an edge) vertices that starts with u and ends with
v.
– Simple paths: All edges of a path are distinct.
– Path lengths: the number of edges, or the number of vertices – 1.
• Connected graphs
27
Department of ISE Vidhya Vikas Institute of Technology
– A graph is said to be connected if for every pair of its vertices u and v
there is a path from u to v.
• Connected component
– The maximum connected subgraph of a given graph.
28
Department of ISE Vidhya Vikas Institute of Technology
• Cycle
– A simple path of a positive length that starts and ends a
the same vertex.
• Acyclic graph
– A graph without cycles
– DAG (Directed Acyclic Graph)
1 2
3 4
29
Department of ISE Vidhya Vikas Institute of Technology
Trees
• Trees
– A tree (or free tree) is a connected acyclic graph.
– Forest: a graph that has no cycles but is not necessarily connected.
• Properties of trees
– For every two vertices in a tree there always exists exactly one simple
path from one of these vertices to the other. Why?
• Rooted trees: The above property makes it possible to select an arbitrary vertex in a free tree
and consider it as the root of the so called rooted tree.
• Levels in a rooted tree. rooted
30
Department of ISE Vidhya Vikas Institute of Technology
3
1 3 5 4 1 5
|E| = |V| - 1 2 4 2
31
Department of ISE Vidhya Vikas Institute of Technology
– If (u, v) is the last edge of the simple path from the root to vertex v, u
is said to be the parent of v and v is called a child of u.
– Vertices that have the same parent are called siblings.
• Leaves
– A vertex without children is called a leaf.
• Subtree
– A vertex v with all its descendants is called the subtree of T rooted at
v.
• Depth of a vertex
32
Department of ISE Vidhya Vikas Institute of Technology
– The length of the simple path from the root to the vertex.
• Height of a tree
– The length of the longest simple path from the root to a leaf.
h=2
3
4 1 5
Ordered Trees
• Ordered trees
33
Department of ISE Vidhya Vikas Institute of Technology
– An ordered tree is a rooted tree in which all the children of each vertex
are ordered.
• Binary trees
– A binary tree is an ordered tree in which every vertex has no more than
two children and each children is designated s either a left child or a right
child of its parent.
• Binary search trees
– Each vertex is assigned a number.
– A number assigned to each parental vertex is larger than all the numbers
in its left subtree and smaller than all the numbers in its right subtree.
• log2n h n – 1, where h is the height of a binary tree and n the size.
9 6
6 8 3 9
5 2 3 2 5 8
34
Department of ISE Vidhya Vikas Institute of Technology
Computing time functions
1 constant
log n logarithmic
n linear
n log n n-log-n
n2 quadratic
n3 cubic
35
Department of ISE Vidhya Vikas Institute of Technology
2n exponential
n! factorial
36
Department of ISE Vidhya Vikas Institute of Technology
37
Department of ISE Vidhya Vikas Institute of Technology
Order of growth
• Most important: Order of growth within a
constant multiple as n→∞
• Example:
– How much faster will the algorithm run on computer that is
twice as fast?
40
Department of ISE Vidhya Vikas Institute of Technology
Establishing order of growth using the definition
Example:
• 5n+2 is O(n); c= 7 and n0 = 1
41
Department of ISE Vidhya Vikas Institute of Technology
Note : The Upper Bound indicates that the function will be the worst case that it
does not consume more than this computing time.
42
Department of ISE Vidhya Vikas Institute of Technology
Big-oh
43
Department of ISE Vidhya Vikas Institute of Technology
44
Department of ISE Vidhya Vikas Institute of Technology
Establishing order of growth using the definition
45
Department of ISE Vidhya Vikas Institute of Technology
Big-omega
46
Department of ISE Vidhya Vikas Institute of Technology
47
Department of ISE Vidhya Vikas Institute of Technology
Establishing order of growth using the definition
Example:
• 3n+2 is Ɵ (n)
• c1 g(n) ≤ f(n) ≤ c2 g(n) for every n ≥ n0
• 3 n ≤ 3n+2 ≤ 4 n for every n0 = 2, c1 = 3, c2 = 4
48
Department of ISE Vidhya Vikas Institute of Technology
Big-theta
49
Department of ISE Vidhya Vikas Institute of Technology
50
Department of ISE Vidhya Vikas Institute of Technology
Properties of asymptotic order of growth
• f(n) O(f(n))
Examples:
• n(n+1)/2 vs. n2
Analysis
Department of ISE Vidhya Vikas Institute of Technology 57
1. Input parameter : n 3.
2. Basic operation:
Comparison A[i] >
max
4.
58
Example 2: Element uniqueness
problem
60
Є O(n2)
3.
4.
Department of ISE Vidhya Vikas Institute of Technology 61
Department of ISE Vidhya Vikas Institute of Technology 62
Department of ISE
64
Department of ISE Vidhya Vikas Institute of Technology 65
Analysis
1. Input parameter is input size n2 X n2
2. Basic operation: Comparison C[i,j] == C[i,j] + A[i,k] *
B[k,j]
Є O(n3)
1 3
n- n-
1 1
1 1 1 1 1 1 1 1
Fibonacci numbers
Department of ISE Vidhya Vikas Institute of Technology 82
The Fibonacci numbers:
0, 1, 1, 2, 3, 5, 8, 13, 21, …
84
Department of ISE Vidhya Vikas Institute of Technology 85
Department of ISE Vidhya Vikas Institute of Technology 86
Little oh Notation (o)
• The asymptotic upper bound provided by
Onotation may or may not be asymptotically
tight. The bound 2n2 = O(n2) is asymptotically
tight but the bound 2n = o(n2) is not.
• We use o-notation to denote an upper bound
that is not asymptotically tight • f(n) = o(g(n));
• 5n + 2 vs. n
Examples:
1. Computing an (a > 0, n a nonnegative integer)
2. Computing n!
Example: 7 3 2 5
Yes
In place:
Stability: yes
Department of ISE Vidhya Vikas Institute of Technology 92
Brute-Force String Matching
• pattern: a string of m characters to search for
• text: a (longer) string of n characters to search in
• problem: find a substring in the text that matches the pattern
Brute-force algorithm
Step 1 Align pattern at beginning of text
Step 2 Moving from left to right, compare each character of
pattern to the corresponding character in text until
• all characters are found to match (successful search); or
• a mismatch is detected
1. Pattern: 001011
Text: 10010101101001100101111010
2. Pattern: happy
Text: It is never too late to have a
happy childhood.
• Weaknesses
Department of ISE Vidhya Vikas Institute of Technolog 98
– rarely yields efficient algorithms
– some brute-force algorithms are unacceptably slow
– not as constructive as some other design techniques
MODULE – 2
DIVIDE AND CONQUER
8 3 2 9 7 1 5 4
The non-recursive version
of Mergesort starts from
8 3 2 9 71 5 4
merging single elements
into sorted pairs.
8 3 2 9 7 1 5 4
3 8 2 9 1 7 4 5
2 3 8 9 1 4 5 7
1 2 3 4 5 7 8 9
A[i] p A[i] p
• Exchange the pivot with the last element in the first (i.e., )
subarray — the pivot is now in its final position
• Sort the two subarrays recursively
• Note : Invented by
Quicksort Example
5 3 1 9 8 2 4 7
2 3 1 4 5 8 9 7
1 2 3 4 5 7 8 9
1 2 3 4 5 7 8 9
1 2 3 4 5 7 8 91
2 3 4 5 7 8 9
• Improvements:
– better pivot selection: median of three partitioning
– switch to insertion sort on small subfiles
– elimination of recursion
These combine to 20-25% improvement
Analysis
Best Case: Best case occurs, when we are
searching the middle element itself. In that case,
total number of comparisons required is 1. there
fore best case time complexity of binary search is
Ω(1).
Analysis
• This algorithm requires 2(n-1) element
comparisons in the best, average, and worst
cases.
Department of ISE Vidhya Vikas Institute of Technology 125
• Now the Best case occurs when the elements
are in increasing order. The number of element
comparisons is n-1.
• The worst case occurs when the element are in
decreasing order. In this case number of
comparisons is 2(n-1).
First Divide-and-Conquer
Algorithm
A small example: A B where A = 2135 and B = 4014
A = (21·102 + 35), B = (40 ·102 + 14)
So, A B = (21 ·102 + 35) (40 ·102 + 14)
= 21 40 ·104 + (21 14 + 35 40) ·102 + 35 14
Second Divide-and-Conquer
Algorithm
A B = A1 B1·10n + (A1 B2 + A2 B1) ·10n/2 + A2 B2
Example of Large-Integer
Multiplication
2135 4014
Department of ISE Vidhya Vikas Institute of Technology 135
= (21*10^2 + 35) * (40*10^2 + 14) =
(21*40)*10^4 + c1*10^2 + 35*14 where c1 =
(21+35)*(40+14) - 21*40 - 35*14, and
21*40 = (2*10 + 1) * (4*10 + 0)
= (2*4)*10^2 + c2*10 + 1*0 where c2 =
(2+1)*(4+0) - 2*4 - 1*0, etc.
Matrix Multiplication
• Brute-force algorithm
C1 = E + I + J- G C2 = D + G
=
C3 = E + F C4 = D + H + J - F
D = A1(B2 – B4)
E = A4( B3 – B1)
F = (A3 + A4) B1
G = (A1 + A2) B4 7 multiplications
H = (A3 – A1) (B1 + B2)
I = (A2 – A4) (B3 +B4) 18 additions
J = (A1 +A4)(B1 +B4)
Department of ISE Vidhya Vikas Institute of Technology 138
Strassen’s Matrix Multiplication
A= B=1 21 1
3 42 2
A1 = 1, A2 =2, A3 = 3, A4 = 4
B1 = 1, B2 = 2, B3 = 2, B4 = 2
1. D = A1(B2 – B4) = 1(1 – 2) = -1
2. E = A4(B3-B1) = 4(2-1) = 4
3. F = (A3 + A4) B1 = (3+4)1 = 7
Department of ISE Vidhya Vikas Institute of Technology 139
4. G = (A1 + A2)B4 = (1+2)2 = 6
5. H = (A3 – A1) (B1 + B2) = (3-1)(1+1) = 4
6. I = (A2 – A4)(B3+B4) = (2-4)(2+2) = -8
7. J = (A1+A4)(B1+B4) = (1+4)(1+2) =
15
5 5
M2 = (A10 + A11) B00 M1 + M4 - M5 + M7 M3 + M5
=
= (3 + 4) * 1 = 7
11 11
M
3
412 M6 == (A (3 10- 2)- A * (5 + 2) = 00) (B00 +7 B 01)
11 6
M2 = (A10 + A11) B00 M1 + M4 - M5 + M7 M3 + M5
=
= (3 + 4) * 5 = 35
19 14
M3 = A00 (B01 - B11) M2 + M4 M1 + M3 - M2 + M6
= 2 * (2 - 2) = 0
Department of ISE Vidhya Vikas Institute of Technology 145
C10 C11
Solve
102 1
0101
4
1 10
A = 2104
013 0B =
20115021
1 350
A1 A2 B1 B2
0130201150211350
A3 A4 B3 B4
1. D = A1 (B2 – B4)
0 11
1
1 0-
* 0450
41
Department of ISE Vidhya Vikas Institute of Technology 147
1 0 -1 0
*
4 1 -5 4
-6 0
-9 4
2. E = A4 (B3 – B1)
Number of multiplications:
M(n) = 7M(n/2), M(1) = 1
1 ……. n-1
1 ……. n/2
(n / 4)
---
a b a b
c d c d
human
fish
sheep
shrimp
plankton wheat
e f g h
Example: 1 e f g h
Efficiency: same as efficiency of the DFS-based algorithm, but how would you
identify a source? How do you remove a source from the dag?
a d
c
b e
Example 2
24-08-2020 4
• Approximations/heuristics:
– traveling salesman problem (TSP)
– knapsack problem
– other combinatorial optimization problems
178
Department of ISE Vidhya Vikas Institute of Technology 179
Change-Making Problem
• Problem Statement: Given coins of several
denominations find out a way to give a customer an
amount with fewest number of coins.
• Example: if denominations are 1,5,10, 25 and 100 and
the change required is 30, the solutions are,
• Amount : 30
• Solutions : 3 x 10 ( 3 coins )
6 x 5 ( 6 coins )
1 x 25 + 5 x 1 ( 6 coins )
Department of ISE Vidhya Vikas Institute of Technology 180
1 x 25 + 1 x 5 ( 2 coins )
The last solution is the optimal one as it gives us change only with 2
coins.
Change-Making Problem
Optimal solution using this method is (x1, x2, x3,x4,x5,x6,x7) = (1, 0,1, 0.57,0,1,0)
Knapsack problem
197
Knapsack Algorithm
Problem - 2
Jobs n= 5
p1,p2,p3,p4,p5 = 20,15,10,1,6 d1,d2,d3,d4,d5
= 2, 2, 1, 3,3
6 c 6 c c
a a a
4 1 1 1
4
2 2
d d d
b 3 b b 3
6 c 6 c c
a a a
1 1 1
4 4
2 2
d d d
b b b 3
3
COST=11 COST=6
4
Department of ISEDepartment of ISE VIDHYA VIKAS Institute of Technology and MgmtVIDHYA
VIKAS Institute of Technology and Mgmt 5 224
5
1 2 3 4
5
Initially S 0 1 0 0 0 0
1 d ∞ 1 60 100 ∞ 10
60 100
1
10 60 10
2 3 0
10
20 3
50 20 2
5 20
4 50 20
5 4
Department of ISEDepartment of ISE VIDHYA VIKAS Institute of Technology and MgmtVIDHYA
VIKAS Institute of Technology and Mgmt 5 225
5
Example
4
Department of ISEDepartment of ISE VIDHYA VIKAS Institute of Technology and MgmtVIDHYA
VIKAS Institute of Technology and Mgmt 5 226
5
1 2 3 4 5
S 1 0 0 0 1
1 d 1 60 100 ∞ 10
60 100
1
10 60 100
2 3
10
20 3
50 20 2
5 20
4 50 20
5 4
Department of ISEDepartment of ISE VIDHYA VIKAS Institute of Technology and MgmtVIDHYA
VIKAS Institute of Technology and Mgmt 5 227
5
Example
4
Department of ISEDepartment of ISE VIDHYA VIKAS Institute of Technology and MgmtVIDHYA
VIKAS Institute of Technology and Mgmt 5 228
5
1 2 3 4 5
S 1 0 0 1 1
1 d 1 60 100 15 10
60 100
1
10 60 100
2 3
10
20 3
50 20 2
5 20
4 50 20
5 4
Department of ISEDepartment of ISE VIDHYA VIKAS Institute of Technology and MgmtVIDHYA
VIKAS Institute of Technology and Mgmt 5 229
5
Example
4
Department of ISEDepartment of ISE VIDHYA VIKAS Institute of Technology and MgmtVIDHYA
VIKAS Institute of Technology and Mgmt 5 230
5
1 2 3 4 5
S 1 0 1 1 1
1 d 1 60 35 15 10
60 100
1
10 60 100
2 3
10
20 3
50 20 2
5 20
4 50 20
5 4
Department of ISEDepartment of ISE VIDHYA VIKAS Institute of Technology and MgmtVIDHYA
VIKAS Institute of Technology and Mgmt 5 231
5
Example Final distance form note 1 to all other nodes
4
Department of ISEDepartment of ISE VIDHYA VIKAS Institute of Technology and MgmtVIDHYA
VIKAS Institute of Technology and Mgmt 5 232
5
1 2 3 4 5
S 1 1 1 1 1
1 d 1 60 35 15 10
60 100
1
10 60 100
2 3
10
20 3
50 20 2
5 20
4 50 20
5 4
Department of ISEDepartment of ISE VIDHYA VIKAS Institute of Technology and MgmtVIDHYA
VIKAS Institute of Technology and Mgmt 5 233
5
4
b c
3 6
Example2 a 7 2
d
d
5 4
e 4
b c
3 6
2 5
Tree vertices Remaining vertices
a d e
7
a(-,0) b(a,3) c(-,∞) d(a,7)
e(-,∞)
4
4 b c
3 6
2 5
a d e
7
b(a,3) c(b,3+4) d(b,3+2) e(-,∞)
4
4
c(b,7) e(d,9)
Department of ISE Vidhya Vikas Institute of Technology 234
7 4
e(d,9)
238
O(|E|log|V|) for graphs represented by adj. lists and
min-heap implementation of priority queue
Dynamic Programming
Invented by American mathematician Richard Bellman in the
1950s to solve optimization problems
Main idea:
-Solve smaller instances once.
-Record solutions in a table.
-Get solution to a larger instance from some smaller instances.
-Optimal solution for the initial instance is obtained from that table.
Department of ISE Vidhya Vikas Institute of Technology 241
Principle of Optimality
249
Department of ISE Vidhya Vikas Institute of Technology 250
Department of ISE VIDHYA VIKAS Institute of Technology and
Mgmt
Multistage Graph
A Multi stage graph G = <V,E> which is a directed graph. In this
graph all the vertices and partitioned into K stages where
K>=2.
{
R(k)[i,j] =
R(k-1)[i,j]
or
(path using just 1 ,…,k-1)
Initial condition?
j
Warshall’s Algorithm (matrix generation)
j
Initial condition?
B D
Average # of comparisons
= 1*0.4 + 2*(0.2+0.3) + 3*0.1
A = 1.7
311
w3 = 3, p3= 16 3 w4 = 2, p4= 11 4 Department of ISEDepartment of
ISE0 - 1 -1 VIDHYA VIKAS Institute of Technology and Mgmt-VIDHYA VIKAS
Institute of Technology and Mgmt1 -1 -1 ?
320
if j<Weights[i] = value←MFKnapsack(i −1,j)
else value←max,MFKnapsack(i −1, j),
values[i]+MFKnapsack(i −1,
j−Weights*i+)- V[i, j+←value
return V[i, j]
MODULE – 5
322
Backtracking
Backtrack’ the Word was first introduced by Dr. D.H. Lehmer in
1950s.
• R.J Walker Was the First man who gave algorithmic description in
1960.
• Later developed by S. Golamb and L. Baumert.
In state space tree, root represents an initial state before the search
for a solution begins. The nodes of the first level in the tree
represent the choice made for the first component of a solution, the
nodes of the second level represent the choices for the second
components, and so on. A node in a state space tree is said to be
promising if it corresponds to a partially constructed solution that
may lead to a complete solution; otherwise a node is said to be non
promising.
Horizontal Attack:
Department of ISE Vidhya Vikas Institute of Technology 330
Row wise attacking is avoided by placing 1st queen in
1st row, 2nd queen in 2nd row and so on.
By placing ith queen in ith row, horizontal attacking can
be avoided
Vertical Attack:
(i, x[i]) means the position of ith queen in row i and
column x[i]
Q4
Diagonal Attack:
Algorithm
Example 2
Department of ISE Vidhya Vikas Institute of Technology 339
Department of ISE Vidhya Vikas Institute of Technology 340
Department of ISE Vidhya Vikas Institute of Technology 341
Example
2 3 4
4 3
3 2 4 3
Dead end
4 2
1 1
Solution Solution
Solution
Hamiltonian Cycle void
NextValue(int k, int G[][], int x[], int n) {
while
(true) {
14321
2 3 4
3 2 4 3
Dead end
4 2
1 1
Solution Solution
Sum of Subsets
Department of ISE Vidhya Vikas Institute of Technology 353
Find a subset of a given set S= {S1, S2, S3, S4, ------ Sn}
Of n +ve integers whose sum is equal to given +ve integer d subject
to the constrains
1. Implicit: All Xi values should be distinct and should belong to
the set S
2. Explicit: optimal solution be = d
Xi of the solution vector is either 1 or 0 depending on weather the
weight Wi is included or not.
X1=1 X1=0
3, 2, 18 0, 2, 18
X2=1 X2=0
8, 3, 13 3, 3, 13
14, 4, 7 8, 4, 7 9, 4, 7 3, 4, 7
X4=1
15, 5, 0
Solution
C 5 8 1 18
4
D 7 6 9 4
10
b J1 b J3 b J4
a 2 2 2
b 6 3 7
c 1 5 1
d 4 4 7
13 14 17
C J3 C J4 C J4
a 2 2 a 2
b 6 6 b 6
c 1 8 c 1
Knapsack Problem
Knapsack Problem: Given n items of known weights wi and values vi, i=1, 2, . . . ,
n,and a knapsack of capacity W, find the most valuable subset of the items that
fit in the knapsack. It is convenient to order the items of a given instance in
descending order by their value-to-weight ratios. Then the first item gives the
Ub = 100
Ub = 100
Ub = 100
24-08-2020