Question

Below is a pseudocode for a function that finds the integer 5 in the 3 element integer array. The...

Below is a pseudocode for a function that finds the integer 5 in the 3 element

integer array. The number 5 is in the array, but it is not known where it is. The Find5 function

returns it’s seat number.

Find5 (A[1..3])
found = false
while( not found )
i = random(1, 3)
if A[i] == 5 then
found = true
return i

The function random (i, j) returns the integer of the closed range [i..j] with equal probability for each

number. Note that both i and j can occur.

a) What is the likelihood that the while-loop performs only once?

b) What is the probability that the function will use more than k iterations in the while loop?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I have used the simple tree based approach to find both the probabilities.

Function random can return 754ヶ-Yo 3

cThe Prabability o the while Leap in am bl Here he asks forthe war s are 4 total cases there will he g iter ations add 8 time

for any query leave a comment here ill get back to you as soon as possible :)

PLEASE DO NOT FORGET TO LEAVE A THUMBS UP! THANKS! :)

Add a comment
Know the answer?
Add Answer to:
Below is a pseudocode for a function that finds the integer 5 in the 3 element integer array. The...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Part I Short Answer (50 points) 1. Write a pseudocode declaration for a String array initialized...

    Part I Short Answer (50 points) 1. Write a pseudocode declaration for a String array initialized with the following strings: “Einstein”, “Newton”, “Copernicus”, and “Kepler”. 2. Assume names in an Integer array with 20 elements. Write a pseudocode algorithm a For Loop that displays each element of the array. 3. Assume the arrays numberArray1 and numberArray2 each have 100 elements. Write a pseudocode algorithm that copies the values in numberArray1 to numberArray2 . 4. Write a pseudocode algorithm for a...

  • URGENT Question 3 25 pts ArrayMystery: Input: n: a positive integer Pseudocode: Let output be an...

    URGENT Question 3 25 pts ArrayMystery: Input: n: a positive integer Pseudocode: Let output be an empty array For i = 1 to n j = 1 While ij <= n Addj to the end of output j - j + 1 Return output Answer the following questions about the ArrayMystery algorithm above. a) How many times will the inner while loop iterate? You should express your answer in terms of i and n, using Big-Oh notation. Briefly justify your...

  • C++ 3. Random modification of all elements in an integer array. a) Initialize an integer array...

    C++ 3. Random modification of all elements in an integer array. a) Initialize an integer array of capacity 5. b) Implement an array output function. c) Output the array to console. d) Implement an offset function that accepts an integer array as input and randomly modifies each element by +/- 5. e) Use the offset function to update the array. f) Output the modified array. Example Output (input in bold) Original: 5 1 4 9 2 Offset: 7 -2 6...

  • (Find the smallest element) use pointers to write a function that finds the smallest element in...

    (Find the smallest element) use pointers to write a function that finds the smallest element in an array of integers. Use {1,2,4,5,10,100,2,-22} to test the function. using the following header. int minindex(double* list, int size) example output: array size: 8 number 1: 1 number 2: 2 number 3: 4 number 4: 5 number 5: 10 number 6: 100 number 7: 2 number 8: -22 smallest element is: -22 C++ only.

  • Write a program that dynamically allocates an integer array of size of 20 to hold a...

    Write a program that dynamically allocates an integer array of size of 20 to hold a user-defined number of test scores. Once all the scores are entered, the array should be passed to • a function that calculates the average score, the minimal score, and the maximal score in the array, and returns these scores to the main function (hint: use pass by reference, I gave an example in the class) • a function that searches a specific number. The...

  • Given an array of integer, please complete a function multiply(). The function accepts the first memory...

    Given an array of integer, please complete a function multiply(). The function accepts the first memory address of an array and the size of an array as parameters and returns the multiplication of all the elements. In order to get a full score, the function must use a loop to iterate through each element of an array. Pseudo code example:   multiply([ 1, 2, 3], 3) → 6   multiply([1, 1, 4 ,2], 4) → 8   multiply([7, 0, 0, 7, 0, 7],...

  • Use C: 3. In function main, declare a two-dimensional integer array with 5 rows and 4...

    Use C: 3. In function main, declare a two-dimensional integer array with 5 rows and 4 columns. Call the following functions from function main. Call a function createArray to seed the random number generator and to fill the two-dimensional array with random integers between -20 and +20. Parameters for this function should be the array and the number of rows and columns). Call a function signs to count the number of positive values, number of negative values and number of...

  • (+30) Provide a python program which will Populate an array(list) of size 25 with integers in...

    (+30) Provide a python program which will Populate an array(list) of size 25 with integers in the range -100 (negative 100)   to +100 inclusive Display the array and its length (use the len function) Display the average of all the integers in the array Display the number of even integers (how many) Display the number of odd integers (how many) Display the number of integers > 0   (how many) Display the number of integers < 0   (how many) Display the...

  • Java question Q1) Use the following code snippet which generates a random sized array with random...

    Java question Q1) Use the following code snippet which generates a random sized array with random contents to complete the following problems: public int [] createRandomArray() {         int size = (int) (Math.random() * 10) + 1;         int[] array = new int [size];         for (int i = 0; i < array.length; i++) {             array[i] = (int) (Math.random() * 10 ) + 1;         }         return array;     } Assignment...

  • . In the method main, prompt the user for a non-negative integer and store it in...

    . In the method main, prompt the user for a non-negative integer and store it in an int variable num (Data validation is not required for the lab). Create an int array whose size equals num+10. Initialize the array with random integers between 0 and 50 (including 0 and excluding 50). Hint: See Topic 4 Decision Structures and File IO slides page 42 for how to generate a random integer between 0 (inclusive) and bound (exclusive) by using bound in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT