CS502 - Fundamentals of Algorithm Solution Assignment No 1 Spring 2021

Question No 1:
Suppose that one of the largest commercial bank branch in UAE has recently experienced a significant distress due to covid 19.  A huge No. of account holders withdraws the payment from the bank. Now manager want to check the total number of accounts those have less than 1000$.
 
You are required perform the following task:
  1. Write only Pseudocode to check the total number of accounts, who have less than 1000$ using array list.
  1. After writing Pseudocode calculate the worst-case time complexity T(n).
Question No 2:
A prime number is a number that can only be divided by itself and 1. Using the following code, we can check whether the number is prime or not. Your task is to find the time complexity of the following code with respect to worst case.
 
int arr[5], j, x , y, z;
for(x=0; x<5; x++)
  {
            cout<<"Enter the no."<<endl;                                                        
            cin>>arr[x];
   }
for(x=0;x<5;x++)
            {
                        y=0;
                        for(j=2; j<arr[x];j++)
                          {
                                    z=arr[x]%j;
                                    if(z==0)
                                      {
                                        y=1;
                                        break;
                                        }
                            }
                    if(y==0)
                        cout<<arr[x]<<endl;
            }
}


pointing hand for click

Click Below To Download Solution File


Download



Recent Uploads:


Post a Comment

Previous Post Next Post