Editing
Algorithms and Complexity
(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> == '''Comparing Linear Search vs. Binary Search:''' <syntaxhighlight lang="python"> def linear_search(arr, target): """O(n) complexity: checks every item.""" steps = 0 for item in arr: steps += 1 if item == target: return steps return steps def binary_search(arr, target): """O(log n) complexity: halves the search space each step.""" low = 0 high = len(arr) - 1 steps = 0 while low <= high: steps += 1 mid = (low + high) // 2 if arr[mid] == target: return steps elif arr[mid] < target: low = mid + 1 else: high = mid - 1 return steps # Test with 1 million items data = list(range(1000000)) target = 999999 print(f"Linear Search steps: {linear_search(data, target)}") # ~1,000,000 print(f"Binary Search steps: {binary_search(data, target)}") # ~20 # Binary search finds 1 item in a million in just 20 guesses! </syntaxhighlight> ; Real-World Algorithms : '''Google Search''' β PageRank (an algorithm for ranking web pages). : '''GPS/Google Maps''' β Dijkstra's Algorithm (finding the shortest path). : '''Cryptography''' β RSA (based on the complexity of factoring large prime numbers). : '''Compression''' β Huffman Coding (making files smaller without losing info). </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