Skip to main content

Posts

Showing posts with the label algorithm

Shift Reduce algorithm source code in c for Compiler

#include #include #include #include #include using namespace std; struct stru1 { char non_ter[1],pro[25]; }cfg[25]; int n,st=-1,j,i,t=-1,m; int v,c,p=1; char str[20],stack[20],ch,tmp[10]; void match(int k); void matchl(int k); int main() { printf("Enter the number of productions:\n"); scanf("%d",&n); printf("\n"); printf("Enter the productions on LEFT and RIGHT sides:\n"); for(i=0;i \n"); scanf("%s",cfg[i].pro); printf("\n"); } printf("Enter the input string:\n"); scanf("%s",str); printf("\n"); i=0; do { ch=str[i]; stack[++st]=ch; tmp[0]=ch; match(1); i++; }while(str[i]!='\0'); c=st; v=st; puts(stack); printf("\n"); while(st) { --st; v=st; t=-1; p=0; while(v<=c) { ...

Iterative Deeping algorithm source code in C++

 Source code of iterative deeping search is given. # include <stdio.h> # include <iostream> # include <sstream> # include <algorithm> # include <string.h> # include <string> # include <math.h> # include <queue> # include <vector> using namespace std; int node,edge; vector<int>adj[100]; bool flag[100]; int dist[100],par[100],leb[100]; int bfs(int s,int e,int lev) {    int i,cur,head,tail,que[10000],l=0;    head = tail = 0;    que[head++] = s;    flag[s] = 1;    dist[s] = 0;    par[s] = -1;    leb[s] = 0;    memset(leb,0,sizeof(leb));    while(head != tail)    {        cur = que[tail++];        if(leb[cur] == lev)        {            return 0 ;      ...

Line Clipping or Liang Bersky Algorithm source code in c++ with openGL

#include <windows.h> #include <GL/glut.h> #include <stdlib.h> #include <iostream> #include <string> #include <string> #include <ctype.h> #include <math.h> #include <stdio.h> #include <map> #include <vector> double xmin=50,ymin=50,xmax=100,ymax=100; double xvmin=150,yvmin=150,xvmax=400,yvmax=400; double x2,y2,x3,y3; int test(double p,double q,double *t1,double *t2) {     double t=q/p;     if(p<0.0)     {         if(t> *t1) *t1=t;         if(t> *t2) return(false);     }     else if(p>0.0)     {         if(t< *t2) *t2=t;         if(t< *t1) return(false);     }     else if(p==0.0)     {    ...

Successive shortest paths algorithm description with source

• Start with flow f with f ( u,v )=0 for all u , v . • repeat until value( f ) = r – Find the shortest path P in G f from s to t – Let q be the minimum residual capacity of an edge on P. – Send min( q , r – value( f )) additional units of flow across P. On the successive shortest paths algorithm : • May use exponential running time • Assume G has no negative edge costs. • Gives optimal answer. – Invariant: f   has minimum cost among all flows with value value ( f ). • Suppose we obtain f’ from f  by sending across P. • Let f’’ be a minimum cost flow with same value as f’ . • Write f’’ – f as weighted sum of paths from s to t in G f and circuits in G f . Argue that cost( f’ – f ) / cost( f’’ – f ), using that: – P is shortest path – Circuits have non-negative costs, by optimality of f .   Source code link is given  here

Exon Chaining source code in Perl (Dynamic programming)

Exon Chaining Problem: Can't tell lucky or not the same problem is can be found in Uva online judge for programming.When our team attend a contest in a university in bangladesh this modified version of this problem is given .(11908 Skyscraper) . In Bio-informatics it is a set of exon is given now create the amino acid from which the needed protein can be found. Input >> here cuttings from start to end with score is given. Output >> Give the maximum Allginment Score and selected chunk. Code is given bellow (perl): ************************************************************************************* INPUT >> 2 3 3 1 5 5 4 8 6 6 12 10 9 10 1 7 17 12 11 15 7 13 14 0 16 18 4 OUTPUT>> 21 use strict; use warnings; main(@ARGV); sub main {   my $line;   my $co = 0;   my ($i,$ans);   open(MYDATA,"in1.txt");   my @G = [(1...10),(1...4)];   while($line = <MYDATA>)   {     chomp($line...

Bio-informatics Edit distance source code for alignment of two genome Sequence in perl

Edit distance problem(By modified LCS): If input is >> A AAAA Then output is >> ------A AAAA where --- means insert. Delete can be handle in same way and replace also. Complex one is>> ATCGA TGAC out >> A T C G A - -  T  - G A C Now the code is in perl and is given bellow.... *********************************************************************************** main(@ARGV); my $co = 0; my($x,$y); sub main {   my @line;   my @a;   my @b;   my $c = 0;   open(MYDATA,"in.txt");   while($line = <MYDATA>)   {     chomp($line);     if($c == 0)     {        @a = split'',$line;     }     else     {        @b = split'',$line;     }     ++$c;   }   close MYDATA;    lcs(\@a,\@b);  ...

Introduction to Bioinformatics Algorithm Partial Digest source code in Perl

Partial Digest Problem : Its a common known problem in bio-informatics where chunk of DNA with deferent length is given.Our work is to find out in what position this chunk is cut-up.I completed this problem by backtracking in Perl language where multiple solution can be found.The code is given here.You should first understand the problem than use this code.(For your good)I use Introduction to Bio-informatics Algorithm Book as reference. ************************************************************************************* use strict; use warnings; main(@ARGV); sub main {     # here value is the  set of piece which cut from entire length  and flag use for just check which piece used and which     # piece not used before and unsed is counter for how much piece are not  used still now , inti is the starting point and     # end is end point of entire length  and at the end point are the array which contain st...