Skip to main content
deleted 238 characters in body
Source Link
teddcp
  • 159
  • 5

With the help of Steven, i am posting the solution.

def divide(dd,dr):
    '''
            let dd and dr be the dividend and divisor
            x be the current macium divisor, less that dividend
            c be the counter
            q is the qutotient
    '''
    x=dr
    c=0
 
    #find the maxium number of time we need to iterate over dividend
    #by increasing divisor exponentially
    # i.e Determine how far left to shift the divisor.
    
    #it will run lgx time  ----------Loop1
    while (x<<c) <= dd:
            c+=1
            print(c)
    q=0

    #then subtract from dividend and update result as usual manner
    
    #will run c time i.e lgx time  -----------Loop2
    for j in range(c-1,-1,-1):
            if x<<j <= drdd :
                    dr=drdd- =(x<<j)
                    q+=1<<j
                     

    print(q,dd)

    '''
    total time complexity will be 2lgx i.e lgx
    '''

** Just Little bit doubt in the time complexity of loop1 and loop2.**

But this solution works.

With the help of Steven, i am posting the solution.

def divide(dd,dr):
    '''
            let dd and dr be the dividend and divisor
            x be the current macium divisor, less that dividend
            c be the counter
            q is the qutotient
    '''
    x=dr
    c=0
 
    #find the maxium number of time we need to iterate over dividend
    #by increasing divisor exponentially
    # i.e Determine how far left to shift the divisor.
    
    #it will run lgx time  ----------Loop1
    while (x<<c) <= dd:
            c+=1
            
    q=0

    #then subtract from dividend and update result as usual manner
    
    #will run c time i.e lgx time  -----------Loop2
    for j in range(c-1,-1,-1):
            if x<<j <= dr:
                    dr=dr- x<<j
                    q+=1<<j
            
    print(q,dd)

    '''
    total time complexity will be 2lgx i.e lgx
    '''

** Just Little bit doubt in the time complexity of loop1 and loop2.**

But this solution works.

With the help of Steven, i am posting the solution.

def divide(dd,dr):
    '''
            let dd and dr be the dividend and divisor
            x be the current macium divisor, less that dividend
            c be the counter
            q is the qutotient
    '''
    x=dr
    c=0
    while (x<<c) <= dd:
            c+=1
    print(c)
    q=0

    #then subtract from dividend and update result as usual manner

    #will run c time i.e lgx time  -----------Loop2
    for j in range(c-1,-1,-1):
            if x<<j <= dd :
                    dd-=(x<<j)
                    q+=1<<j
                     

    print(q,dd)

    '''
    total time complexity will be 2lgx i.e lgx
    '''

** Just Little bit doubt in the time complexity of loop1 and loop2.**

But this solution works.

edited body
Source Link
teddcp
  • 159
  • 5

With the help of Steven, i am posting the solution.

def divide(dd,dr):
    '''
            let dd and dr be the dividend and divisor
            x be the current macium divisor, less that dividend
            c be the counter
            q is the qutotient
    '''
    x=dr
    c=0

    #find the maxium number of time we need to iterate over dividend
    #by increasing divisor exponentially
    # i.e Determine how far left to shift the divisor.
    
    #it will run lgx time  ----------Loop1
    while (x<<c) <= drdd:
            c+=1
            
    q=0

    #then subtract from dividend and update result as usual manner
    
    #will run c time i.e lgx time  -----------Loop2
    for j in range(c-1,-1,-1):
            if x<<j <= dr:
                    dr=dr- x<<j
                    q+=1<<j
            
    print(q,dd)

    '''
    total time complexity will be 2lgx i.e lgx
    '''

** Just Little bit doubt in the time complexity of loop1 and loop2.**

But this solution works.

With the help of Steven, i am posting the solution.

def divide(dd,dr):
    '''
            let dd and dr be the dividend and divisor
            x be the current macium divisor, less that dividend
            c be the counter
            q is the qutotient
    '''
    x=dr
    c=0

    #find the maxium number of time we need to iterate over dividend
    #by increasing divisor exponentially
    # i.e Determine how far left to shift the divisor.
    
    #it will run lgx time  ----------Loop1
    while (x<<c) <= dr:
            c+=1
            
    q=0

    #then subtract from dividend and update result as usual manner
    
    #will run c time i.e lgx time  -----------Loop2
    for j in range(c-1,-1,-1):
            if x<<j <= dr:
                    dr=dr- x<<j
                    q+=1<<j
            
    print(q,dd)

    '''
    total time complexity will be 2lgx i.e lgx
    '''

** Just Little bit doubt in the time complexity of loop1 and loop2.**

But this solution works.

With the help of Steven, i am posting the solution.

def divide(dd,dr):
    '''
            let dd and dr be the dividend and divisor
            x be the current macium divisor, less that dividend
            c be the counter
            q is the qutotient
    '''
    x=dr
    c=0

    #find the maxium number of time we need to iterate over dividend
    #by increasing divisor exponentially
    # i.e Determine how far left to shift the divisor.
    
    #it will run lgx time  ----------Loop1
    while (x<<c) <= dd:
            c+=1
            
    q=0

    #then subtract from dividend and update result as usual manner
    
    #will run c time i.e lgx time  -----------Loop2
    for j in range(c-1,-1,-1):
            if x<<j <= dr:
                    dr=dr- x<<j
                    q+=1<<j
            
    print(q,dd)

    '''
    total time complexity will be 2lgx i.e lgx
    '''

** Just Little bit doubt in the time complexity of loop1 and loop2.**

But this solution works.

deleted 7 characters in body
Source Link
teddcp
  • 159
  • 5

With the help of Steven, i am posting the solution.

def divide(dd,dr):
    '''
            let dd and dr be the dividend and divisor
            x be the current macium divisor, less that dividend
            c be the counter
            b be the exponential rate(2^i)
            q is the qutotient
    '''
    x=dr
    c=0
    b=1

    #find the maxium number of time we need to iterate over dividend
    #by increasing divisor exponentially
 
    #it# willi.e runDetermine lgxhow time
far left to shift whilethe dd>=x:divisor.
            c+=1
      #it will run lgx time  b=b<<1----------Loop1
         while (x<<c) <= x*=2
dr:
            if x*2>dd:c+=1
                 
    breakq=0
    
    #then subtract from dividend and 
 update result as usual print(x,b,c)
manner
    q=0

    #will run c time i.e lgx time  -----------Loop2
    for ij in range(c-1,-1,-1):
            if dd>=xx<<j <= dr:
                    dddr=dr-=x
                    q+=bx<<j
            x//=2
            b//=2q+=1<<j
            
    print(q,dd)

    '''
    total time complexity will be 2lgx i.e lgx
    '''

** Just Little bit doubt in the time complexity of loop1 and loop2. But this solution works.**

But this solution works.

With the help of Steven, i am posting the solution.

def divide(dd,dr):
    '''
            let dd and dr be the dividend and divisor
            x be the current macium divisor, less that dividend
            c be the counter
            b be the exponential rate(2^i)
            q is the qutotient
    '''
    x=dr
    c=0
    b=1

    #find the maxium number of time we need to iterate over dividend
    #by increasing divisor exponentially
 
    #it will run lgx time
    while dd>=x:
            c+=1
            b=b<<1
            x*=2

            if x*2>dd:
                    break
            
     print(x,b,c)

    q=0

    #will run c time i.e lgx time
    for i in range(c,-1,-1):
            if dd>=x:
                    dd-=x
                    q+=b
            x//=2
            b//=2
            
    print(q,dd)

    '''
    total time complexity will be 2lgx i.e lgx
    '''

Just Little bit doubt in the time complexity. But this solution works.

With the help of Steven, i am posting the solution.

def divide(dd,dr):
    '''
            let dd and dr be the dividend and divisor
            x be the current macium divisor, less that dividend
            c be the counter
            q is the qutotient
    '''
    x=dr
    c=0

    #find the maxium number of time we need to iterate over dividend
    #by increasing divisor exponentially
    # i.e Determine how far left to shift the divisor.
    
    #it will run lgx time  ----------Loop1
    while (x<<c) <= dr:
            c+=1
             
    q=0
 
    #then subtract from dividend and update result as usual manner
    
    #will run c time i.e lgx time  -----------Loop2
    for j in range(c-1,-1,-1):
            if x<<j <= dr:
                    dr=dr- x<<j
                    q+=1<<j
            
    print(q,dd)

    '''
    total time complexity will be 2lgx i.e lgx
    '''

** Just Little bit doubt in the time complexity of loop1 and loop2.**

But this solution works.

Source Link
teddcp
  • 159
  • 5
Loading