Task: i want to print London five time so i have multiple algorithms to do this.So i will pick best algorithm for this.First we will think about the property of best algorithm.there are multiple properties of best algorithms.
- Memory--the algorithm which take less memory
- Time--the algorithm which take minimum time during execution and writing.
1
void print()
{
for(int i=1;i<=5;i++)
cout<<"London;
}
{
for(int i=1;i<=5;i++)
cout<<"London;
}
2
void print()
{
cout<<"London;
cout<<"London;
cout<<"London;
cout<<"London;
cout<<"London;
}
Here 1 method use for loop and use print instruction only one time and print london five times.
Where in method 2 print instruction use five time to print london five time.so you can see 2 method will take more time to write and take more space in memory and also take more time to execute .
so we can say method 1 is the best case in term of Memory and Time.
No comments:
Post a Comment