Posts

Showing posts from 2016

Edit Distance Problem

/* ==========  ========== ========== ========= ======== ===========*/ //            CF - Edit Distance Problem                                                                               // //       Solution Code using  DP                                     // //            Author - Piyush Jain                                                                                            // //                                                                                                                                         // /* ========== ========== ========== ==========  ========== ======   */ //Note:- We are converting  string s into t and assuming and every operaion (INSERT,DELETE and REPLACEMENT took ONE unit cost) // dp[i-1][j] => stand for insert operation in "s" string // dp[i][j-1] => stand for delete operation in "s" string // dp[i-1][j-1] => replacement of i-1th character in "s" string via j-1th character of stri

Enable logging in Haproxy.

HAProxy Log Setup HAProxy wants to log.   First HAProxy does not log directly into a file due to performance reason. So we need to handle  that with syslog server. But Haproxy also requires a syslog to listen on UDP port ( which in default syslog/rsyslog installation is not enabled ).   Basically log enable format in haproxy cfg is  “log <address> <facility> [max level [min level]]” Note:-  Adds a global syslog server. Up to two global servers can be defined. They will receive logs for startups and exits, as well as all logs from proxies configured        with "log global”.    <address> can be one of:        - An IPv4 address optionally followed by a colon and a UDP port. If no port is specified, 514 is used by default (the standard syslog port).        - A filesystem path to a UNIX domain socket, keeping in mind considerations for chroot (be sure the path is accessible inside the chroot) and uid/gid (be sure the path is appropriately

Kruskal Algorithm.

//No one born perfect :) //Kruskal Algorithm //Finding MST (Minimum Spanning Tree) //Greedy Algo //O(ElogE or ElogV) //DS use DisJoint DS (Union Find)(very important DS) //How it is work ? (We are considering that Graph is connected ) // a). First Sort all edge in increasing order according to weight // b). Now Iterate each edge(u,v) in Edges and check whether these // vertax u and v are in same tree or not (which we are finding using union and find method) // if not include this edge otherwise continue (For more understanding see source code) //  c). You will get a MST in end. //For proof go wiki page:- // https://en.wikipedia.org/wiki/Kruskal%27s_algorithm#Proof_of_correctness // Happy Coding. ///////////////////////////////////////////////////////////////////////////////////////////// #include <iostream> #include <cstdio> #include <list> #include <cstring> using namespace std; // vector<vector <long int,long int>