Time and Space complexity

  • to store program instructions.
  • to store constant values.
  • to store variable values.
  • And a few other things like function calls, jumping statements, etc.
int fact=1;              //fact=4 byte
for(int i=1;i<=n;++i) //n=4 byte
{
fact *=i; //i=4 byte
}
return fact; //aux space =4 byte
//space=16 byte
int count = 0;
for (int i = 0; i < N; i++)
for (int j = 0; j < i; j++)
count++;
  1. find out the growing variable.
  2. eliminate the constant terms.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store