This repo is a small, educational playground for comparing search algorithms and talking about Big O. It includes JavaScript examples as the primary learning path, plus a readable Python version for cross-checking ideas.
- JavaScript search experiments:
search.jsbuilds sorted arrays of even numbers, runs linear search and binary search, and records timing results so you can compare behavior at different input sizes. - Python search experiments:
search.pymirrors the JavaScript logic in Python so you can read the same ideas in a second syntax. - Notebook walkthrough:
search.ipynbbreaks the code into small sections with explanations and plots so you can see time and iteration counts. - Plot helper:
plot_results.pyrenders the timing results as horizontal bar charts and labels each bar with the search index and iteration count.
- See the difference between linear search ( O(n) ) and binary search ( O(log n) ).
- Observe how input size affects runtime.
- Connect iteration counts to algorithmic complexity.
- Learn how to measure performance and visualize results.
- Open
search.js. - Run it with Node:
node search.js- Open
search.pyorsearch.ipynb. - Run the script:
python search.py- Or open the notebook and run cells in order.
- The arrays contain only even numbers. When we add 1 to a target, it becomes odd and is guaranteed to be missing. This is a simple way to test "not found" cases.
- Timing very small arrays can be noisy because overhead and scheduling can dominate the real work.
- The Python code is included for readability, not as a separate learning track.