Question

In: Computer Science

1. Fill in the blanks by selecting the statements that can be true based on the...

1. Fill in the blanks by selecting the statements that can be true based on the statement in the first column.

g(n) grows slower than f(n)

g(n) grows the same rate as f(n)

g(n) grows faster than f(n)

f(n)=O(g(n))

f(n)=o(g(n))

f(n)=Ω(g(n))

f(n)=ω(g(n))

f(n)=θ(g(n))

2. Group the following functions f1, f2, …, f10 into different groups, so that functions within the same group grow at the same asymptotic rate. Also list groups in increasing asymptotic growth rate order. Note logn has base 10 and lgn has base 2.

f1

1 + 2 + 3 + … + (n-1) + n

f2

nlogn

f3

(lgn)*( lgn)

f4

1 + 2 + 4 + 8 + … + 2m (n=2m)

f5

2lgn + 100

f6

64n + 32

f7

2(2n)

f8

10logn + 3

f9

2n

f10

log(n!)

3. Provide best-case and worst-case running time and space complexity analysis in Big-Oh notation for sort method.

Big-O Notation

Brief Explanation

Best-Case Running Time

Worst-Case Running Time

Best-Case Space Complexity

Worst-Case Space Complexity

// assume input array has at least 2 elements

void sort(int[] arr) {

       int n = arr.length;

       boolean isOrdered = true;

       for (int i=0; i<n-1; i++) {

              if (arr[i] > arr[i+1]) {

                     isOrdered = false;

                     break;

              }

       }

      

       if (isOrdered) return;

      

       for (int i = 0; i < n - 1; i++) {

              for (int j = 0; j < n - i - 1; j++) {

                     if (arr[j] > arr[j + 1]) {

                           int temp = arr[j];

                           arr[j] = arr[j + 1];

                           arr[j + 1] = temp;

                     }

              }

       }

}

4. Provide best-case and worst-case running time and space complexity analysis in Big-Oh notation for the second method.

Big-O Notation

Brief Explanation

Best-Case Running Time

Worst-Case Running Time

Best-Case Space Complexity

Worst-Case Space Complexity

public static void genCode(int n, List<Integer> list, Random random) {

       int m = random.nextInt(100);

       if (m != 50 ) {

        if (n == 0) {

             return;

       } else {

              list.add(m);

             genCode(n-1, list, random);

       }

       }

}

public static void genCode(int n) {

    List<Integer> list = new LinkedList<Integer>();

    Random random = new Random();

    genCode(n, list, random);

}

Solutions

Expert Solution

Q1 solution

Gn grows slower than fn gn grows same as fn gn grows faster than fn
F(n)=O(g(n)) False true true
F(n)=o(g(n)) False false true
F(n)=omega(g(n)) True true false
F(n)=Omegaw(g(n)) True false false
F(n)=theta(g(n)) False true false

Q2 solution

F​​​​​​8>f5>f3>f9>f7>f10>f2>f1>f4

F8and f5 in one class

F3

F9,f7

F10,f2

F1

F4

Q4 solution

Big oh brief explanation
Best case Running time constant when m=50 on first call of function
Worst case Running time n recursive call n to 1 with m!=50 in all call.
Best case space complexity constant no additional space as returned on first call
Worst case space complexity constant O(n) n activation records for each recursive call

​​​

Q3 solution

big oh Brief explanation
Best case Running time n sorted list case
Worst case Running time n​​​​​​2 0ne element not in order
Best case space constant no additional space required
Worst case space constant

no additional space required


Related Solutions

Problem C. Fill True or False in the blanks for the following statements. True 1) _...
Problem C. Fill True or False in the blanks for the following statements. True 1) _ __ Operating system defines the ways in which the system resources are used to solve the computing problems of the users. 2) _ _ Operating system (OS) controls and coordinates use of hardware among various applications and users. 3) ______ System daemons are the first programs to be loaded and executed when powering-up or rebooting a computing system. 4) ______ When an OS runs...
Fill in the blanks with True (T) or False (F) for each of the given statements....
Fill in the blanks with True (T) or False (F) for each of the given statements. It is possible to directly form an acyl anion with an aldehyde and base. Electrophilic aromatic substitution is always faster with a heterocycle than with benzene. Pyridines are electron poor aromatic rings and are particularly good at nucleophilic aromatic substitution. Heterocyclopentadiene undergo electrophilic aromatic substitution primarily at the C-3 position. 1,3-diester is less acidic than a 1,3-ketoester, which is less acidic than an 1,3-diketone...
Fill in the blanks. Enter T for true and F for false about thefollowing statements...
Fill in the blanks. Enter T for true and F for false about the following statements regarding signature-based and anomaly-based intrusion detection systems.a)     (T/F)Signature-based detection is like anti-virus scanners and if a signature is not available then they will miss detecting the attack.b)     (T/F)Anomaly-based detection relies on statistics and artificial intelligence to characterize abnormal network traffic from normal traffic.c)     (T/F) If there is a real change in behavior of the traffic e.g. during final exams week there is a lot of network traffic...
Fill in the blanks in each of the following statements: 1. Each function definition can specify...
Fill in the blanks in each of the following statements: 1. Each function definition can specify __________________ that represent additional information the function requires to perform its task correctly. 2. Declaring data members with access modifier __________________ is known as information hiding. 3. The initial value of a string is the __________________which does not contain any characters. 4. Variables declared in the body of a particular function are known as __________________and can be used only in that function. 5. Each...
Fill in the blanks in each of the following statements
Fill in the blanks in each of the following statementsa) --------- allows you to build JavaFx GUIS using drag and drop techniques.b) The elements in the scene graph are called --------------c) A(n) ----------- file contains the description of a JavaFX GUI.d) The method ---------------- is called by FMXLLoader before the GUI is displayed
Fill in blanks and true or false 1.To start a corporation in the U.S., it is...
Fill in blanks and true or false 1.To start a corporation in the U.S., it is necessary to file an application in one of the states. The legal document that the state approves is the ____. 2.One of the advantages of the corporation form of business as opposed to a partnership form is the ease of transferring ____. 3.At a corporation, Assets minus Liabilities is____. 4.Shares of stock that have been issued and have not been reacquired by the issuing...
Use the mechanism below to fill in the blanks in the statements. Step 1 A +...
Use the mechanism below to fill in the blanks in the statements. Step 1 A + B → C Step 2 C + D → B + E Substance is a catalyst in this mechanism Substance is an intermediate in this mechanism
A language L is “NP-complete “if the following statements are true about L. Fill out blanks....
A language L is “NP-complete “if the following statements are true about L. Fill out blanks. L is ______________________________; For every language ? ′ in NP, there is a ______________________ reduction of _____________ to ___________.
Fill in the blanks to make the following statements correct. Please note that you can simply...
Fill in the blanks to make the following statements correct. Please note that you can simply write the words in your assignment response. The shut-down price is the price at which the firm can just cover its                   . If the average variable cost of producing any given level of output exceeds the price at which it can be sold, then the firm should                   . If a firm is producing a level of output such that MC > MR, that firm should                    output. The...
Fill in the blanks in each of the following statements: a) The _________ states that every...
Fill in the blanks in each of the following statements: a) The _________ states that every column in a primary key must have a value, and the value of the primary key must be unique b) The ________ states that every foreign-key value must appear as another table's primary-key value. c) A(n) ________ in a pattern indicates that a string matching the pattern can have zero or more characters at that location in the pattern. d) Java DB is the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT