Posts

DNF sorting ( 0s , 1s , 2s, sorting )

Image
ABOUT  DNF  SORTING  WHAT IS SORTING?   Sorting    is   a   process   of   arranging   items (   any things   ex :- ,elements in array   , table , marks , price of things etc)   in systematically   such that   in ascending   or descending    in form of   correctly   sequence . 1.          Ordering :- Arranging items   in a sequence ordered by some   strategy. 2.        Categorizing :- grouping elements in similar properties.                                    WHAT IS DNF SORTING?   It is   also   known   as Dutch National Flag   .Some times    It is known    by     0 ,1, 2s sorting. ...

Write the program to arrange the n queen(queen of chessboard) in n*n matrix such that they can not ATTACK TO eachother.

Image
  OUTPUT : In form of matrix of elements (0 and 1)     where 1 is suitable position where can be keep without attack to each other.   USED : Recursion , BACKTRACKING etc CHARACTERISTICS   OF QUEEN :     A )They can move in any position in a row where it is presence.     B )They can move in any position in a column where it is presence.     C )They can move in any position in a diagonal where it is presence. CONDITION :     Arrange the queen such that they can not ATTACK to each other.     in n*n matrix       APPROCH :    A )put a queen in a row than move next row to put      the next queen in next row such that they can not ATTACK each other        After matrix 4 they are not any place where a queen can be Put without attack by anyone so BACKTRACK occur here and reach again to Matrix 1 and then continue...

write a program for finding the path in maze from, begin to end

Image
write a program for finding the path in maze from, begin to end ABOUT FIGURE :Deep blue indicates wall and deep green denotes free path. In above figure , upper matrix is input In below matrix is output (path in form of 1) CONDITION : movement takeplace ony in positive x direction                   and in negative y direction APPROCH :  a)in a maze 1 denote movement space and 0 denote wall   b)use recursion to find the way by reducing number of box   c)use a new_array which initialisation by 0,and after getting path         become 1 on that place.   D ) use BACKTRACKING ,if_rat will not get path then it take back the path      this_ is known as backtracking. backtracking (algorithmic technique) Definition:  Find a solution by trying one of several choices. If the choice proves incorrect, computation  backtrac...

Write the program for finding aprroxiamate root of a function by Bisection method

Image
The method is applicable for numerically solving the equation  f ( x ) = 0 for the  real  variable  x , where  f  is a  continuous function  defined on an interval [ a ,  b ] and where  f ( a ) and  f ( b ) have opposite signs. In this case   a  and  b  are said to bracket a root since, by the  intermediate value theorem , the continuous function  f  must have at least one root in the interval ( a ,  b ). At each step the method divides the interval in two by computing the midpoint  c  = ( a + b ) / 2 of the interval and the value of the function  f ( c ) at that point. Unless  c  is itself a root (which is very unlikely, but possible) there are now only two possibilities: either  f ( a ) and  f ( c ) have opposite signs and bracket a root, or  f ( c ) and  f ( b ) have opposite signs and bracket a root. [5]  The method sele...

Write the program to determine the maximum possible way to reach the end from starting in game board.

Image
         #include <iostream> #include <string> using namespace std;   int maxpath( int str, int end)    {   if (str==end)            {  return 1;} //when number of blocks be lessthen no of jumps(max jump 6)      if (str>end)       {return 0;} // then this conditio n will follow satisfy.                             int count=0;          for ( int i=1;i<=6;i++)         {  count =count + maxpath(str+i,end);}       return count;        }                int main() {    int   str=1; //str = ...

Write the program to make Permutation(arrangements of string ) of a string .

Image
http://cpp.sh/6tjpq   some points :- 1_ )Permutation :- A permutation is a mathematical technique      that determines the number of possible arrangements in a set     when the order of the arrangements matters.     2_ ) Syntex   :: string.substr(i  , ln  )       Use of this Syntex :- to make        substring (i.e make small         String from big string).      i = i represent index.      ln= ln represent lenth of string           ex:- let string  a = "abgs" ;             cout<<a.substr(0,0) //print nothing lenth is zero             cout<<a.substr(0,1) //print 'a' because at zero index 'a' is present and length is 1     ...

Write the program to print all possible words from keypad 2 and 3 from keypad mobile.

Image
  /* click on below the  link and  run this program.     http://cpp.sh/8g5dbz */ Some points :  1) if we want  to add characters make a string than we should  make a string variable f=""; and add in intial with characters example " let suppose we want add char a[0]+char b[0] and to make a string if we add simply then we get 197 but if we add f+a[0]+b[0 ] then we will get string ( ad ). 2)to change  ASCII code of string or character into Integer then simply      suppose char a ="A"; to_string(a)//output 65(ASCII code of A)  in string form.       */ #include <iostream> #include <string> using namespace std; string keypadarr[]={ " " , "/" , "abc" , "def" , "ghi" , "jkl" , "mno" , "pqr","so on" }; void keypadword(string a,string b ) //user define function {         if (a.size()==0)        { return ;}   ...

Write the program to make substring of a string.

Image
#include <iostream> #include <string> using namespace std;   void substring(string a,string ans)   { if (a.size()==0)        {cout<<ans <<endl;      return ;}      char c=a[0];      string ros=a.substr(1);      substring(ros,ans);      substring(ros ,ans+c);     }   int main() {     string a = "ABC" ;     string b = "" ;          substring(a,b);         return 0; }

Write the program to replace pi with 3.14 in string. input = pippdfpig output = 3.14ppdf3.14g

Image
  #include <iostream> using namespace std; void removepi(string a)    { if (a.size()==0)         { return ;}        if (a[0]== 'p' && a[1]== 'i' )      {cout<< "3.14" ;       removepi(a.substr(2));}       else {cout<<a[0];        removepi(a.substr(1));}             } int main() {     string a;      a= "pippdfpig" ;     removepi(a);     return 0; }

Write a program to reverse the string. input = google output = elgoole */

Image
  #include <iostream>   #include <string>   using namespace std; void rvrsstr(string a) //rvrsstr=reverse string:user function {     if (a.size()==0)         { return ;}         rvrsstr(a.substr(1));         cout<<a[0];                           }     int main()     {   string a;          a= "google" ;          rvrsstr(a);       return 0;      }