Random numbers recursion worst case

Viewed 16
int reqNum = 4;

fun(){
    int randNum = randomNumber(1,8); // Generates a random number from 1 to 8
     
    if (randNum == reqNum){
        return;
    }
    else{
        fun();
    }
}

what's the worst case of this?

it's gonna keep calling itself over and over till the random number is equal to the reqNum.

1 Answers

Worst case is O(infinity) usual case is O(m) where m is the size of the range of random numbers

Related