AmitKumarDas / fun-with-programming

ABC - Always Be Coding
2 stars 2 forks source link

[book] algorithmic thinking #15

Closed AmitKumarDas closed 2 years ago

AmitKumarDas commented 3 years ago
// refer
//
// - buy the book
// - http://www.danielzingaro.com/alg/
// Local variables are stored on stack
// On each func call some stack memory is used
// 
// static variables changes the storage duration from 
// automatic to static
// 
// Variable maintains its value between function calls
// They are stored on their own separate segment of memory
for i:=0; i<n; i++ {
  for j:=i+1; j<n; j++ {
    // ...
  }
}
// above has n(n-1) comparisons
// however above has duplicate comparisons
// e.g. 1,2 and 2,1
// hence n(n-1)/2 comparisons
// i.e. O(n^2) time or quadratic time or exponential time