6 votes 6 votes Consider the following pseudo- code while (m<n) if (x>y ) and (a<b) then a=a+1 y=y-1 end if m=m+1 end while What is cyclomatic complexity of the above pseudo -code? 2 3 4 5 IS&Software Engineering isro2014 is&software-engineering cyclomatic-complexity non-gate + – neha singh asked Jun 26, 2016 • retagged Nov 13, 2017 by Arjun neha singh 8.0k views answer comment Share Follow See all 17 Comments See all 17 17 Comments reply Show 14 previous comments Kapil commented Jun 24, 2016 reply Follow Share 8 - 6 + 2 = 4 0 votes 0 votes shivanisrivarshini commented Jun 24, 2016 reply Follow Share Thank u i got it 1 votes 1 votes `JEET commented Jan 6, 2020 reply Follow Share @Satbir Any idea about the equivalent C code? 0 votes 0 votes Please log in or register to add a comment.
Best answer 14 votes 14 votes Cyclomatic complexity will be 8 - 6 +2 = 4 Kapil answered Jun 26, 2016 • selected Jul 2, 2016 by naga praveen Kapil comment Share Follow See all 18 Comments See all 18 18 Comments reply asu commented Jun 26, 2016 reply Follow Share kapil : another formula for calculating CC is =number of decission stmnts +1 here i found only 2 such stmnts..that is 1.while loop 2. if i think the if condition has 2 decision stmnts since there is and condition..we have to check both what u say? 0 votes 0 votes Kapil commented Jun 26, 2016 reply Follow Share @asu yes u r right about the formula but check last second node. it is a decision element....... so 3 + 1 = 4 0 votes 0 votes asu commented Jun 26, 2016 reply Follow Share in the program what are the decision states 0 votes 0 votes Kapil commented Jun 26, 2016 reply Follow Share no dont see the code . for decision states , we have to see the diagram . 0 votes 0 votes asu commented Jun 26, 2016 reply Follow Share not decision states..it is decision statements(which is clear from code) 0 votes 0 votes Kapil commented Jun 26, 2016 reply Follow Share No , it is like this, Cyclomatic complexity V(G) is equal to the number of predicate (decision) nodes plus one .. you can also check answer by counting number of regions.. they are 4. 0 votes 0 votes asu commented Jun 26, 2016 reply Follow Share NOT REGIONS IT IS: (NUMBER OF BOUNDED AREAS +1) 0 votes 0 votes Kapil commented Jun 26, 2016 reply Follow Share ohhh yes... u r right 0 votes 0 votes asu commented Jun 26, 2016 reply Follow Share OK..PLZ TELL ME WHAT ARE THE DECISION STATEMENTS I THINK 1.WHILE LOOP 2.X>Y 3.A<B SINCE THERE IS AND OPERATION WE HAVE TO CHECK BOTH THE CONDITION HENCE BOTH ARE DECISION STMNTS AM I RT? 1 votes 1 votes Danny commented Jun 30, 2016 reply Follow Share yes @asu you are right , 1 votes 1 votes Shreya Roy commented Mar 16, 2017 reply Follow Share Kapil, I think in your diagram the edge u have drawn from 'end if ' to 'end while' should not be there, rather 'end if 'to 'while' the edge is already there ( you have drawn too) and whether to go to 'end while' or ' if 'node is decided at 'while ' node only, I mean there should be only one incoming edge to 'end while' node and that is from 'while' node only. hence 3 is the answer , 1 votes 1 votes Arunav Khare commented Apr 9, 2017 reply Follow Share The diagram for if has 3 nodes, while 4 nodes (which u have drawn) are in if-else..isn't it ? 1 votes 1 votes srestha commented May 6, 2017 reply Follow Share @Kapil why branching in if statement? there is an AND between two statement of if. So, branching not required in if stmt. rt? 0 votes 0 votes Shivansh Gupta commented Dec 11, 2017 reply Follow Share Cyclomatic complexity is given by Control Flow graph and CFG of a block has 1 start and 1 end node. So instead of "end while", there should be an "end" node(not affects answer 4) and also there will be a "start" node before "while"(will increase node and edges by 1 each, hence answer remains as 4 only). 0 votes 0 votes gdas commented Nov 4, 2018 reply Follow Share i think this is wrong approach.... 3 votes 3 votes dr_Jackal commented Dec 26, 2019 i edited by dr_Jackal Dec 26, 2019 reply Follow Share Before seeing this question- answer, I still believe there is only one way to escape the loop (without break condition or OS preemption) i.e the falsity of loop condition check , Can anyone please explain me how this edge (?) is opened here, Since official ans is also 4 , but I am getting 3 with my approach. Thanks in advance !!! 0 votes 0 votes commenter commenter commented Jan 3, 2020 reply Follow Share @dr_Jackal Even I'm getting 3 as answer. This solution is clearly wrong. There won't be any edge between last to nodes. Also last node won't be "end while". "end while" must be in last second node. Here they gave just "if'-then" statement not "if-then-else" statement. So in the diagram there is an extra node. 0 votes 0 votes `JEET commented Jan 6, 2020 reply Follow Share This seems to be a favorite question of ISRO. 1 votes 1 votes Please log in or register to add a comment.
10 votes 10 votes Answer is (B) part. Chhotu answered Apr 15, 2017 Chhotu comment Share Follow See 1 comment See all 1 1 comment reply Rahul Garg commented Oct 5, 2017 reply Follow Share which answer is right ... 3 or 4 ? 0 votes 0 votes Please log in or register to add a comment.
5 votes 5 votes Cyclomatic complexity = no of predicate nodes +1 =3+1 One for while, two for if bcoz of two conditions as if first condition then if second condition then do given. Praveen Saini answered Oct 2, 2015 Praveen Saini comment Share Follow See all 2 Comments See all 2 2 Comments reply Sourabh Kumar commented Jun 16, 2016 reply Follow Share Can you draw the control flow graph. 0 votes 0 votes Praveen Saini commented Jun 16, 2016 reply Follow Share \ check that 1 votes 1 votes Please log in or register to add a comment.