Initialise all elements of ar_low with 0
for (int i=0; i<n-1; i++) {
for (int j=i+1; j<n-1; j++) {
if (ar[j] <= ar[i])
ar_low[i]++ ;
}
}
O(n^2)
For O(nlogn), create a BST - O(nlogn)
Traverse the tree, counting children on the left side of each node and
putting it ar_low - O(n)
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.