We learned about big O notation, but I often see T(n) as well. For example,
public static Comparable[] mergeSort(Comparable[] A, int low, int high) {
if (low < high) { //at least 2 elements? //cost = c
int mid = (low + high)/2; //cost = d
Comparable[] A1 = mergeSort(A, low, mid); //cost = T(n/2) + e
Comparable[] A2 = mergeSort(A, mid+1, high); //cost = T(n/2) + f
return merge(A1,A2); //cost = g n + h
}
.... //cost = i
I believe c,d,e,... are meant to be arbitrarily named constants.
What does T(n/2) mean? also how is T notation related to big O?
When we say that an algorithm runs in time T(n), we mean that T(n) is an upper bound on the running time that holds for all inputs of size n. This is called worst-case analysis. The algorithm may very well take less time on some inputs of size n, but it doesn't matter.
Similar to big O notation, big Omega(Ω) function is used in computer science to describe the performance or complexity of an algorithm. If a running time is Ω(f(n)), then for large enough n, the running time is at least k⋅f(n) for some constant k. Here's how to think of a running time that is Ω(f(n)):
In essence: T(n) ∊ O(f(n)) means that T(n) doesn't grow faster than f(n).
The time complexity, measured in the number of comparisons, then becomes T(n) = n - 1. In general, an elementary operation must have two properties: There can't be any other operations that are performed more frequently as the size of the input grows.
This notation refers to the maximum amount of time (or, more specifically, steps) that a function takes to run.
T(n) may be much more specific than O(n); for example, let's say you have a program that for any input, requires n^2+n+1
steps to run:
T(n) = n^2+n+1
O(n) = n^2
More information can be found here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With