Question
[Verification and Validation] The following is an implementation of the function findMiddle , which is expected to find an element in the given array that
[Verification and Validation]
The following is an implementation of the function findMiddle, which is expected to find an element in the given array that is closest to the average of the elements in the array.
Below is a control flow graph of the program.
Answer the following questions.
1.) What is the path produced by the input: arr = [2]? 2.) What is the path produced by the input: arr = [4, 5, 1, 3]? 3.) Find a test input which produces the test path [1, 2, 3, 2, 3, 2, 3, 2, 4, 5, 6, 8, 5, 6, 8, 5, 6, 7, 8, 5, 9]. 4.) Find a test path which is not produced by any test input. 5.) Find all the nodes n such that Def(n) contains k. (In other words, find all the nodes n where the variable k is assigned a value.) 6.) Find all the nodes n such that Use(n) contains sum. (In other words, find all the nodes n where the value of the variable sum is read.) 7.) Find two DU-paths with respect to the variable sum. 8.) Find all the nodes to which there is a DU-path from node 4 with respect to the variable k.
1 public static int findMiddle (int[] arr) sum, middle; int k, double mean; sum = 0; for (k 0; k arr . length ; k++) 4 sum += arr [k] mean = sum arr. length; middle = arr[0] ; for (k 0; kStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started