Answer 1: ~~~~~~~~~~~~~~~~~.

Added on - 22 Sep 2019

  • Dissertation

    type

  • 4

    pages

  • 1164

    words

  • 100

    views

  • 0

    downloads

Showing pages 1 to 2 of 4 pages
~~~~~~~~~~~~~~~~~~Answer 1: ~~~~~~~~~~~~~~~~~Complexity = O(n^2)Function to compute sum is (n/2)^2;Proof : 1 + 3 + 5 + 7 + 9 + 11 + 2(n-1) = n^2so : 1 + 3 + 5 + 7 + 9 + n-1 = (n/2)^2;Some Example :10 - 2515 - 49100 - 25001000 – 250000Prog :publicclassTest2 {publicstaticvoidmain(String[]args) {System.out.println(func(10000));}publicstaticintfunc(intn) {intsum= 0;n=n- (n% 2 );for(intk= 1;k<n;k+= 2)for(intj= 0;j<k; ++j)++sum;returnsum;}}~~~~~~~~~~~~~~~Answer 2: ~~~~~~~~~~~~~~~~~~~~No of comparison is same in the all the cases.It will be 2(n-1)Complexity: O(n).As Every element is getting compared 2 times except the firstelement A[0].So Complexity isO (2(n-1)) which is equivalent to O (n)~~~~~~~~~~~~~~~ Answer 3: ~~~~~~~~~~~~~~~~~~~~
It will be printed 55 Times.Make the recursion tree to understand moref(4*4*4*4*4) —1. f(4*4*4*4*2) — so on2. f(4*4*4*4*1) — so onProgram to verifypublicclassTest1 {privatestaticintcount= 0;publicstaticvoidmain(String[]args) {System.out.println("Starting....");fun(4*4*4*4*4);System.out.println(count);}privatestaticvoidfun(intn) {if(n<2) {return;}if(n==2) {count++;System.out.println("Hii");}fun(n/2);fun(n/4);}}~~~~~~~~~~~~ Answer 4 : ~~~~~~~~~~~~~~~~~~~~~~Binomail Cofficient:C(n, k) = C(n-1 , k-1) + C(n-1, k)C(n,0) = C(n,n) = 1 // Base conditionRecursive Function:intbinomialCoeff(intn,intk){// Base Cases
desklib-logo
You’re reading a preview
card-image

To View Complete Document

Become a Desklib Library Member.
Subscribe to our plans

Unlock This Document