Iterative vs. Recursive Binary Search Algorithms in Python

In this article, you鈥檒l learn about a basic algorithm, every computer scientist must know: the binary search algorithm. I have drawn the code from my NoStarch programming introductory book Python One-Liners: Applications Binary Search The algorithm has important practical applications in many basic data structures such as sets, trees, dictionaries, bags, bag trees, bag dictionaries, … Read more

The Shortest Quicksort Algorithm in Python

Quicksort is not only a popular question in many code interviews 鈥 asked by Google, Facebook, and Amazon 鈥 but also a practical sorting algorithm that is fast, concise, and readable. Because of its beauty, you won鈥檛 find many introductions to algorithms that don鈥檛 discuss the Quicksort algorithm. In this one-liner tutorial, you鈥檒l learn about … Read more

Python Dijkstra Algorithm

You can download the PDF file of the presentation here. Also, watch the presentation as a Gif here: What is Dijkstra’s Algorithm? Dijkstra’s algorithm solves the single-source shortest path (SSSP) problem. Generally, it enables finding the shortest route between two vertices in a graph. Its author is dr. Edsger W. Dijkstra, a pioneering contributor to … Read more

The Sieve of Eratosthenes in Python

Finding prime numbers is of critical importance for practical applications such as cryptography. Many public-key methods are only safe from a cryptographic point of view because it鈥檚 generally inefficient and slow to compute the prime factors of large numbers. As you go over the article, feel free to watch my explainer video on the Sieve … Read more

Python Palindromes One-Liner

This one-liner introduces another basic computer science term: palindromes. Similar to anagrams, palindromes are a popular coding interview question. First things first: What is a Palindrome? 鈥淎 palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward, such as madam or racecar or the number 10201.鈥 [source] … Read more

Iterative Deepening Depth-First Search (DFS) Algorithm in Python

What is an Iterative Deepening Depth-First Search Algorithm? Continuing our story even further, after introducing graphs and basic graph traversal algorithms, we will refine the Depth-First Search Algorithm by introducing the iterative depth limitation. An iterative deepening depth-search algorithm also traverses a graph by exploring it vertex-by-vertex, but it does it by following the vertical … Read more