Earlier I showed how to do depth-first search in C# and breadth-first search in C#. In this article I want to show depth-first search in Python, using both a recursive and non-recursive solution, because I want to show an example of topological sorting of a directed acyclic graph and the algorithm is based on depth-first search. I am also actively learning Python and it is best that I write Python code daily as much as possible.Read More
A look at breadth-first search in C# for traversing graphs. Breadth-first search is very similar to depth-first search, except that it internally uses a Queue instead of a Stack when traversing the graph. In the case of an unweighted graph, breadth-first search can also find the shortest path between two vertices in a graph.Read More
Program and use the depth-first search algorithm in C# and .NET Core to find all the vertices that can be reached in an undirected graph given a starting vertex. Depth-first search helps answer the question of connectivity, and is useful for mapping physical networks, web pages, social networks, etc. There are recursive and iterative versions of depth-first search, and this article will show the iterative version that requires an extra Stack Data Structure to maintain vertices visited.Read More
I built my first decorator in Python to provide caching on Python functions that can support memoization, like the well-known recursive Fibonacci algorithm. Turns out a decorator, called lru_cache, already exists in functools that does memoization. This article shows how to create a custom Python decorator for caching as well as use the lru_cache decorator in functools to speed up the recursive Fibonacci algorithm.Read More
This weekend I completed the data structures portion of the Cracking the Coding Interview Questions on HackerRank. One of the programming challenges, validating a binary search tree, taught me how to verify a binary search tree is valid and I wanted to share my solution using Python.Read More
I have been learning about Binary Heaps in my data structures class, and have been coding several examples in both Python and C#. In this article I want to introduce
heapq in the Python collections module, which provide min Binary Heap functionality. I also provide an example of how to write a custom min Binary Heap in Python to perform Heapsort!
Implementing a Queue Data Structure in Python and C#. In Python, I will describe how to use
deque in the collections module as well as how to develop your own custom Queue using a Link List. In C#, I describe how to implement a Queue using an Array as well as using the
Queue<T> Classes in System.Collections and System.Collections.Generic. I will also discuss abstraction in computer science to help hide the implementation details.
Using memoization in the naieve, recursive algorithm for solving Fibonacci numbers makes a huge performance impact by reducing the number of recursive calls to re-solve Fibonacci numbers already calculated. In this case I will be using a Python dictionary and local functions ( nested functions ) to improve the recursive, naieve algorithm.Read More
This article first shows how to use the
List Type in Python as a Stack data structure. It then provides an example of a custom
Stack Class built in Python that still leverages the
List Type in Python but uses abstraction to hide the underlying storage and its non-Stack methods. The article also shows how to use the
deque in Python,
Stack<T> in C# from
System.Collections.Generic, and how to code the Stack data structure using a link list!
In a recent programming challenge I was asked to code an inorder traversal of a binary search tree to print the values of its keys in the correct order. An order traversal of a binary search tree will print the keys of the node's left sub-tree, followed by the node's key, followed by the keys of the node's right sub-tree. I also show how to create a binary search tree in Python using level order traversal (like breadth-first search) and a list of ordered keys.Read More
The Quickselect Algorithm is a selection algorithm based on the Quicksort sorting algorithm that provides a best case runtime of O(n) when finding the k-th smallest item in an unordered list. Quickselect achieves a better best case runtime compared to Quicksort, because it only has to recursively partition one side of the current partition. Here is an example of the Quickselect Algorithm using Python.Read More
Most articles talk about setting the host environment in ASP.NET Core using Environment Variables, but I wanted to set the host environment in an ASP.NET Core web application using command line arguments. This is actually really easy to do.Read More
Learn how to store and retrieve user secrets in ASP.NET Core MVC Web Applications. This article discusses using the Secret Manager tool to add user secrets for your web application and retrieve them using ASP.NET Core Configuration. This is perfect for storing usernames and passwords for twitter, facebook, github, etc. per user outside of the project directory so they don't get pushed to your source code repository and shared with others.Read More
Today, in one of my algorithms design and analysis classes I learned about Quicksort. Much like Merge Sort, Quicksort is a divide and conquer sorting algorithm that sorts the items in O(nlogn). In this article I will be writing a Quicksort function in Python.Read More
I mentioned learning about generating Fibonacci numbers using Python in my computer science and algorithm courses using recursive functions and Dynamic Programming. I wrote an article about the differences: Fibonacci Numbers - Tale of Two Algorithms using Python. In this article I show a Fibonacci Number Generator using Python generators. I also talk more about Python generators as well as mention the differences between
xrange in Python 2.7.
I walk you through developing an ASP.NET Core MVC Web Application with Entity Framework Core and SQLite using EF Core Migrations on macOS using Visual Studio Code. The application also shows how to use ASP.NET Core Dependency Injection to inject a custom DbContext into a service responsible for fetching data from SQLite.Read More
Making change is another classic example of Dynamic Programming I learned in my algorithms classes. In this example, I use Python to make change for a certain dollar amount given a list of dollars in U.S. currency. The goal is to make change using the least number of bills. Dynamic Programming is a great solution for this, since the problem involves overlapping sub-problems.Read More
Using Dynamic Programming in Python to solve the Knapsack Problem in Clash of Clans. The goal is to find the best troop composition to hide the maximum amount of elixir and dark elixir in my barracks!Read More
Use EF Core Migrations to create the initial migration for the SQLite Database used in the Getting Started with Entity Framework Core and SQLite Tutorial. This example introduces two new dependencies: Microsoft.EntityFrameworkCore.Tools and Microsoft.EntityFrameworkCore.Design, as well as the dotnet ef migrations add and dotnet ef database update commands.Read More
A solution to insertion sort using Python that I wrote with Pythonista on my iPad Pro. I have also included several Doctests to verify it is sorting a list of integers correctly using insertion sort. If you are attending computer science and algorithms courses like myself, I hope you find the code useful!Read More
My computer science assignment was to develop a class in Python that encrypts and decrypts messages using the Caesar Cipher. I chose this solution, because it was the most creative by using Python string constants, the zip function to create a tuple from 2 iterable lists, dictionaries for constant lookup, and list comprehensions for doing the actual encryption and decryption.Read More