Coding Question: You are given an set of numbers {1..N} and an array A[N-1]. Find the number from the set that is not present in the array. (IN JAVA, without using HashSet) a. Include comments within your code. Be detailed. b. What other approaches did you consider to solve this question and why did you choose this approach?
Code:
import java.io.*;
import java.util.*;
class Compare
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int i,flag,j,n1,n2;
/*Accepting Number Of Elements Of Set*/
System.out.println("Enter Number Of Elements In Set");
n1=sc.nextInt();
/*Creating Array Named set to Hold The Set Elements*/
int set[]=new int[n1];
/*Accepting Number Of Elements(Length) Of Array*/
System.out.println("Enter The Elements Of Set");
for(i=0;i<n1;i++)
{
set[i]=sc.nextInt();
}
/*Accepting The Array Elements*/
System.out.println("Enter The Number Of Elements In Array");
n2=sc.nextInt();
int arr[]=new int[n2];
System.out.println("Enter The Array Elements");
for(i=0;i<n2;i++)
{
arr[i]=sc.nextInt();
}
/*Finding Numbers From Set That Are Not Present In Array*/
/*Nested For Loops For Comparison Of Set Elements And Array
Elements*/
for(i=0;i<n1;i++)
{
flag=0;
for(j=0;j<n2;j++)
{
if(set[i]==arr[j])
{
flag=1;
/*If flag=1 then ith element of set is found at jth index in
array*/
}
}
/*If flag=0 then elements ith element of set is not found in array
*/
if(flag==0)
{
System.out.println(set[i]+" Not Found In Array");
}
}
}
}
Output Screenshot:
Please Up-Vote,If You Find This Solution Helpful !!
In Case Of Any Doubt/Query Feel Free To Comment Down Below.
Coding Question: You are given an set of numbers {1..N} and an array A[N-1]. Find the...
Java question
Given an array of integer numbers, write a linear running time complexity program in Java to find the stability index in the given input array. For an array A consisting n integers elements, index i is a stability index in A itf ATO] + A[1] + +A[iI-1] Ali+1]+ Ali+2] +... + A[n-1]; where 0 <i< n-1 Similarly, 0 is an stability index if (A[1] A[2]A[n-1]) 0 and n-1 is an stability index if (A[0] A[1]+... A[n-21) 0 Example:...
Given an array of integer numbers, write a linear running time complexity program in Java to find the stability index in the given input array. For an array A consisting n integers elements, index i is a stability index in A if A[0] + A[1] + ... + A[i-1] = A[i+1] + A[i+2] + ... + A[n-1]; where 0 < i < n-1. Similarly, 0 is an stability index if (A[1] + A[2] + ... + A[n-1]) = 0 and...
Use Java or Javascript to slve
1. Given an array of numbers, write a function to return an array of numbers' where productsli] is the Input: [1, 2, 3,4, 5] Output: [(2*3*4*5), (1 3*4*5), (1*2*4*5), (1*2*3*5), (1*2*3*4)1 [120, 60, 40, 30, 24] You should do this in O(N) without using division.
Maximum Value But Limited Neighbors You are given an array a[1..n] of positive numbers and an integer k. You have to produce an array b[1..n], such that: (i) For each j, b[j] is 0 or 1, (ii) Array b has adjacent 1s at most k times, and (iii) sum_{j=1 to n} a[j]*b[j] is maximized. For example, given an array [100, 300, 400, 50] and integer k = 1, the array b can be: [0 1 1 0], which maximizes the...
1. Given a set of numbers: A = {1, 3, 5, 2, 8, 7, 9, 4 }. Add each digit of your N-Number (e.g. N0 0 3 2 2 0 1 8) to each element of A separately to get your own final array B. ( e.g. B={1,3,8,4,10,7,10,12} = {B1,B2,B3,B4,B5,B6,B7,B8}. ) a) Your set B = ? b) Use merge-sort to sort the array B. Show each step. c) How many “comparisons” for each algorithm above? 2. Use binary-search for...
Question 6 (1 point) Let a be an array, let N be the number of elment used in the array. For the given set of code below, what does the output represent? int sum = 0; for (int i = 0; i < N;i++) if (a[i] > 0) sum = sum + 1; textBox1.text = " + sum; Execution of code with nothing being printed in textBox1. Execution of code with printing all numbers Execution of code with counting the...
need help in this algorithm question
Let A be an array containing n numbers (positive and negative). Develop a divide and conquer algorithm that finds the two indices 1 sisjsn such that A[k] (the sum of the elements from i to j) is maximized. For example, in the array A [10,-5,-6,5, 7,-2,4, -11], the sub-array A[4:6] has the sum 5+ 7-2+4-14 and no other sub-array contains elements that sum to a value greater than 14, so for this input the...
You and Ellie are playing a game, in which first Ellie chooses r numbers out of the set 1,2,,n, for 1 S n, and then you independently choose r numbers out of the same set. What is the probability that: (a) Your set of r chosen numbers do not include consecutive values? (b) Your set of r chosen numbers includes precisely one pair of consecutive values? (c) Given Ellie's selection, your numbers are precisely the same as hers? (d) Given...
You will be given an array of N elements sorted small to large. For the X and Y values that satisfy the X ≤ Y condition, draw the flow diagram of the algorithm that finds the start and end addresses of the region with the numbers greater than X and less than Y with the divide and manage approach and with O (logN) complexity. Also code the algorithm in c language. (not c++) Example: A[0…8] array 3, 5, 7, 9,...
DESCRIPTION: You will be given a 1-D array, called wordFun, of Strings. The array has an unknown number of cells filled with data. As before, the array will already be filled with strings, some of which contain the string "Angela". You will create a method called countItUp which returns and integer array containing the number of times each of the letters in my name occur within the strings within this array. For example, if the input array was wordFun =...