Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

complexity question

$
0
0
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.

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]);
    }
    
}


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>