what is the complexity of my code? is it nlogn or more?>
dnt worry its not a homework i have exam im solving questions, this comlexity things complicate me !!
this is my code:
(the question wanted to print the most numbers possiple from the array in condition the sum of these numbers is not higher than max, with O(nlogn) complexity)
for example: 6,1,-8,-12,37,38,39,15 and max=0 the output is 6,1,-8,-12.
dnt worry its not a homework i have exam im solving questions, this comlexity things complicate me !!
this is my code:
(the question wanted to print the most numbers possiple from the array in condition the sum of these numbers is not higher than max, with O(nlogn) complexity)
for example: 6,1,-8,-12,37,38,39,15 and max=0 the output is 6,1,-8,-12.
void print_max(int a[], int n, int max) /* n is the length of the array, max is any number */ { int sum=0, i=0; merge_sort(a,n); \* merge_sort comlexity is nlogn */ while(sum<=max) { sum+=a[i]; i++; printf("%d, ",a[i]); } }