Question

In: Computer Science

1)If an algorithm performs N steps then we say it is O(N) ? 2) An example...

1)If an algorithm performs N steps then we say it is O(N) ?

2) An example of something that is O(N) is(chose one)

A)printing to the screen.B)executing a conditional statement. C) initializing an integer variable. D) looping through an array of size N.

3)Suppose we found the run time of an algorithm was O(2N3 + 4N2 + 5N + 3). What is the Big O notation for the algorithm?

A) O(5N), B) O(4N^2), C) O(N^3), D) O(2N^3)

Solutions

Expert Solution

PLEASE FIND THE ANSWER(S) and EXPLANATION BELOW.

          

  1. If any algorithm takes N steps, then we say that it has O(N) (TRUE.)
    • O(f(n)) is nothing but the number of steps taken to run the code.\
    • Here f(n) takes N steps, hence it is O(N)
  2. OPTION D
    • All the other like:
      • print data to screen takes a single step. O(1)
      • execute a conditional statement is also a single step. O(1)
      • Initializing an integer variable is also O(1)
      • looping through an array of size N. Hence, it is O(N)
  3. OPTION C
    • 2N3 + 4N2 + 5N + 3
    • <= 2N3 + 4N3 + 5N3 + 3N3
    • <=14N3
    • =O(N3)


Related Solutions

Algorithm problem 4 [3.1-4] Is (2^(n+1))∈O(2^n)? Is (2^(2n))∈O(2^n)?
Algorithm problem 4 [3.1-4] Is (2^(n+1))∈O(2^n)? Is (2^(2n))∈O(2^n)?
Suppose that we performed the algorithm SELECT whose running time is O(n) on 133 elements, and...
Suppose that we performed the algorithm SELECT whose running time is O(n) on 133 elements, and found the median of medians x by making groups of 5 elements. What is the maximum number of elements which are guaranteed to be greater than equals to x (without counting x, itself)?
Given an array A of n integers, describe an O(n log n) algorithm to decide if...
Given an array A of n integers, describe an O(n log n) algorithm to decide if the elements of A are all distinct. Why does your algorithm run in O(n log n) time?
1. When do we say an algorithm is optimal for a problem? Explain with a specific...
1. When do we say an algorithm is optimal for a problem? Explain with a specific problem and two concrete examples of algorithms, one of which is optimal and one which is not optimal for your chosen problem.
1. What is A-Star (A*) Algorithm in Artificial Intelligence? 2. A* Algorithm Steps 3. Why is...
1. What is A-Star (A*) Algorithm in Artificial Intelligence? 2. A* Algorithm Steps 3. Why is A* Search Algorithm Preferred? 4. A* and Its Basic Concepts 5. What is a Heuristic Function? 6. Admissibility of the Heuristic Function 7. Consistency of the Heuristic Function 8. Find an Implementation in Java, C or Python just choose in which programming language you prefer only select one.
Present an O(n) algorithm that sorts n positive integer numbers a1, a2, . . . ,...
Present an O(n) algorithm that sorts n positive integer numbers a1, a2, . . . , an which are known to be bounded by n 2 (so ai ≤ n 2 , for every i = 1, . . . , n. Use the idea of Radix Sort (discussed in class and presented in Section 8.3 in the textbook). Illustrate your algorithm by showing on paper similar to Fig. 8.3, page 198 in the textbook (make sure you indicate clearly...
Consider the problem of sorting an array A[1, ..., n] of integers. We presented an O(n...
Consider the problem of sorting an array A[1, ..., n] of integers. We presented an O(n log n)-time algorithm in class and, also, proved a lower bound of Ω(n log n) for any comparison-based algorithm. 2. Give an efficient sorting algorithm for an array C[1, ..., n] whose elements are taken from the set {1, 2, 3, 4, 5}.
Consider the problem of sorting an array A[1, ..., n] of integers. We presented an O(n...
Consider the problem of sorting an array A[1, ..., n] of integers. We presented an O(n log n)-time algorithm in class and, also, proved a lower bound of Ω(n log n) for any comparison-based algorithm. 3. Give an efficient sorting algorithm for an array D[1, ..., n] whose elements are distinct (D[i] ̸= D[j], for every i ̸= j ∈ {1, ..., n}) and are taken from the set {1, 2, ..., 2n}.
Consider the problem of sorting an array A[1, ..., n] of integers. We presented an O(n...
Consider the problem of sorting an array A[1, ..., n] of integers. We presented an O(n log n)-time algorithm in class and, also, proved a lower bound of Ω(n log n) for any comparison-based algorithm. 1. Give an efficient sorting algorithm for a boolean1 array B[1, ..., n]. 2. Give an efficient sorting algorithm for an array C[1,...,n] whose elements are taken from the set {1,2,3,4,5}. 3. Give an efficient sorting algorithm for an array D[1, ..., n] whose elements...
For Project 2, write a program for MIPS that performs the following steps. It 1. Receives...
For Project 2, write a program for MIPS that performs the following steps. It 1. Receives a string of upper- and/or lowercase letters from keyboard (user types the letters on the SPIM console window). 2. Stores ASCII codes of the letters in stack. 3. Stop receiving letters when ? is typed by the user. 4. Converts uppercase letters to their lowercase letters and vice versa, and prints the converted string on the SPIM console window. Assume only valid inputs are...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT