sudhakar810nit
BAN USER- 0of 0 votes
Answerswrite a program that prints numbers 1 to 100
- sudhakar810nit in United States
with most efficient condition
1. Run Time Complexity
2. Run time Space complexity
3. Compilation Time
4. Compile Time Space Complexity
5. Power complexity (reduction of battery used)| Report Duplicate | Flag | PURGE
Search Media C
{
char i=-9;
while((i+=10)<100 && printf("%d%d%d%d%d%d%d%d%d%d",i,i+1,i+2,i+3,i+4,i+5,i+6,i+7,i+8,i+9));
}
it will reduce the time complexity by 10 times.
yes bt increase space complexity by 10 times.
bt over all 10+10+1 =21
rather dn 100+1+1=102
#include<conio.h>
struct
{
unsigned i:7;
}a;
void main()
{
clrscr();
while(++a.i!=100 && printf("%d",a.i));
getch();
}
EXPLANATION
look here-
1) BIT FIELD CONCEPT
i prefer bit field concept because we need only print 1-100 and it need only 7 bit so it save memory(space)
2)rather than using post increment i prefer pre increment becausethe implementation of post-increment (a++) must create a temporary storage for housing the original value of a, increment/store a, and return the original temporary value. In contrast, pre-increment (++a) only has to increment/store the value and return it – no temporary required.
IT ALSO MINIMIZE SAPCE (as compare to post increment)
3)the time complexity is O(n) and space complexity is just O(1) because here i used only one variable
4) but i am little bit confuse at comparison portion
in my opinion (!=) faster than < or > operator so thts the reson why i use !=.
plz explain also what is the complexities............
space and time complexity
vinil it will take 100+1+1 that is space complexity is 102
- sudhakar810nit February 03, 2014and what about time and power complexity(means cpu utilization)