The document provides procedures for implementing various algorithms including minimum spanning tree, single source shortest path, job sequencing with deadlines, traveling salesperson problem, knapsack problem, N-queens problem, graph coloring, merge sort, linear search tree, subset sum problem, Euler circuit detection, expression evaluation using stacks, and infix to postfix conversion. Input, procedures with steps, and output are described for implementing each algorithm using concepts like adjacency matrices, dynamic programming, backtracking, divide and conquer, and stacks.
The document provides procedures for implementing various algorithms including minimum spanning tree, single source shortest path, job sequencing with deadlines, traveling salesperson problem, knapsack problem, N-queens problem, graph coloring, merge sort, linear search tree, subset sum problem, Euler circuit detection, expression evaluation using stacks, and infix to postfix conversion. Input, procedures with steps, and output are described for implementing each algorithm using concepts like adjacency matrices, dynamic programming, backtracking, divide and conquer, and stacks.
The document provides procedures for implementing various algorithms including minimum spanning tree, single source shortest path, job sequencing with deadlines, traveling salesperson problem, knapsack problem, N-queens problem, graph coloring, merge sort, linear search tree, subset sum problem, Euler circuit detection, expression evaluation using stacks, and infix to postfix conversion. Input, procedures with steps, and output are described for implementing each algorithm using concepts like adjacency matrices, dynamic programming, backtracking, divide and conquer, and stacks.
The document provides procedures for implementing various algorithms including minimum spanning tree, single source shortest path, job sequencing with deadlines, traveling salesperson problem, knapsack problem, N-queens problem, graph coloring, merge sort, linear search tree, subset sum problem, Euler circuit detection, expression evaluation using stacks, and infix to postfix conversion. Input, procedures with steps, and output are described for implementing each algorithm using concepts like adjacency matrices, dynamic programming, backtracking, divide and conquer, and stacks.
Download as DOC, PDF, TXT or read online from Scribd
Download as doc, pdf, or txt
You are on page 1of 13
B.
Tech (Computer Engineering) 5th Semester
COT-311, ALGO!T"# ($) "%n&outs 1' !mp(ement the minimum cost sp%nning tree. !nput' Undirected graph G represented by adjacency cost matrix. $roce&ure' Step 1: Find the minimum cost edge from the given graph. Step 2: the next (i j! to be added is such that i is the vertex a"ready inc"uded in the tree j is the vertex not yet inc"uded and cost (ij! is minimum among a"" edges (#"! $here # is in the tree and " is not. Step %: &epeat the above process for a"" vertices. Output' 'inimum cost tree represented by n(2 array. )' !mp(ement the sing(e source shortest p%th %(gorithm. !nput' Undirected graph G represented by adjacency cost matrix. $roce&ure' Step 1: Shortest path from the initia" vertex v) is generated and saved in a set S $hich denotes the set of vertices to $hich the shortest path have a"ready been generated. Step 2: Se"ect u among the vertices not in S $hose dist*u+ is minimum. Step %: For $ not in S. ,et dist*$+ be the "ength of shortest path starting from the u going through a"" the vertices that are in S and ending at $. Step -: Find out $ such that its distance is minimum $.r.t vertex u a"ready inc"uded in S. Step .: &epeat step % / - for the rest of vertices. Output' 0rray containing the vertices having shortest path. 3' !mp(ement the %(gorithm *or +o, se-uencing .ith &e%&(ine. !nput' 1he arrays indicating the dead"ines (di! and profits (pi! of the jobs. $roce&ure' Step 1: 2obs are sorted such that p1 3 p2 44..3 pn . Step 2: Since the jobs are in non5increasing order of pi6s so $e ta#e first job $ith "argest va"ue of pi. Step %: 2obs are maintained in array 2 $hich indicates a set of jobs that are a"ready inc"uded. Step -: 7hen job i is consider determine $here in 2 this job has to be inserted. Output' 0rray 2 $hich represents the se8uence of jobs. /' !mp(ement the %(gorithm *or tr%0e(ing s%(es person pro,(em using &1n%mic %ppro%ch. !nput' Undirected graph G represented by adjacency cost matrix. $roce&ure' Step 1: ,et S be the set of input vertices and 9onsider function g (i S! be the "ength of shortest path starting at vertex i and going through a"" vertices in S and terminating in vertex 1. Step 2: So our aim is to find out g (1 : ; <1=! is the "ength of optima" sa"es person tour using g (1 : ; <1=! > min 2? #? n <c1# @ g (# : ; <1 #=!= Step %: For the above purpose ta#e set : $ith siAes B : B ) 144.n .and repeat the above process. Output' 0 variab"e min cost giving the minimum cost va"ue. 5' !mp(ement the %(gorithm *or 2n%ps%c2 pro,(em using LC Br%nch %n& Boun& pro,(em. !nput' 0rray of profits (pi! and $eights ($i! and max. 9apacity m of the #napsac#. $roce&ure' Step 1: 0rrange the $eights and profit according to the non5 increasing order of piC$i. 9a"cu"ate the "east cost va"ue indicating the Step 2: 9a"cu"ate the "east cost va"ue indicating the $eights inc"uded in the #napsac# $here fractiona" portion of the $eight is a"so considered. Step %: 9a"cu"ate the upper bound va"ue indicating the $eights inc"uded in the #napsac# $here fractiona" portion is not considered. Step -: &epeat the step 2 / % by considering xi > ) and xi > 1 $here xi represents $hether $i is not ta#en and ta#en in the #napsac# respective"y. Step .: For the case $here there is "east va"ue repeat step - for the next va"ue of i. Output' 0rray x $hich indicates the $eights $hich are inc"uded or not inc"uded in the #napsac# respective"y. 3' !mp(ement the %(gorithm *or n--ueen pro,(em using B%c2tr%c2ing. !nput' :ariab"e n indicating the no. of 8ueens to be p"aced over nDn matrix. $roce&ure' Step 1: 1a#e an array D $hich indicates over $hich co"umn 8ueen i is p"aced. Step 2: 1ry to p"ace 8ueen # over the co"umn E after chec#ing that they shou"dn6t be on the same diagona" and on the same co"umn .Start the va"ue of # from 1. Step %: &epeat step 2 for a"" 8ueens i.e # > 2 to n. Output' 0rray x $hich indicates the co"umns over $hich 8ueens can be p"aced. 4' !mp(ement the %(gorithm *or gr%ph co(oring using B%c2tr%c2ing. !nput' Undirected graph G represented by adjacency cost matrix. $roce&ure' Step 1: 1a#e an array D $hich indicates the co"ors that cou"d be given to the vertices of the graph. Step 2: 1ry to give co"or to the vertex i after chec#ing $hether the adjacent vertex has been given the same co"or. Step %: &epeat step 2 for a"" vertices i.e. i > 2 to n. Output' 0rray x $hich indicates the co"ors given to the vertices of the graph. 5' !mp(ement the %(gorithm *or merge sort using &i0i&e %n& con-uer %ppro%ch. !nput' 0rray indicating the "ist of unsorted numbers. $roce&ure' Step 1: Fivide the "ist into 2 parts using mid > ("o$ @ high! C 2 $here "o$ and high indicates boundary va"ues of the array. Step 2: Gver the sub5part Step %: &epeat step 2 for a"" vertices i.e. i > 2 to n. Output' 0rray containing the "ist of sorted va"ues. 6' !mp(ement the %(gorithm *or optim%( ,in%r1 se%rch tree using &1n%mic %ppro%ch. !nput' % 0rrays indicating the set of identifiers probabi"ity of search of an e"ement probabi"ity of not search of an e"ement. $roce&ure' Step 1: ca"cu"ate $(ij!> p(j!@8(j!@$(i j51!. Step 2: ca"cu"ate c(ij!> min< c(i#51!@c(#j!@$(ij! and find r(ij! $hich represents the node $ith minimum va"ue for $hich c(ij! got its minimum va"ue. Step %: &epeat step 1 /2 for i and j $here i5j varies from ) to n Output' 0rray r (i j! containing the root of sub trees containing nodes i@1 to j. 17' !mp(ement the %(gorithm *or sum o* su,sets pro,(em using ,%c2tr%c2ing. !nput' 0rray indicating the $eights $ * + and a variab"e m to indicate maximum va"ue $roce&ure' Step 1: Generate "eft chi"d using s @ $*#+ ? m $here s indicates sum ta#en so far and repeated the process unti" condition vio"ates. Step 2: Generate right chi"d using s @ r ; $*#+ 3 m and s @ $ *#@1+ ? m $here r indicates the remaining $eights and repeat the process unti" condition vio"ates. Output' 0rray x indicating ) or 1 $hich means $hether the $eight is inc"uded or not. 11' 8rite %n %(gorithm to chec2 .hether the gr%ph cont%ins Eu(er circuit or not. !nput' Undirected graph G represented by adjacency matrix. $roce&ure' Step 1: For every vertex ca"cu"ate the degree of the vertex Step 2: Find out the modu"us $ith 2 if for any vertex modu"us is 1 then brea# and dec"are no Hu"er circuit e"se Hu"er circuit is there. Output' 0 f"ag variab"e indicating $hether the graph contains Hu"er6s circuit or not. 1)' 8rite % progr%m *or e9pression e0%(u%tion using st%c2s. !nput' Hnter the postfix expression. $roce&ure' Step1: Scan the entire expression from "eft to right. Step 2: a! if an operand is encountered then put it on stac#. b! Ef encounter an operator then pop t$o e"ements of the stac# and perform Gperation on that e"ement. c! I"ace the resu"t on the Stac#. Output':a"ue on the top of the Stac#. 13' 8rite % progr%m *or in*i9 to post*i9 con0ersion. !nput &ead the infix expression containing operands that are sing"e character "etters or digits and operators in a string. :unctions' Irecedence function that ta#es t$o characters as an arguments and return true if argument1 has precedence over argument2 e.g. preced(@(! >F0,SHpreced(@@! >1&UHI&H9HF((@! >1&UH. $roce&ure' Step 1: Iush function that ta#es an operand to be pushed onto the stac# Step 2: Iop function that returns an operand from stac# Step %: Ento post function that ta#es t$o strings as arguments one string for infix expression and other string for the postfix expression. 1his function scans the infix expression. Step -: Iush J(Jonto stac# and add J!K to the end of infix string Step .: Scan infix string from "eft to right and repeat steps % to L for each e"ement of M unti" the stac# is empty: a! 0n operand is encountered add it to postfix string. b! 0 "eft parenthesis is encountered push it onto stac#. c! Ef an operator N is encountered then: &epeated"y pop from from stac# and add to postfix string each operator $hich has the 1&UH va"ue on ca""ing preced function ( !. 0dd N to stac# Ef a right parenthesis is encountered then: &epeated"y pop from stac# and add to postfix string each operator unti" a "eft parenthesis is encountered &emove the "eft parenthesis. *Fo not add the "eft parenthesis to postfix string+. Output' Iosts fix expression in a string.