Write a function that will have a list as an input, the task of the function is to check if all the elements in the list are unique,( i.e. no repetition of any value has occurred in the list), then the function returns true otherwise it returns false. Your program should include a main method that call the method to test it.
For the function you implemented in part 1, please calculate T(n), which represents the running time of your algorithm in terms of n. Where n is the length of the list. Then find the order of magnitude of your algorithm (Big O).
Please find another algorithm that solves part 1, write the code, calculate T(n) and find Big O. Then compare the efficiency with the algorithm from part1 to determine the more efficient one.
In: Computer Science
In: Computer Science
C Program: How do I write a Greedy function for 0-1 knapsack, to find total value only( replace struct Knapsack)
# include
#include
#include
struct Knapsack {
int value;
int weight;
};
// returns maximum of two integers
int max(int a, int b) { return (a > b)? a : b;
}
// Returns the maximum value that can be put in a
knapsack of capacity W
struct Knapsack knapSackExhaustive(int W, int wt[],
int val[], int n){
int i, w;
int K[n+1][W+1];
int totalWeight=0;
// Build table K[][] in bottom up manner
for (i = 0; i <= n; i++){
for (w = 0; w <= W; w++){
if (i==0 || w==0)
K[i][w] = 0;
else if (wt[i-1] <= w){
K[i][w] = max(val[i-1] +
K[i-1][w-wt[i-1]], K[i-1][w]);
}
else
K[i][w] = K[i-1][w];
}
}
//For calculation of totalweight;
int res = K[n][W];
w = W;
for (i = n; i > 0 && res > 0; i--)
{
// either the result comes from the top
// (K[i-1][w]) or from (val[i-1] + K[i-1]
// [w-wt[i-1]]) as in Knapsack table. If
// it comes from the latter one/ it means
// the item is included.
if (res == K[i - 1][w])
continue;
else {
// This item is included.
//printf("%d ", wt[i - 1]);
totalWeight=totalWeight+wt[i-1];
// Since this weight is included its
// value is deducted
res = res - val[i - 1];
w = w - wt[i - 1];
}
}
struct Knapsack knap;
knap.value=K[n][W];
knap.weight=totalWeight;
return knap;
}// end struct knapSackExhaustive
int main(void) {
struct Knapsack aSack;
int i;
time_t t;
int val[5];
int wt[5];
//Intializes random number generator
srand((unsigned) time(&t));
// Print 5 random values from 3 to 15
printf("Five Random Values:\n");
for( i = 0 ; i < 5 ; i++ ) {
val[i]=rand()%15+3;
printf("%d\n",val[i]);
}
int j;
//Print 5 random weights from 1 and 10000
printf("Five Random Weights:\n");
for( j = 0 ; j < 5 ; j++ ) {
wt[j]=rand() % 10000;
printf(" %d\n", wt[j]);
}
int W = 10000;
int n = sizeof(val)/sizeof(val[0]);
aSack = knapSackExhaustive(W, wt, val, n);
printf("Total Value: %d\t\n", aSack.value);
printf("Total Weight:%d\t",aSack.weight);
return 0;
}
In: Computer Science
Rewrite the attached mycat.c program in 3 using read, write, open and close (System I/O functions) instead of the standard I/O functions.
#include<stdio.h>
int main(int argc, char* argv[])
{
FILE *fp;
void filecopy(FILE *, FILE *);
if (argc == 1)
{
filecopy(stdin, stdout);
}
else
{
while(--argc >0)
{
if ((fp = fopen(*++argv, "r")) == NULL)
{
printf("cat: can not open %s\n", *argv);
return 1;
}
else
{
filecopy(fp, stdout);
fclose(fp);
}
}
}
return 0;
}
void filecopy(FILE *ifp, FILE *ofp)
{
int c;
while ((c = getc(ifp)) != EOF)
{
putc(c, ofp);
}
}
In: Computer Science
You will have to experiment with using chmod on the
folder and the file to come up with the following:
Find the chmod commands for both the folder and the file that you
would use to give the minimum permissions for You (the owner) to be
able to edit and change the file (and I don’t want to see 777! ? )
:
___________________________________________________________
___________________________________________________________
___________________________________________________________
In: Computer Science
in arduino, having two LED lights, I need to find a way to turn one LED with the push of a button, then with a next push of the button turn off the first LED and turn the second LED on. Help with the circuit and code would be appreciated.
In: Computer Science
Required Names:
StoreProgram
This project will be a program that provides information about inventory in a grocery store. Use this codeas your starting point. This code already has a main method written for you. DO NOT modify the main method. If you modify the main method, you will lose points.
In the main method, you will notice three arrays:
Here is the code as seen in the file:
String[] storeItems = {
"broccoli", "onion", "carrot", "turnip", "mango",
"bread", "garlic", "celery", "apple", "banana",
"raisins", "grapes", "lemon", "orange", "potato"
};
int[] itemQuantities = {
23, 5, 7, 15, 2,
13, 13, 8, 20, 30,
3, 25, 10, 9, 1
};
double[] itemPrices = {
2.0, 0.89, 0.70, 1.50, 2.99,
3.45, 1.45, 1.12, 3.99, 0.25,
4.99, 7.00, 1.75, 1.80, 3.25
};
Each array provides information about a specific item by index. This means that each index is specific for the item in the store. For example, notice that "carrot" is at index 2 in the storeItems array. This means that the quantity of carrots is also located at index 2in the itemQuantities array (which is 7), and the price of carrots is located at index 2 in the itemPrices array (which is 0.70).
For the purpose of this assignment, you can assume that the three arrays are always of equal length. This means that if you refer to the length property on any of them (for example, itemPrices.length), then the length will be the same for the other two arrays as well.
Instructions
Your program will need to have:
To help runTransaction run properly without making it too bulky, you will be required to implement the following methods as well. Each of these methods should have three parameters (the three arrays), and they should not return any values.
Pleases if I can get help today with how to do these steps of coding ?
In: Computer Science
- Read the below chapter and discuss in details (2-3 pages) using your own words about Cloud Security Concerns, Risk Issues, and Legal Aspects (use the below reference )
NOTE: please make sure that the answer is typing on the computer with font size 11pt
In: Computer Science
Please DO NOT copy-paste from other sources. answer will be checked for plagiarism. Thank you!!!
Question: Using a Web browser, perform some research on a newer malware variant that has been reported by a major malware containment vendor. Using a search engine, go to the vendor’s Web site; this could be Symantec, McAfee, or any of their competitors. Visit one malware prevention software vendor. Search for the newest malware variants and pick one. Note its name and try to understand how it works. Now look for information about that same malware from at least one other vendor. Were you able to see this malware at both vendors? If so, are there any differences in how they are reported between the two vendors?
In: Computer Science
write a Linear Search algorithm using sentinel approach? How can the sentinel linear search improve the performance over the standard linear search?
In: Computer Science
Using Excel to Calculate Factorials, Permutations, and Combinations
Using Excel to Calculate Factorials, Permutations and Combinations"
· In cell A1, compute 3 factorial
· In cell A2, calculate the number of permutations when selection 3 items from a total of ten items.
· In cell A3, calculate the number of combinations when selecting 3 items from a total of ten items.
In: Computer Science
What are the concurrency-control manager and recovery manager, respectively? What are their purpose?
In: Computer Science
In: Computer Science
Implementing a Stack
Write a program that implements a stack of integers, and exercises the stack based on commands read from cin. To do this, write a class called Stack with exactly the following members: class Stack { public: bool isEmpty(); // returns true if stack has no elements stored int top(); // returns element from top of the stack // throws runtime_error("stack is empty") int pop(); // returns element from top of the stack and removes it // throws runtime_error("stack is empty") void push(int); // puts a new element on top of the stack private: vector elements; }; The program should read commands from cin until either end-of-file is reached or the command end is entered. (You can manually test for end-of-file by entering CTRL-D.) Each time the program expects a new command it should first print a prompt: "stack> " Your program should catch all errors that happen and continue execution until the end command or end-of-file. In case the command push is read, the program should read an integer value from cin and push it onto the stack. In case top is read, the program should print the top integer of the stack to cout. In case pop is read, the program should print the top integer of the stack to cout, and remove it from the stack. In case the command list is read, the program should print all values currently on the stack, without modifying the stack. (Exact format see below.) Your program should check whether a "number" to be pushed is actually a number. If not, print an error message (see below), and reset cin such that it will again accept commands. (See Section 7.6 of the zyBook.) Also, your program should ignore all characters behind a number to be pushed that are on the same input line (example see below). An example of a correct execution of this program is shown below: stack> push 5 stack> pop 5 stack> pop error: stack is empty stack> push 6 stack> push 4bb stack> push foo error: not a number stack> list [4,6] stack> list [4,6] stack> top 4 stack> hello error: invalid command stack> end You may want to use the compare() function (Links to an external site.) on a string to check which command has been entered. Use of arrays, a built-in stack class, or container classes from std:: other than vector, is not allowed.
In: Computer Science
In: Computer Science