O(V+E) Complexity in DFS and BFS of a Graph

The Time Complexity for DFS and BFS is O(V+E). We all know that. But what does V+E is actually mean ? Ever noticed Dijkstra also has this V+E in its time complexity = O((V+E)logV). Ever wondered why ? Understanding DFS and BFS Depth First Search and Breadth First Search are two graph traversal algorithms. While DFS explores the graph recursively, BFS explores the graph level by level. Let’s see the two algorithms:...

October 22, 2022 · 5 min · Ashish Gaur

Dijkstra - Single Source Shortest Path

Dijkstra is a Greedy algorithm to find the shortest path in a graph from a single source. Let’s take a weighted a graph as below: We’ll take 0 as the source. Shortest path from source 0 to node 4 will go through node 1 and node 3: Similarly we’ve to find the shortest path from the source 0 to every node. How does Dijkstra finds this ? Understanding Dijkstra Dijkstra like any other Greedy algorithm finds the next most optimum path at each step....

October 15, 2022 · 5 min · Ashish Gaur

CAP Theorem

When designing distributed systems it’s important to know CAP(Consistency, Availability and Partition Tolerance) theorem in order to understand trade offs in designing different distributed systems. CAP Theorem states that in a distributed system, one can choose two out of three - Consistency, Availability and Partition Tolerance. What does these three terms mean: Consistency - means a client sees the same data irrespective of the node it connects to....

October 11, 2022 · 7 min · Ashish Gaur

Memory Allocation in Java

A typical Java process deals with the RAM, Non RAM memory and Registers. It’s useful to understand how a Java process accesses and manages these memories: Registers - the fastest storage in your computer are Registers. Why so ? Because Registers are present inside the processor itself. Registers cannot be accessed directly by a process. RAM - The memory allocated to a process resides in the RAM. There are two types of allocation that happens: Heap memory space - The general purpose pool of memory where all Java objects reside....

October 10, 2022 · 1 min · Ashish Gaur

Inheritance in Java

Inheritance is a mechanism through which a class can inherit properties(fields and methods) of another class. This allows to resuse the fields and methods of the parent class. Inheritance also represents the IS-A relationship which describes the parent-child relationships between the classes. Types of Inheritance Java allows 5 types of Inheritance: Single - One class inherits another class. class A { public void method() { // Do Something } } class B extends A { public void anotherMethod() { // Do Something } } Multilevel - A chain of inheritance....

October 10, 2022 · 2 min · Ashish Gaur