as per HomeworkLib rules i cannot answer more than one question so please post again for the rest.
ALGORITHM
// Take a set of elements as input
// Take K as input
// Iterate from first to last element of the set
// if while iterating any element in the set is found whose value is less than K, end loop and return TRUE from the function
// if the iteration ends and no element in the set is found whose value is less than K return FALSE
C CODE
#include <stdio.h>
// function which checks whether any element exists in the set
which is less than K
// function takes three parameters
// arr- array of elements
// n- size of array
// K- value for comparison
int check(int *arr,int n,int K)
{
// iterate through the array
for(int i=0;i<n;i++)
{
// if any element exist which is
less than K return true
if(arr[i]<K)
return 1;
}
// no element exist which is less than K so return
false
return 0;
}
int main(void) {
// number of elements in the set
int n;
scanf("%d",&n);
// array of numbers
int arr[n];
// input of set elements
for (int i=0;i<n;i++)
scanf("%d",&arr[i]);
// value for comparison 'K'
int K;
scanf("%d",&K);
// call check() function and see whether it return
true or false
if(check(arr,n,K))
printf("Yes there exists a subset
of the given set whose sum of elements is less than K");
else
printf("No such subset
exists");
return 0;
}
OUTPUT:
5 //(number of elements)
1 2 3 4 5 //elements of set
2 //K
Yes there exists a subset of the given set whose sum of elements is less than K
BIG-O
The Big-O of above algorithm is O(n), where 'n' is number of elements in the set
In worst-case the algorithm will have to iterate from first element of the set to last element of the set to find out whether there exists any element whose value is less than K
Subset Sum-2 Write an algorithm (in comments) and specify the big O, and a C program...
Write a C program, allow user to input elements. Given a finite set of integers, find all the subsets with the sum of the elements greater than k.
in java
3) Sum. Write a program that prompts the user to read two integers and displays their sum. Your program should prompt the user to read the number again if the input is incorrect.
EVERYTHING IN C# Write a program that includes a method that returns the sum of all the elements of an ArrayList of Integer Objects. Allow the user to enter the integers to be added to your ArrayList from the console (max of 10 integers). And also write a program that includes a method that returns the sum of all the elements of a Linked List of Integers. Allow the user to enter the integers to be added to your Linked...
2. Write a program to do the following: • ask the user to input the size of an array of integers and allocate space for the array • ask the user to input the integer values for the array and store these values into the array • calculate and display the sum and the average of elements of the array.
Write a program in MIPS assembly language that implements the DESCENDING bubble sort algorithm to sort a variable-sized array of signed 32-bit integers (words)that are read from the console. Be reminded that in a descending sort, the integers are sorted from the largest to the smallest. A “special value” 99999 will beused to signify the end of the input sequence. This value is not to be considered part of the input data set. However, any value greater than 99999 that...
1) A Java program that implements an insertion sort algorithm. (InsertionSort.java): Must include the proper comments in the code. 2) A report in pdf. It contains: a) the pseudocode of the insertion sort algorithm and assertions between lines of the algorithm. b) As insertion sort has a nested-loop of two layers, you need to put one assertion in each loop. c) a proof of the partial correctness of the algorithm using mathematical induction c.1) prove the correctness of the two...
C++
Write a program to calculate the sum of two matrices that are
stored inside two-dimensional arrays. Your program should include
three functions: one for getting input data, one for calculating
the sum of matrices, and one for printing the result.
a) Function inputMatrix: This Function prompts the user to enter
the data and stores data inside two-dimensional array.
b) Function addMatrices: This function calculatesthe sum result
of two matrices.
c) Function printMatrix: This function prints the matrix to
screen....
In this program, you will be using C++ programming constructs, such as overloaded functions. Write a program that requests 3 integers from the user and displays the largest one entered. Your program will then request 3 characters from the user and display the largest character entered. If the user enters a non-alphabetic character, your program will display an error message. You must fill in the body of main() to prompt the user for input, and call the overloaded function showBiggest()...
a. Use pseudocode to specify a brute-force algorithm that takes as input a list of n positive integers and determines whether there are two distinct elements of the list that have as their sum a third element of the list. That is, whether there exists i, j.k such that iヂj, i关k,j关k and ai + aj = ak. The algorithm should loop through all triples of elements of the list checking whether the sum of the first two is the third...
Having trouble coding this for C++. Please add comments for
better understanding!
Write a program that draws two triangles by using a character 'X' as examples below. The program must prompts a user for an integer larger than 2. The user input will then be used to set the size of the output. If a user input an even value, the program will increase it by one before drawing the box. Example 1: Input: 3 Output: XXX XXX XX XX...