Algorithms, Blockchain and Cloud

Teaching Kids Programming – Binary Search Algorithm and Exponential Formula (MATH) to Solve Equation x^x=2^2048


Teaching Kids Programming: Videos on Data Structures and Algorithms

Given x is a positive integer, find such that

Math Exponential Formula

The exponential formula:
Thus:



Thus:

Bruteforce – Linear Search Algorithm

The upperbound of x can be set to 2048 because is greater than .

T = 2**2048
for x in range(1, 2048+1):
    if x**x == T:
        print(x)

Binary Search Algorithm to Find Root to Equation

We can binary search:

def f():
    L = 1
    R = 2048
    T = 2**2048
    while L <= R:
        m = L + R >> 1
        mm = m**m
        if mm == T:
            return m
        if mm > T:
            R = m - 1
        else:
            L = m + 1
    return -1  # solution not found

–EOF (The Ultimate Computing & Technology Blog) —

503 words
Last Post: Teaching Kids Programming - Maximum Absolute Value of Sublist via Kadane's Algorithm
Next Post: Teaching Kids Programming - Top K Frequent Elements (Heap and Counter)

The Permanent URL is: Teaching Kids Programming – Binary Search Algorithm and Exponential Formula (MATH) to Solve Equation x^x=2^2048 (AMP Version)

Exit mobile version