mini project
TRANSCRIPT
Mini Project
PREPARED BY: VIKAS TIWARI
ROLL NO: 30
Randomized
algorithms
1.Numerical AlgorithmFor some problems, finding the exact
solution requires a long time, randomness can be used to find an approximate
numerical solution of such problems.
All these algorithms are called numerical probabilistic algorithms.
These algorithms produce approximate results and the quality of the solution can be
improved if we run the algorithm for a longer time
2. Monte Carlo Algorithm
The randomized algorithm runs for a fixed number of steps for each input and produces an answer that is correct with a bounded probability. That is it may produces incorrect solution.
It has a fixed deterministic running time
For decision problems: Two Kinds
1. one-sided error
2. Two-sided error
1. One-sided error
• It is said to have one-sided error if there is a non-zero probability that it errors is zero for at least one of the possible outputs (YES / NO) that it produces.
• Example: Min-Cut algorithm, which is better, Monte Carlo or Las Vegas.
Two-sided error
• A Monte Carlo algorithms is said to have tow-sided error if there is a non-zero probability that it errors when it outputs either YES or NO.
Greedy Method
Prim’s Algorithm
4
37
1 2
5
6
25
14
11
20
12
2223
10
Prim’s Algorithm
4
37
1 2
5
6
Total Wait = 0
Step 1:
Prim’s Algorithm
4
37
1 2
5
6
10
Total Weight = 10
Step 2:
Prim’s Algorithm
4
37
1 2
5
6
23
10
Step 3:
Total Weight = 33
Prim’s Algorithm
4
37
1 2
5
6
20
23
10
Step 4:
Total Weight = 53
Prim’s Algorithm
4
37
1 2
5
6
11
20
23
10
Step 5:
Total Weight: 64
Prim’s Algorithm
4
37
1 2
5
6
14
11
20
23
10
Step 6:
Total Weight = 78
Prim’s Algorithm
4
37
1 2
5
6
14
11
20
23
10
Step 7:
Total Weight = 90
12
Kruskal’s Algorithm
4
37
1 2
5
6
25
14
11
20
12
2223
10
First we select all the vertices. Then an edge with optimum weight is selected from heap, even though it is not adjacent to previously selected edge.
Kruskal’s Algorithm
4
37
1 2
5
6
Total Wait = 0
Step 1:
Kruskal’s Algorithm
4
37
1 2
5
6
10
Total Weight = 10
Step 2:
Kruskal’s Algorithm
4
37
1 2
5
6
10
Total Weight = 21
Step 3:
11
Kruskal’s Algorithm
4
37
1 2
5
6
10
Total Weight = 33
Step 4:
11
12
Kruskal’s Algorithm
4
37
1 2
5
6
10
Total Weight = 47
Step 5:
11
12 14
Kruskal’s Algorithm
4
37
1 2
5
6
10
Total Weight = 67
Step 6:
11
12 14
20
Kruskal’s Algorithm
4
37
1 2
5
6
10
Total Weight = 90
Step 7:
11
12 14
20
23
Backtracking
n-Queen’s Problem
Let us take 4-queens and 4 x 4 chessboard.
Now we start with chessboard.
n-Queen’s Problem
Q
row and column.
n-Queen’s Problem
Q
Q
row and column.
n-Queen’s Problem
Q
row and column.
Q
n-Queen’s Problem
Q
row and column.
Q
Q
Divide and Conquer
Binary Search
• Consider a list of elements stored in array A as
10 20 30 40 50 60 70
0 1 2 3 4 5 6
Low High
Mid
Left sublist Right sublist
Middle element m = (low + high)/2
Thank You