Question

#1. Using the definition of big-O, prove that f(x) = 5x^4+x^3+8x-2 . Show all work. #2....

#1. Using the definition of big-O, prove that f(x) = 5x^4+x^3+8x-2 . Show all work.

#2.

void bubbleSort(Student myClass[], int size) {
   int pass = 0;                            // counts each pass of the sort
   bool done = false;                       // whether sorted or not 

   // each pass puts one element into its sorted position,
   // smallest value bubbles to the top of the array
   while (!done) {
      done = true;                                 // possibly sorted

      // compare consecutive elements, swap if out of order
      for (int i = size-1; i > pass; i--) {
         if (myClass[i].id < myClass[i-1].id) {
            myswap(myClass[i], myClass[i-1]);
            done = false;                          // still not sorted
         }
      }
      pass++;
   }
}

Give an analysis of the running time (find a tight big-O) for the sort.

Give a brief written, more intuitive, explanation of the big-O answer.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1)
given f(x) = 5x^4+x^3+8x-2

By the definition of Big O, f(x) = O(g(x)) if there exists c and n0 such that c*g(x) >= f(n) and n>n0

We can write c*g(x) as 6x^4 which means
=> 6x^4 >= 5x^4+x^3+8x-2

=> Hence c = 6 , Hence f(x) = O(x4)

2)
Every time, we take two value and then we check if the value is smaller than its previous element, If Yes, then we swap the element
So it will move the lowest element at the beginning.

The Total time complexity is O(n2)

Thanks, PLEASE COMMENT if there is any concern.

Add a comment
Know the answer?
Add Answer to:
#1. Using the definition of big-O, prove that f(x) = 5x^4+x^3+8x-2 . Show all work. #2....
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • this is c code. please answer all questions on a piece of paper and show work....

    this is c code. please answer all questions on a piece of paper and show work. i need to prepare as i have a midterm i will have to be completing on paper 1) Bit Operators: This C program compiles and runs. What is its output? 1) #include <stdio.h> 2) void main (void) 3) unsigned char x =60; 4) 5) 6) 7) 8 ) 9) 10) 11) 12) 13) unsigned char a = x < 1; unsigned char b unsigned...

  • 1. [5 marks Show the following hold using the definition of Big Oh: a) 2 mark...

    1. [5 marks Show the following hold using the definition of Big Oh: a) 2 mark 1729 is O(1) b) 3 marks 2n2-4n -3 is O(n2) 2. [3 marks] Using the definition of Big-Oh, prove that 2n2(n 1) is not O(n2) 3. 6 marks Let f(n),g(n), h(n) be complexity functions. Using the definition of Big-Oh, prove the following two claims a) 3 marks Let k be a positive real constant and f(n) is O(g(n)), then k f(n) is O(g(n)) b)...

  • In below C++ sort.cpp 1- Implement the insertion_sort function. 2- Implement the compareSensorPtr function and the...

    In below C++ sort.cpp 1- Implement the insertion_sort function. 2- Implement the compareSensorPtr function and the code in main to create and sort the array of pointers. The places to make modifications are indicated by TODO: comments. You should not have to make modifications anywhere else. 3- what's big O and runtime for 100000 items. #include <iostream> #include <algorithm> #include <numeric> #include <vector> #include <string> #include <cstdlib> #include <cassert> using namespace std; // Set this to false to skip the...

  • Using Merge Sort: (In Java) (Please screenshot or copy your output file in the answer) In...

    Using Merge Sort: (In Java) (Please screenshot or copy your output file in the answer) In this project, we combine the concepts of Recursion and Merge Sorting. Please note that the focus of this project is on Merging and don't forget the following constraint: Programming Steps: 1) Create a class called Art that implements Comparable interface. 2) Read part of the file and use Merge Sort to sort the array of Art and then write them to a file. 3)...

  • This assignment is comprised of 3 parts: ​All files needed are located at the end of...

    This assignment is comprised of 3 parts: ​All files needed are located at the end of the directions. Part 1: Implementation of Dynamic Array, Stack, and Bag First, complete the Worksheets 14 (Dynamic Array), 15 (Dynamic Array Amortized Execution Time Analysis), 16 (Dynamic Array Stack), and 21 (Dynamic Array Bag). These worksheets will get you started on the implementations, but you will NOT turn them in. ​Do Not Worry about these, they are completed. Next, complete the dynamic array and...

  • These are my answere to the following questions: are they right? 1. B 2. T 3....

    These are my answere to the following questions: are they right? 1. B 2. T 3. T 4. T 5. F 6. T 7. A 8. D 9. E 10. B 11. B 12. A 13. A 14. D 15. C 16. D 17. T 18. C 19. T 20. T 21. T 22. A 23. T 24. D 25. B 26. A 27. A 28. A 29. T 30. C 31. D 32. A 33. T 34. F 35....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT