Question

Consider the following function: 01: void cpUniq (const int* source, int N, vector<int>& dest) 02: {...

Consider the following function:

01: void cpUniq (const int* source, int N, vector<int>& dest)
02: {
03:    list<int> L;  
04:    for (int i = 0; i < N; ++i)  
05:    {  
06:        copy (source, source + i, front_inserter<int>(L));  
07:    }  
08:    for (int j: L)  
09:    {  
10:        if (find(dest.begin(), dest.end(), j) != dest.end())  
11:         dest.push_back(j);  
12:    }  
13: }

and the following list of complexity values:

A: O(1), B: O(log N), C: O(N), D: O(N log N), E: O(N2), F: O(N3), G: O(N4)

For each of the ranges of line numbers below, enter the letter code (A-G) of the closest correct complexity for that range of lines or X if none of the options is correct.

Assume that dest is empty when the function is called.

Line 3:
Line 6:
Lines 4-7:
Line 11:
Line 10:
Lines 10-11:
Lines 8-12:
Lines 2-13:

Homework Answers

Answer #1


          

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
QUESTION 1 For the following recursive function, find f(5): int f(int n) { if (n ==...
QUESTION 1 For the following recursive function, find f(5): int f(int n) { if (n == 0)    return 0; else    return n * f(n - 1); } A. 120 B. 60 C. 1 D. 0 10 points    QUESTION 2 Which of the following statements could describe the general (recursive) case of a recursive algorithm? In the following recursive function, which line(s) represent the general (recursive) case? void PrintIt(int n ) // line 1 { // line 2...
Complete the following function (detailed instructions are given below the code): private static int predecessor(int array[],...
Complete the following function (detailed instructions are given below the code): private static int predecessor(int array[], int arrayLen, int key) { // Complete this function. } Given a set of numbers, the predecessor of a number x is the highest number in the set that is less than or equal to x. Thus, if I have the set {6; 9; 10; 13; 22; 31; 34; 88}, then the predecessor of 31 is 31 itself, whereas the predecessor of 30 is...
Consider the following function: double arrayavg(int a[], int n){ int sum=0; for(int i=0; i!=n; ++i){ sum+=a[i];...
Consider the following function: double arrayavg(int a[], int n){ int sum=0; for(int i=0; i!=n; ++i){ sum+=a[i]; } return (double)sum/n; } Rewrite the function to eliminate the array subscripting (a[i]), using pointer arithmatic instead. Write a program that reads a line of input and checks if it is a palindrome (ignoring spaces) Write a program that takes the name of a file as a command line argument, and prints the contents of the file (similar to the linux 'cat' program). Write...
Please answer the following C question: Read the following files called array-utils5A.c and array-utils5A.h. Build an...
Please answer the following C question: Read the following files called array-utils5A.c and array-utils5A.h. Build an executable with gcc -Wall -DUNIT_TESTS=1 array-utils5A.c The definitions for is_reverse_sorted and all_different are both defective. Rewrite the definitions so that they are correct. The definition for is_alternating is missing. Write a correct definition for that function, and add unit tests for it, using the unit tests for is_reverse_sorted and all_different as models. Please explain the logic errors present in in the definition of is_reverse_sorted...
Write a C++ program to demonstrate thread synchronization. Your main function should first create a file...
Write a C++ program to demonstrate thread synchronization. Your main function should first create a file called synch.txt. Then it will create two separate threads, Thread-A and Thread-B. Both threads will open synch.txt and write to it. Thread-A will write the numbers 1 - 26 twenty times in nested for loops then exit. In other words, print 1 - 26 over and over again on separate lines for at least 20 times. Thread-B will write the letters A - Z...
The program shown below reads in (N) values of time (hours, minutes, and seconds). If the...
The program shown below reads in (N) values of time (hours, minutes, and seconds). If the values for hours, minutes and seconds are a legal military time (i.e. 00 00 00 to 23 59 59) the program should display the formatted results (i.e. 12 34 56 should be displayed as 12:34:56). If there's an error for any of the entered values, an exception should be thrown and an error message should be displayed. Note, there are three exception conditions, one...
Convert the following C program to C++. More instructions follow the code. #include <stdio.h> #include <stdlib.h>...
Convert the following C program to C++. More instructions follow the code. #include <stdio.h> #include <stdlib.h> #define SIZE 5 int main(int argc, char *argv[]) {    int numerator = 25;    int denominator = 10;    int i = 0;    /*    You can assume the files opened correctly and the    correct number of of command-line arguments were    entered.    */    FILE * inPut = fopen(argv[1], "r");    FILE * outPut = fopen(argv[2], "w");    float result =...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g, char wordlist[][MAX_WORD_LENGTH], int numwords)] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) What int setup_game needs to do setup_game() does exactly what the name suggests. It sets up a new game of hangman. This means that it picks a random word from the supplied wordlist array and...
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 6    at assignment2.Client.readStudents(Client.java:64)    at assignment2.Client.main(Client.java:253) void readStudents() { //...
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 6    at assignment2.Client.readStudents(Client.java:64)    at assignment2.Client.main(Client.java:253) void readStudents() { // Scanner class object declare Scanner readStudentFile = null; // try block begin /*System.out.println("Working Directory = " + System.getProperty("user.dir")); // for debugging purposes only*/ try { // open file readStudentFile = new Scanner(new File("student.txt")); // loop until end of file while (readStudentFile.hasNextLine()) { String stu = readStudentFile.nextLine(); String[] eachStu; eachStu = stu.split(" "); String firstName = null, middleName = null, lastName = null; long id...
Please do the following in python: Write a program (twitter_sort.py) that merges and sorts two twitter...
Please do the following in python: Write a program (twitter_sort.py) that merges and sorts two twitter feeds. At a high level, your program is going to perform the following: Read in two files containing twitter feeds. Merge the twitter feeds in reverse chronological order (most recent first). Write the merged feeds to an output file. Provide some basic summary information about the files. The names of the files will be passed in to your program via command line arguments. Use...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT