Posts

Showing posts from November, 2024

Types of Question related to 2 Nodes of a Graph

  Existence of a Path Is there a path from node A A A to node B B B ?  1971. Find if Path Exists in Graph Does a path satisfying certain constraints (e.g., through specific nodes or avoiding certain nodes/edges) exist?  Distance Between Two Nodes Shortest distance : Using algorithms like Dijkstra, Bellman-Ford, or BFS (for unweighted graphs). 787. Cheapest Flights Within K Stops Exact distance or range : Finding if a specific distance exists. Number of Paths Between Two Nodes Simple paths : Count paths where no node is revisited. All paths : Count paths (with possible revisits). K-length paths : Paths of exactly or at most k k k edges Shortest Path Between Two Nodes Weight-based shortest path : Using weights on edges. Fewest edges : Finding paths with the smallest number of edges. Maximum Flow or Minimum Cut Between Two Nodes Maximum flow problems deal with finding the maximum "amount" of a resource that can flow between two nodes in a capacitated graph. Connectivity Qu...

Observer Design Pattern

Observer Design is one of the most important Design Pattern. It has many practical usage like notification services. The main two entities are Publisher(class) and Observer (interface) . Publisher is a class with functions like addObserver and notifyyObservers. Here class WeatherStation is extending Publisher class so that all the functions of Publisher can come to it. Here two Observers Mobile and Monitor is implementing interface  Observer. Inside Mobile and Monitor class, they are subscribing to WeatherData inside the constructors. import java.util.*; interface  Observer {  void  notifyy(); } class Mobile implements Observer{     WeatherStation ws;     public Mobile(WeatherStation ws) {         this.ws = ws;         ws.addObserver(this);     }          @Override     public void notifyy() {         System.out.println("Mobile is noti...