Login
Order Now
Support
Algorithms Task

Algorithms Task

  • 20th May, 2022
  • 16:52 PM

int fun(int arrival[ ],int departure[ ],int n)
{
// suppose n elements in the both array
// consider array to be 1 indexed
sort(arrival);
sort(departure);
// Sort both the array using any of the faster sort complexity O(Nlogn)
Int i=2;
Int j=1;
Int ans=1; // final answer we will return
Int cur=1; // current status of platform needed
while(i<=n && j<=n)
{
if(arrival[i] <= departure[j] )
{
cur++;
i++;
}
Else
{
cur--;
j++;
}
ans=max(ans,cur);
}
return ans;
}

//// Time complexity -: O(NlogN) N -: denotes number of element in the array
//// Space complexity -: O(1) we don't used any extra space at all just variables in our function

****************************************
Bool fun(Node root,Node par)
{
if(root==NULL)
return false;
if(par==NULL)
{
root->val=0;
fun(root->left,root);
fun(root->right,root);
Return true;
}
if(par->left==root){
root->val=2*par->val+1;
}
Else
root->val=2*par->val+2;
fun(root->left,root);
fun(root->right,root);
return true;
}
/// Time complexity just O(N) where N denotes the number of nodes in the tree
/// Space complexity O(1) as we are not using any extra space we are just doing everything
// in place

Share this post

assignment helpassignment helperassignment expertsassignment writing services