1,853
18
Essay, 2 pages (250 words)

Ronaldo marques

Ronaldo Marques COSC-2436-73426 15/03/2013 Project 2 5. 2-2 A) A : Array[1.. n] I: Integer // Temp variable X: integer // Random integer between 1 and ‘ n’ N: Interget // Size of array A Count: Integer // counts how many elements has been searched CheckedA: Array[1.. n] // it will keep track of index that was already checked Function int Random-Search(A, x) //Initialize variables For i := 1 to n CheckedA[i] = false N = A. Lenght // gets A length Count := 0 While (count < n) I := Random(1, n) // uses the library function to get a a random integer between 1 and n //assigns it to I If (not CheckedA[I]) // check if the record has been searched before count++ //increment count by 1 CheckedA[ I] := true // set the flag to show this record has been searched if (A[I] = x) return I // if x is found in A[I] the function returns I and terminates return -1 // if the while loop exit without retuning a value it means the value //was not found on A[1.. n], so we return -1 to show that no record was found. B) Expected number of indices into A is a geometric random variable with expectation of 1/p and p equal to 1/n to be right. So, E[X] = n. C) Just like the last problem but not with probability equal k/n E[X] = 1/p = n/k D) In order to the function exit with -1 value in case if no result was found, all the items of CheckedA array must be set to true and the count variable must be equal to the number of elements on A (n). Since I is picked randomly and it can be picked multiple times it would have to be E(X) = nlnn + O(n).

Thank's for Your Vote!
Ronaldo marques. Page 1
Ronaldo marques. Page 2

This work, titled "Ronaldo marques" was written and willingly shared by a fellow student. This sample can be utilized as a research and reference resource to aid in the writing of your own work. Any use of the work that does not include an appropriate citation is banned.

If you are the owner of this work and don’t want it to be published on AssignBuster, request its removal.

Request Removal
Cite this Essay

References

AssignBuster. (2022) 'Ronaldo marques'. 3 January.

Reference

AssignBuster. (2022, January 3). Ronaldo marques. Retrieved from https://assignbuster.com/ronaldo-marques/

References

AssignBuster. 2022. "Ronaldo marques." January 3, 2022. https://assignbuster.com/ronaldo-marques/.

1. AssignBuster. "Ronaldo marques." January 3, 2022. https://assignbuster.com/ronaldo-marques/.


Bibliography


AssignBuster. "Ronaldo marques." January 3, 2022. https://assignbuster.com/ronaldo-marques/.

Work Cited

"Ronaldo marques." AssignBuster, 3 Jan. 2022, assignbuster.com/ronaldo-marques/.

Get in Touch

Please, let us know if you have any ideas on improving Ronaldo marques, or our service. We will be happy to hear what you think: [email protected]