14

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?

James
  • 706
  • 3
  • 8
  • 16
  • 1
    From wikipedia article on O-notation: "A function T(n) that will express how long the algorithm will take to run (in some arbitrary measurement of time) in terms of the number of elements in the input set." – James Nov 29 '12 at 03:15
  • 2
    `T(n)`, denoting the *exact* time needed to calculate the data of size `n`. It's very useful when calculate the time needed of a recursive function. – xiaoyi Nov 29 '12 at 03:27

2 Answers2

15

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.

username tbd
  • 9,152
  • 1
  • 20
  • 35
0

I've personally never seen this notation before, but I suspect it refers to "big-Theta" (Θ), which is both an asymptotic upper-bound (big-O) and an asymptotic lower bound.

Also related: Big-Omega (Ω) is used to denote just an asymptotic lower-bound (mirroring big-O).

Cameron
  • 96,106
  • 25
  • 196
  • 225