### 1. Job Sequencing with Deadline and knapsack
### 1. Job Sequencing with Deadline and knapsack
We are given a set of jobs, each with a deadline and a profit, and the objective is
to maximize the total profit by scheduling these jobs within their deadlines. The
jobs are:
#### Steps:
1. **Sort Jobs by Profit**: To maximize profit, we first sort the jobs in
descending order of profit.
2. **Schedule Jobs**: Now, schedule each job based on its deadline, checking the
latest available slot.
We are given a knapsack with a capacity of 50 kg and items with the following
weights and values:
#### Steps:
1. **Calculate Value per Unit Weight**: To maximize the value, we should consider
the items with the highest value per weight first.
2. **Sort by Value per Unit Weight**: The items are already sorted.
**Greedy Selection**:
- Select Item 2 (1 kg), total value = 10.
- Select Item 4 (2 kg), total value = 15. Now the knapsack holds 3 kg.
- Select Item 3 (3 kg), total value = 20. Now the knapsack holds 6 kg.
- Select Item 1 (2 kg), total value = 12. Now the knapsack holds 8 kg.
However, the optimal solution is obtained using dynamic programming, not the greedy
method.
#### Steps:
1. **Dynamic Programming Approach**:
- Create a DP table where the rows represent the items and the columns represent
the capacity from 0 to 15.
- Fill the table by considering two possibilities for each item:
- Exclude the item.
- Include the item if its weight is less than or equal to the current
capacity.
For a given graph, we can use Dijkstra’s algorithm to find the shortest path from a
source vertex to all other vertices. Here’s the general process:
1. **Initialization**: Set the distance of the source vertex to 0 and all other
vertices to infinity.
2. **Update Distances**: For each vertex, update the distances of its adjacent
vertices by adding the edge weight to the current distance.
3. **Choose Minimum Distance**: Select the vertex with the minimum distance that
hasn’t been visited yet, and repeat the process until all vertices are visited.
### 6. **Dijkstra's Algorithm to Find the Shortest Path from Vertex 1 to Vertex 7**
We are asked to find the shortest path from vertex 1 to vertex 7 using Dijkstra's
algorithm. Assuming the graph is provided, the following steps would be performed:
#### Example:
- \( 1 \rightarrow 2 = 5 \)
- \( 2 \rightarrow 3 = 7 \)
- \( 3 \rightarrow 7 = 9 \)
- \( 1 \rightarrow 4 = 10 \)
- \( 4 \rightarrow 7 = 15 \)
Dijkstra’s algorithm will explore the shortest path from vertex 1 to vertex 7,
which in this case may follow the path \( 1 \rightarrow 2 \rightarrow 3 \rightarrow
7 \).