mini project

32
Mini Project PREPARED BY: VIKAS TIWARI ROLL NO: 30

Upload: banaras-hindu-university

Post on 25-Jul-2015

78 views

Category:

Education


0 download

TRANSCRIPT

Page 1: Mini project

Mini Project

PREPARED BY: VIKAS TIWARI

ROLL NO: 30

Page 2: Mini project

Randomized

algorithms

Page 3: Mini project

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

Page 4: Mini project

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

Page 5: Mini project

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.

Page 6: Mini project

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.

Page 7: Mini project

Greedy Method

Page 8: Mini project

Prim’s Algorithm

4

37

1 2

5

6

25

14

11

20

12

2223

10

Page 9: Mini project

Prim’s Algorithm

4

37

1 2

5

6

Total Wait = 0

Step 1:

Page 10: Mini project

Prim’s Algorithm

4

37

1 2

5

6

10

Total Weight = 10

Step 2:

Page 11: Mini project

Prim’s Algorithm

4

37

1 2

5

6

23

10

Step 3:

Total Weight = 33

Page 12: Mini project

Prim’s Algorithm

4

37

1 2

5

6

20

23

10

Step 4:

Total Weight = 53

Page 13: Mini project

Prim’s Algorithm

4

37

1 2

5

6

11

20

23

10

Step 5:

Total Weight: 64

Page 14: Mini project

Prim’s Algorithm

4

37

1 2

5

6

14

11

20

23

10

Step 6:

Total Weight = 78

Page 15: Mini project

Prim’s Algorithm

4

37

1 2

5

6

14

11

20

23

10

Step 7:

Total Weight = 90

12

Page 16: Mini project

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.

Page 17: Mini project

Kruskal’s Algorithm

4

37

1 2

5

6

Total Wait = 0

Step 1:

Page 18: Mini project

Kruskal’s Algorithm

4

37

1 2

5

6

10

Total Weight = 10

Step 2:

Page 19: Mini project

Kruskal’s Algorithm

4

37

1 2

5

6

10

Total Weight = 21

Step 3:

11

Page 20: Mini project

Kruskal’s Algorithm

4

37

1 2

5

6

10

Total Weight = 33

Step 4:

11

12

Page 21: Mini project

Kruskal’s Algorithm

4

37

1 2

5

6

10

Total Weight = 47

Step 5:

11

12 14

Page 22: Mini project

Kruskal’s Algorithm

4

37

1 2

5

6

10

Total Weight = 67

Step 6:

11

12 14

20

Page 23: Mini project

Kruskal’s Algorithm

4

37

1 2

5

6

10

Total Weight = 90

Step 7:

11

12 14

20

23

Page 24: Mini project

Backtracking

Page 25: Mini project

n-Queen’s Problem

Let us take 4-queens and 4 x 4 chessboard.

Now we start with chessboard.

Page 26: Mini project

n-Queen’s Problem

Q

row and column.

Page 27: Mini project

n-Queen’s Problem

Q

Q

row and column.

Page 28: Mini project

n-Queen’s Problem

Q

row and column.

Q

Page 29: Mini project

n-Queen’s Problem

Q

row and column.

Q

Q

Page 30: Mini project

Divide and Conquer

Page 31: Mini project

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

Page 32: Mini project

Thank You