Algorithm

Getting Started with AlgorithmWhat is an Algorithm?

Characteristics of Algorithm1 Topic

Analysis Framework

Performance Analysis3 Topics

Mathematical Analysis2 Topics

Sorting AlgorithmSorting Algorithm10 Topics

Searching Algorithm6 Topics

Fundamental of Data StructuresStacks

Queues

Graphs

Trees

Sets

Dictionaries

Divide and ConquerGeneral Method

Binary Search

Recurrence Equation for Divide and Conquer

Finding the Maximum and Minimum

Merge Sort

Quick Sort

Stassen’s Matrix Multiplication

Advantages and Disadvantages of Divide and Conquer

Decrease and ConquerInsertion Sort

Topological Sort

Greedy MethodGeneral Method

Coin Change Problem

Knapsack Problem

Job Sequencing with Deadlines

Minimum Cost Spanning Trees2 Topics

Single Source Shortest Paths1 Topic

Optimal Tree Problem1 Topic

Transform and Conquer Approach1 Topic

Dynamic ProgrammingGeneral Method with Examples

Multistage Graphs

Transitive Closure1 Topic

All Pairs Shortest Paths6 Topics

BacktrackingGeneral Method

NQueens Problem

Sum of Subsets problem

Graph Coloring

Hamiltonian Cycles

Branch and Bound2 Topics

0/1 Knapsack problem2 Topics

NPComplete and NPHard Problems1 Topic
Knapsack Problem
Fractions of items can be taken rather than having to make binary (01) choices for each item.
Fractional Knapsack Problem can be solvable by greedy strategy whereas 0 – 1 problem is not.
Steps to solve the Fractional Problem:
 Compute the value per pound for each item.
 Obeying a Greedy Strategy, we take as possible of the item with the highest value per pound.
 If the supply of that element is exhausted and we can still carry more, we take as much as possible of the element with the next value per pound.
 Sorting, the items by value per pound, the greedy algorithm run in O (n log n) time.
Fractional Knapsack (Array v, Array w, int W)
1. for i= 1 to size (v)
2. do p [i] = v [i] / w [i]
3. SortDescending (p)
4. i ← 1
5. while (W>0)
6. do amount = min (W, w [i])
7. solution [i] = amount
8. W= Wamount
9. i ← i+1
10. return solution
Example: Consider 5 items along their respective weights and values: –
I = (I_{1},I_{2},I_{3},I_{4},I_{5})
w = (5, 10, 20, 30, 40)
v = (30, 20, 100, 90,160)
The capacity of knapsack W = 60
Now fill the knapsack according to the decreasing value of p_{i}.
First, we choose the item I_{i} whose weight is 5.
Then choose item I_{3} whose weight is 20. Now,the total weight of knapsack is 20 + 5 = 25
Now the next item is I_{5}, and its weight is 40, but we want only 35, so we chose the fractional part of it,
Solution:
ITEM  w_{i}  v_{i} 

I_{1}  5  30 
I_{2}  10  20 
I_{3}  20  100 
I_{4}  30  90 
I_{5}  40  160 
Taking value per weight ratio i.e. p_{i}=
ITEM  w_{i}  v_{i}  P_{i}= 

I_{1}  5  30  6.0 
I_{2}  10  20  2.0 
I_{3}  20  100  5.0 
I_{4}  30  90  3.0 
I_{5}  40  160  4.0 
Now, arrange the value of p_{i} in decreasing order.
ITEM  w_{i}  v_{i}  p_{i}= 

I_{1}  5  30  6.0 
I_{3}  20  100  5.0 
I_{5}  40  160  4.0 
I_{4}  30  90  3.0 
I_{2}  10  20  2.0 