Divide and Conquer-1
Divide and Conquer-1
The best-case analysis is easy, for a successful search only one element
comparison is needed.
For an unsuccessful search theorem states that [logn] element
comparison is needed in the best case.
In conclusion we are new able to completing describe the computing
time of binary search by giving formulas that describe the best, average
and worst case.
Successful Search's Unsuccessful Search's
O(1) O(logn) o(logn) O(logn)
Best , Average worst , best, average, worst
Finding Maximum and Minimum
22 13 -5 -8 15 60 17 31 47
Algorithm
Algorithm Maxmin(I ,j ,Ma x,Min){
If(i==j) then max=min=a[i]// small(P) Small S(P)
Else if(i==j) then
If(a[i]<a[j]) then
Max=a[J],min=a[i]
Max=a[j], Max=a[j]
}
Else{
//note small p
Mid=[(i+j)/2]
Maximum( j ,mid ,max ,min);
Maximum(mid+1,Max,Min);
If(max<max1) then max=max1;
If(min>min1) then min=min1
}
}
Strassen's Matrix Multiplication
Algorithm Matrix(A,B){
1 multiply two NXN Max Matrix
2 N root[A}
3let (be ab NXN matrix)
4 for i 1 to n
5 do for j to n
6 do C[I,j]=0;
For k 1 to n
Do a[I,j]=(c[I,j]+a[I,j]+B[j,k]+B[k,j])
}}
Divide and conquer strategy
A=
C11=A11B11+A12A21
C12=A11B12+A12B22
C21=A11B11+A22B21
C22=A21B12+A22B22
Strassens Matrix
P=(A11+A12)(B11+B22)
Q=(A21+A22)B11
R=A11(B21-B11)
S=A22(B21-B11)
T=(A111+A12)B22
U=(A11-A12)(B11+B22)
V=(A12-A22)(B21+B22)
C11=P+S --- T+s
C12=R+T
C21=Q+s
C22=P+R-Q+V
For example Matrix
A=2X2 B=2X2
P=(A111+A22)(B11+B22)
P=(4+6)(3+2)=10*5=50
Q=(A21+A22)B11
Q=(5+6)3=(11)3=33
R=A11(B12-B22)
R=4(-2-2)=4(-4)=-16
S=A22(B21-B22)
S=6(4-3)=6(1)=6
T=(A11+A22)B11
T=(4+3)4=7*4=14
U=(A21-A11)(B11+B12)
U=(3-6)(4+2)=-3*6=-18
C11=P+S-T+V
C11=50+6-14+(-18)
C11=56-32
C11=24
C12=R+T
C12=-16+14
C12=-2
C21=Q+s
C21=33+6
C21=39
C22=P+R-Q+v
C22=50+(-16)-33+1
C11=51-49
C11=2
C=2X2
C=2X2
C=2X2
C=2X2
For example
A=2X2
B=2X2
C=2X2
=AXBXC=AXC+BXC
For example Matrix
A=2X2
B=2X2
C=2X2
Quick Sort
Quicksort(A , P,r){
1. If p<r
2. Then partition (A ,P , r)
3. Quicksort (A, P,Q-1)
4. Quicksort (A,Q+1,r)
Algorithm Quick sort
4 5 6 2 8 3
Assignment_4
Thank you