Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Las Vegas algorithm
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Example == <syntaxhighlight lang="java" line="1"> // Las Vegas algorithm, assuming A is array of length n. n = A.length repeat: k = RandInt(n) if A[k] == 1, return k; </syntaxhighlight> As mentioned above, Las Vegas algorithms always return correct results. The code above illustrates this property. A variable ''k'' is generated randomly; after ''k'' is generated, ''k'' is used to index the array ''A''. If this index contains the value 1, then ''k'' is returned; otherwise, the algorithm repeats this process until it finds 1. Although this Las Vegas algorithm is guaranteed to find the correct answer, it does not have a fixed runtime; due to the randomization (in ''line 3'' of the above code), it is possible for arbitrarily much time to elapse before the algorithm terminates.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)