Monday 19 April 2021

Branchless programming

Recently came across this wonderful video about branchless programming. It is an interesting concept which, in probability, not required when building applications that are super sensitive about resources usage or the performance. Irrespective of that, it is good to know that there are simple mathematical techniques (which i guess have been around for quite a long time) which allow us to write code that can faster than what we imagine. There is a lot of content available if you search the topic "branchless programming" on your favorite search engine - however, i found this video to be quite detailed and informative.

Sunday 11 April 2021

Course Schedule (LeetCode problem): C#, Python

Continuing our journey of understanding different languages, we will focus on another LeetCode problem - course schedule

Essentially the problem talks about n courses which have their prerequisites defined in a set of pairs and we need to find out if it is possible to take all courses in single semester. In other words, it is not possible to cover all courses if there is at least one circular dependency amongst the courses.

Few key points:

1. The dependency amongst the courses can be visualized as a directed graph where an edge defines a dependency path from course A to course B.

2. Topological sorting is a standard way of finding cycles in a graph.

A topological ordering is possible if and only if the graph has no directed cycles, that is, if it is a directed acyclic graph (DAG).

Let us look at the code.

C# (implementing using BFS)

public bool CanFinish(int n, int[][] p) {

       

    }