Question

In: Computer Science

Please do Part III Part I Problem statement: Given an array of 'n' non-duplicate integers, find...

Please do Part III


Part I

Problem statement:

Given an array of 'n' non-duplicate integers, find pairs of integers from the array that make the sum equal to K.

Eg. [1, 2, 7, 11, 6, 9, 5] K= 12

Soln: (1,11), (7,5).

Part II

Write an Oracle for testing this program using Data Flow Testing. As usual, write down test cases in a tabular form with reasons, inputs, expected output etc.


Part III  

1.       Identify the basic blocks in your program and draw the flow graph

2.       Identify as many independent paths as possible with a minimum of three paths)

3. Classify these as simple paths and loop-free paths

4.       Identify the definition, P-uses, and C-uses throughout the program

5.       Identify the def-use associations of variables if any.


need solution to it the earliest possible

Program in java would be needed

Solutions

Expert Solution

import java.util.*;
import java.io.*;

public class Main
{
  
  
   public static void main(String[] args) throws IOException{
      
       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      
       System.out.println("Enter list of non-duplicate values");
       int[] A = Arrays.stream(br.readLine().trim().split(" ")).mapToInt(Integer::parseInt).toArray();
      
       System.out.print("K = ");
       int k = Integer.parseInt(br.readLine().trim());
      
       ///////// Adding all list values into a set
       Set<Integer> set = new HashSet<>();
       for(int i : A)
       {
       set.add(i);
       }
      
       ///// iterating over the set
       Iterator itr = set.iterator();
       while(itr.hasNext())
       {
       int val = (int)itr.next();
      
       ////// for each value in set.... checking whether there is a number exists in
       ////// the set which can add up with the current value to make K
       if(set.contains(k-val)){
       int corr_val = k - val;
       if(val != corr_val)
       System.out.print("(" + val + "," + corr_val + "),");
       }
       itr.remove(); //// once checked , there is no need of number anymore. hence simply remove the number from the set
       }
      
   }
}


Related Solutions

IN JAVA PLEASE Given an unsorted array numbers of integers with duplicate values. Sort the array...
IN JAVA PLEASE Given an unsorted array numbers of integers with duplicate values. Sort the array and remove the duplicates in-place such that each element appears only once in the input array and returns the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. Find the time complexity of your removeDuplicates() method in Big-O notation and write that in a comment line on the top...
please write in c++ Algorithm Design problem: Counting inversions: given an array of n integers, find...
please write in c++ Algorithm Design problem: Counting inversions: given an array of n integers, find out the total number of inversions in the given sequence. For example, for the sequence of 2, 4, 1, 3, 5, there are three inversions (2,1), (4,1), and (4,3). Give a brute-force algorithm with running time of O(n^2). Using the technique of divide-and-conquer, design an algorithm with running time of O(nlog n).
Sorting and Searching Given an unsorted array numbers of integers with duplicate values. Sort the array...
Sorting and Searching Given an unsorted array numbers of integers with duplicate values. Sort the array and remove the duplicates in-place such that each element appears only once in the input array and returns the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. Find the time complexity of your removeDuplicates() method in Big-O notation and write that in a comment line on the top...
Given an unsorted array A of size N of integers, find a continuous sub-array which adds...
Given an unsorted array A of size N of integers, find a continuous sub-array which adds to the given number. Declare dynamic arrays and use only pointers syntax. (no [ ]'s or (ptr+1) stuff. input will be the number of input values to enter followed by the sum to compare with. print out the continuous sub-array of values that are equal to sum or the message 'no sum ofund.' there may be more than one sub-array to be found in...
Given an array of integers and the size of the array, write a function findDuplicate which prints the duplicate element from the array.
C++ Programming using iostream and namespace stdGiven an array of integers and the size of the array, write a function findDuplicate which prints the duplicate element from the array. The array consists of all distinct integers except one which is repeated. Find and print the repeated number. If no duplicate is found, the function should print -1. void findDuplicate (int [ ], int)Example 1: Given array: {2,3,5,6,11,20,4,8,4,9} Output: 4 Example 2: Given array: {1,3,5,6,7,8,2,9} Output: -1
Given an array A[1..n] of integers such that A[j] ≥ A[i] − d for every j...
Given an array A[1..n] of integers such that A[j] ≥ A[i] − d for every j > i. That means any inversion pair in A differs in value by at most d. Give an O(n + d) algorithm to sort this array.
Array with Pointers Find Continuous Sub-Array C++ Problem: Given an unsorted array A of size N...
Array with Pointers Find Continuous Sub-Array C++ Problem: Given an unsorted array A of size N of non-negative integers, find a continuous sub-array which adds to the given number. Declare dynamic arrays and use only pointers syntax (no [ ]’s or (ptr+i) stuff.     Input will be the number of input values to enter followed by the sum to compare with. Print out the continuous sub-array of values that are equal to sum or the message ‘No sum found’. There...
Problem Definition: Problem: Given an array of integers print all pairs of integers a and b...
Problem Definition: Problem: Given an array of integers print all pairs of integers a and b where a + b is equal to a given number. For example, consider the following array and suppose we want to find all pairs of integers a and b where a + b = 16 A= [ 10, 4, 6, 15, 3, 5, 1, 13] The following are pairs that sum to 16: 13, 3 6, 10 15, 1 Your program should print these...
Problem 1: [10 Marks] Given a generic array with ‘n’ items (not only integers). Give a...
Problem 1: [10 Marks] Given a generic array with ‘n’ items (not only integers). Give a solution for checking whether there are any duplicate elements in the array or not? You just need to return a boolean (true or false). State the complexity of your solution. Can you come up with another solution that has O(n logn) complexity? Explain. Problem 2: [10 Marks] Now consider the same problem as problem 1, but this time you only have positive integer numbers...
1. Given an array of integers a dimension n. If the array contains the same number...
1. Given an array of integers a dimension n. If the array contains the same number of even and odd elements get (a1 + an) (a2 + an-1) ... 2. Given an array of integers dimension n. All array elements with even numbers preceding the first element to the maximum, multiplied by the maximum. 3. Given an array of dimension n. Insert after each zero element of the element in the middle (or the amount of secondary elements for even...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT