Algorithms

They Use These 15+ Python Interview Questions To Fail You … (And What You Can Do About It)

Fear Your Coding Interview? This article shows you how to make your coding interview a success. General Tips to Prepare Your Interview Watch Google Interview tips. Read Prof. Philip Guo’s tips. Practice coding in Google Docs. Don’t use a code highlighting editor for your training time. Solve at least 50+ code puzzles. And most importantly: …

They Use These 15+ Python Interview Questions To Fail You … (And What You Can Do About It) Read More »

How to Create a Sequence of Evenly Spaced Values [Vanilla Python & Numpy Linspace]

Problem: How to create a sequence of evenly-spaced values Using pure, vanilla Python, and Using NumPy’s linspace() method. Example: Given three arguments: start=10, stop=20, number_of_values=11. How do you create a sequence of 11 values x0, x1, …, x10 where two subsequent values xi and x(i-1) have the same distance for all i in {0, …, …

How to Create a Sequence of Evenly Spaced Values [Vanilla Python & Numpy Linspace] Read More »

How to Create a Sequence of Linearly Increasing Values with Numpy Arange?

Problem: How to create a sequence of linearly increasing values? Solution: Use NumPy’s arange() function. The np.arange([start,] stop[, step]) function creates a new NumPy array with evenly-spaced integers between start (inclusive) and stop (exclusive). The step size defines the difference between subsequent values. For example, np.arange(1, 6, 2) creates the NumPy array [1, 3, 5]. …

How to Create a Sequence of Linearly Increasing Values with Numpy Arange? Read More »

Proportional Sampling Using Weighted Values

Probability and Statistics play a very important role in the field of data science and machine learning. In this blog post you will learn the concept of proportional sampling and how can we implement it from scratch without using any library Proportional Sampling Let us take an example of tossing a die to better understand …

Proportional Sampling Using Weighted Values Read More »

How to Find the Maximum Value in a Python Dict?

There are three problem variants of finding the maximum value in a Python dictionary: Find the maximum value and return this maximum value Find the maximum value and return a (key, value) tuple of both the key and the max value itself Find the maximum value and return only the key assigned to the max …

How to Find the Maximum Value in a Python Dict? Read More »

How to Sort a Dictionary in Python By Key?

To sort a dictionary by key in Python, use the dictionary comprehension expression {key:dict[key] for key in sorted(dict)} to create a new dictionary with keys in sorted order. You iterate over all keys in sorted order, obtain their associated values with rank[key], and put them into a new dictionary. Python dictionaries preserve the order—even if …

How to Sort a Dictionary in Python By Key? Read More »

The Pathfinder Graph Algorithm in Python

Knowing the basics is what sets apart the great from the intermediate coders. In other words, a simple and effective way to grow your skills is to learn the basics of computer science. Python Pathfinder Algorithm In this tutorial, you’ll learn about the pathfinder algorithm that recursively determines whether there’s a direct or indirect path …

The Pathfinder Graph Algorithm in Python Read More »

The Quicksort Algorithm in Python

For a coder, understanding the Quicksort algorithm is like knowing the secret of 42—either you get it, or you don’t belong to the club. If you don’t know either, let’s work on the first one! The Quicksort Algorithm — A Python Implementation The algorithm is a variant of the popular Quicksort algorithm. The function qsort …

The Quicksort Algorithm in Python Read More »

The Maximum Profit Algorithm in Python

This article presents an algorithmic problem with practical value for stock market analysis. For instance, suppose you are trading the cryptocurrency Ethereum. How much profit in dollars can you make by buying low and selling high based on historical data? Maximum Profit Basic Algorithm The max profit algorithm calculates the maximum profit you’d obtain by …

The Maximum Profit Algorithm in Python Read More »