Editing
Randomized Algorithms
(section)
Jump to navigation
Jump to search
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!
== <span style="color: #FFFFFF;">Applying</span> == '''Modeling 'The Prime Finder' (A Monte Carlo test for primality):''' <syntaxhighlight lang="python"> import random def is_probably_prime(n, trials=10): """ Miller-Rabin-style logic. Each trial reduces the 'Risk of Error'. """ if n < 2: return False if n == 2: return True for _ in range(trials): # Pick a random witness 'a' a = random.randint(2, n - 1) # If n is prime, 'a^(n-1) % n' should be 1 (Fermat's Little Theorem) if pow(a, n - 1, n) != 1: return "DEFINITELY COMPOSITE (Not Prime)" return f"PROBABLY PRIME (Risk of Error: 1 in 2^{trials})" # Checking a giant number print(is_probably_prime(104729)) # 10,000th prime </syntaxhighlight> ; Random Landmarks : '''The 'Quicksort' Algorithm''' β The most famous example of a "Randomized" success: it is $O(n^2)$ in the "Worst Case," but "Randomizing the pivot" makes it $O(n \log n)$ almost **every single time** in the real world. : '''Cryptography (RSA/ECC)''' β Without "Randomized Primality Tests," your "Banking Apps" and "Encrypted Chats" would be "Impossible" because finding "Large Primes" would take years. : '''Google PageRank''' β The algorithm that built Google: it treats a "Web Search" like a "Random Walker" surfing the web. Where the walker "Ends up" most often is the "Most important" page. : '''Load Balancing''' β How "Netflix" or "Facebook" handles millions of users: they "Randomly assign" you to a server. This is "Simplest and Best" way to ensure no single server "Explodes." </div> <div style="background-color: #8B4500; color: #FFFFFF; padding: 20px; border-radius: 8px; margin-bottom: 15px;">
Summary:
Please note that all contributions to BloomWiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
BloomWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information