It is the rate of growth of the running time that really interests us.
Consider only the leading term of a formula, since the lower-order terms are relatively insignificant for large n and also ignoring the leading termâ€™s constant coefficient (as constant factors are less significant than the rate of growth in determining computational efficiency for large inputs.)
One algorithm is more efficient than other if its worst-case running time has a lower order of growth.
Due to constant factors and lower order terms, error for small inputs.
Running time depends not only on an input size but also on the specifies of a particular input. (For example: Sequential Search)
The worst-case efficiency of an algorithm is its efficiency for the worst-case input of size n, which is an input of size n for which the algorithm runs the longest among all possible inputs of size.
The best-case efficiency of an algorithm is its efficiency for the best case input of size for which the algorithm runs the fastest among all possible inputs of that size.
The average-case efficiency seeks to provide the information about an algorithmâ€™s behavior on a typical or random input.
C avg (n)=[1.p/n+2.p/n+..........+i.p/n+.........+n.p/n]+n.(1-p)
= p/n[1+2+â€¦â€¦.+i+â€¦â€¦â€¦â€¦+n]+n(1-p)
=p/n (n(n+1))/2+n(1-p)
=p(n+1)/2+n(1-p)
If p=1 (successful search), the average number of key comparisons made by sequential search is (n+1)/2 i.e. the algorithm will inspect half of the listâ€™s elements.
If p=0 (unsuccessful search), the average number of key comparisons made by sequential search will be n .
Used to formalize that an algorithm has running time or storage requirements that are ``never more than,'' ``always greater than,'' or ``exactly'' some amount.
To compare and rank the order of growth of an algorithmâ€™s basic operation count.
To set up the recurrence for T(n), the worst â€“case running time for merge sort on n numbers. Merge sort on just one element takes constant time. When we have n >1 elements, we break down the running time as follows:
Divide: The divide step just computes the middle of the sub array, which takes constant time. Thus, D(n)= Î˜ (1).
Conquer: We recursively solve two problems, each of size n/2, which contributes 2T(n/2) to the running time.
Combine: Merge procedure on an n-element sub array takes time Î˜(n), so C(n)= Î˜(n).
Whose solution is claimed to be T(n)= Î˜(n lg n). The equation 1.0 can be rewritten as follows: T(n)= Where the constant c represents the time required to solve problems of size 1 as well as the time per array element of the divide and combine steps.
We continue expanding each node in the tree by breaking it into its constituent parts as determined by the recurrence, until the problem sizes get down to 1, each with a cost of c.
We add the costs across each level of the tree. The top level has total cost cn, the next level down has total cost c(n/2)+c(n/2)=cn, the level after that has the total cost cn/4+cn/4+cn/4+cn/4=cn, and so on.
In general, the level i below the top has 2i nodes, each contributing a cost of c(n/2i), so the ith level below the top has total cost 2i c(n/2i)=cn.
At the bottom level, there are n nodes, each contributing a cost of c, for a total cost of cn. (2 i =2 log 2 n = nlog 2 2=n nodes)
The longest path from the root to a leaf is n-> (1/2)n-> (1/2)2n ->------->1.
Since (1/2) k n=1 when k= log2n, the height of the tree is log2n. The total numbers of levels of the recursion tree is lg n+1.
To compute the total cost represented by the recurrence (1.1), we simply add the costs of all levels. There are lg n+1 levels, each costing cn, for a total of cn(lg n+1)=cn lg n+cn.
Ignoring the low order term and the constant c gives the desired result of Î˜(n lg n).
It doesnâ€™t require that the intermediate results of each step of execution be uniquely defined and depend only on the inputs and results of the preceding steps.
It makes random choices and these choices are made by random number generator.
When a random number generator is called, it computes a number and returns its value.
When a sequence of calls is made to a random generator, the sequence of numbers returned is random.
In practice, a pseudorandom number generator is used. It is an algorithm that produces numbers that appear random.
Be the first to comment