- #1
evinda
Gold Member
MHB
- 3,836
- 0
Hello! (Wave)
Given the above algorithm, I want to calculate the time complexity.. (Thinking) The cost of the line $2$ is $1$.
The cost of the line $3$ is $1$.
The cost of the line $4$ is $4$.
The cost of the line $5$ is $2$.
The cost of the line $6$ is $T(\lfloor{\frac{n}{2} \rfloor})+1$.
The cost of the line $7$ is $2$.
The cost of the line $8$ is $T(\lfloor{\frac{n}{2} \rfloor})+1$.
The cost of the line $10$ is $1$.
But.. how can I find now the recurrence relation, that describes the time complexity? (Worried) (Thinking)
Code:
Index BinarySearch(Type A[1...N], Type value, Index low, Index high){
1. Index mid;
2. if (high<low)
3. return -1
4. mid=low+(high-low)/2;
5. if (A[mid]>value)
6. return BinarySearch(A, value, low,mid-1);
7. else if (A[mid]<value)
8. return BinarySearch(A, value, mid+1,high);
9. else
10. return mid
}
Given the above algorithm, I want to calculate the time complexity.. (Thinking) The cost of the line $2$ is $1$.
The cost of the line $3$ is $1$.
The cost of the line $4$ is $4$.
The cost of the line $5$ is $2$.
The cost of the line $6$ is $T(\lfloor{\frac{n}{2} \rfloor})+1$.
The cost of the line $7$ is $2$.
The cost of the line $8$ is $T(\lfloor{\frac{n}{2} \rfloor})+1$.
The cost of the line $10$ is $1$.
But.. how can I find now the recurrence relation, that describes the time complexity? (Worried) (Thinking)