Posts

Linear programming problem Using simplex method.

Question :                    Max Z = 6X + 8Y  subject to,                    30X + 20Y ≤ 300                      5X + 10Y ≤110                         X,Y ≥ 0 Solution : Step 1 : First of all,Convert the above equations in standard form.And,then Add S1 ,S2 in the equation (i)  & (ii) respectively in L.H.S Side with coefficient 1. While in the objective function add or subtract (It doesn't affect the equation) S1 & S2 with coefficient 0 in L.H.S. Note 1: If there was greater or equal to sign (≥) in the equation then you have to subtract S1 & S2 respectively in the L.H.S.  Note 2: We had taken here only two variables S1 & S2 because here we have only two equations other than objective function.         ...

Linear Programming Problem Using Graphical Methods.

Image
Suppose you are given an Objective function :                 Max Z = 6x+5y Subject to,                 X+Y ≤  5                 3X+2Y ≤ 12                 X,Y ≥ 0 Solution :- Step 1: You have to put 0 in place of X to calculate Y. Again, you have to put 0 in place of Y and calculate X, by removing the less-than sign.  So, Putting X=0 in equation X+Y ≤ 5. The equation becomes, [0+Y=5], So Y comes out to be Y=5.  So the solution is (0,5).................................................................................{I} Now, putting Y=0 in the equation X+Y ≤ 5. The equation becomes,[X+0=5], So X comes out to be 5. So the solution is (5,0)..................................................................................{II} Now, Putting X=0 in equation 3X+2Y ≤ 12. The equation beco...

What are the advantages of using Distance Vector Routing ?

Advantages of Distance Vector Routing are :  Large Routing Tables High network traffic overhead. Route advertising is done periodically even after the internetwork has converged. Multiple routes to a given network ID can be reflected as multiple entries in the routing tables. Doesn't scale. Disadvantages of Distance Vector Routing are :        1. It is slower to converge than the link state.        2.  It is at risk from the count-to-infinity problem.       3.  It creates more traffic than link-state since a hop count change must be propagated to all routers and processed on each router. Hop count updates take place on a periodic basis, even if there are no changes in the network topology, so bandwidth-wasting broadcasts still occur.      4. For larger networks, distance vector routing results in larger routing tables than link-state since each router must know about all other route...

Write code to reverse C-style string.

Note :- c-string means that 'abcd' is represented as five characters, including the null character. Algorithm: Void reverse(char *str) {       char *end=str;       char temp;       if(str)       {            while(*end)        {             ++end;        }             --end;             while(str < end)             {                   temp=*str;                   *str++ =*end;                   *end-- =temp;             }       } }

Write an algorithm to determine if a string has all unique charcters.

public static boolean isUniqueChars2(String str) {        boolean [] char_set =new boolean[256];           for(int i=0; i<str.length(); i++)           {               int val=str.charAt(i);               if (char_set[val])               return false;              char_set[val]=true;                 }            return true; } 2nd Method : public static boolean isUniqueChars(string str) {       int checker=0;       for(int i=0;i<str.length();++i)       {           int val=str.charAt(i) -'a';           if((checker & (1<<val))>0)           return ...

Prove that every tree has at most one perfect matching.

Image
Since every tree with 2 or more vertices is 2-chromatic. We see that a tree with even no. of vertices will have perfect matching as all vertices with the same color can be grouped together and a matching can be established between the two groups. If the tree has odd number of vertices,then no perfect matching can be established for obvious reason.    [proved ]

Prove that every tree with 2 or more vertices is 2-chromatic.

Image
Since a tree is connected and has no cycle if one starts coloring any one vertex with a specific color and keeps on coloring every alternate vertex with another color, the entire graph can be colored with only two colors and since there is one and only one path between any two vertices in a tree, no two vertices will have the same color. Hence every Tree with 2 or more vertices is 2-Chromatic.    [Proved]                                                                 FIG (I)                                                                  FIG (II)

Show that every Bi-partite graph is 2 chromatic.

Image
Let G be a Bi-partite graph.            So, V(G)=V1 U V2    Color every vertex in V1 by one color and every vertex in V2 by another Colour.    Then, clearly, this coloring is proper. Thus only two colors suffice to color G. so, G is 2 chromatic.    [Proved] image source :Google

Prove that the number of circular permutations of n different objects is (n-1)! .

Since n different objects are arranged in a circle, the relative positions not the linear positions determine the arrangement . Hence, if one of them is kept fixed, the remaining n-1 can be arranged in (n-1)! ways. This is exactly the number of circular permutations with n distinct objects.

State the "Pigeon Hole Principle" and the " Generalised pigeon Hole principle".

If n pigeons are assigned to m pigeonholes and n>m, then at least one pigeonhole contains two or more pigeons. if there are n pigeonholes occupied by nk+1 pigeons, then there must be at least one pigeonhole occupied by k+1 or more pigeons.