Question: In Java Lang Submit the code with comments: Estimating g(x) Given f(x) Counting Operations to Produce Polynomials Demonstrating If we can demonstrate this property by

In Java Lang

Submit the code with comments:

  • Estimating g(x) Given f(x)
  • Counting Operations to Produce Polynomials
  • Demonstrating In Java Lang Submit the code with comments: Estimating g(x) Given f(x)

Counting Operations to Produce Polynomials Demonstrating If we can demonstrate this property

If we can demonstrate this property by finding g(x) and a pair of witnesses c and k, then we have proven that our unknown function f(x) is a member of the set O(g(x)), where g(x) is a known reference function.

Reference Functions for g(x)

by finding g(x) and a pair of witnesses c and k, then

Countable Operations (Arithmetic, Relational, Logical, Assignment/Access)

we have proven that our unknown function f(x) is a member of

the set O(g(x)), where g(x) is a known reference function. Reference Functions

for g(x) Countable Operations (Arithmetic, Relational, Logical, Assignment/Access) {&,&&,|,||,!} {=,[ ]} Introduction{&,&&,|,||,!}

We are interested in recognizing a set of operations that can generalize{=,[ ]}

Introduction

We are interested in recognizing a set of operations that can generalize well to multiple different hardware platforms. These operations invoke the ALU inside of the CPU and represent a basic computational step in a traditional load-store architecture (ie, a Von Neumann architecture). Lets put this into practice and count the number of operations that occur in a basic for loop.

/ote that int a = 0; occurs only once throughout the loop execution for(int a = 0; a  

Note that we are not concerned with the exact number of operations above, but rather, how does the number of operations change as we change n? If we double the input size, does the operation count double? Does it quadruple? Or does it change in some other way? Perhaps as n increases the operation count doesnt change at all, as well see in the first code example below this is O(1). Well express the growth of the unknown function f(x) relative to functions we do know about, and try to get as close to f(x) as possible while also always being greater than f(x) past some value k.

Big O Reduction Rules

Asymptotic analysis is a useful tool for measuring complexity regardless of the specific hardware or platform being used. While a complex subject, there are a number of theorems that will help reduce the task of determining the reference function g(x) and the witnesses c and k. By making use of these reduction theorems, you can produce a polynomial for any arbitrarily complex code block. In general, well divide our code up into methods and examine those. These methods will provide terms that will contribute to our overall polynomial. Once weve produced a formula that corresponds to the code or method in question, well use the rules below to (1) reduce big o estimates and determine the most succinct g(x), c, and k.

  • Addition Rule: If a segment of code a(x) is represented by the sum of two disjoint code sections f(x) and g(x), then the O(a(x)) is equal to the larger of the two : O(f(x)) or O(g(x))
    • Specifically, well to multiple different hardware platforms. These operations invoke the ALU inside
    • In the example main below, foo() is of the CPU and represent a basic computational step in a traditional and bar() is , so main is load-store architecture (ie, a Von Neumann architecture). Lets put this into practice, and we can pick and count the number of operations that occur in a basic forto be loop. /ote that int a = 0; occurs only once throughout thecorrespondingly. (The loop execution for(int a = 0; a Note that we are not term becomes negligible as n moves to infinity, so the Big O is just the larger of the two terms.)
public static void main(String[] args) { foo(); //x^3 bar(); //x^2 } 
  • Product Rule: If a segment of code concerned with the exact number of operations above, but rather, how doesis represented by the product of two (nested) code sections the number of operations change as we change n? If we double and the input size, does the operation count double? Does it quadruple? Or), then the does it change in some other way? Perhaps as n increases theis equal to the product of the two: operation count doesnt change at all, as well see in the first
    • Specifically, code example below this is O(1). Well express the growth of theO(a(x)) = O(f(x) * g(x))
    • In the example main() below, the function foo() is called n times, and inside foo(), we iterate over each of the n items. So foo() is unknown function f(x) relative to functions we do know about, and tryO(n)and main calls foo() n times, resulting in to get as close to f(x) as possible while also always beingO(nn)==O(n2).
public static void main(String[] args) { for(int a = 0; a  
  • Log Exponent Rule: Consider the following logarithm greater than f(x) past some value k. Big O Reduction Rules Asymptotic. Note that we can rewrite this using the log roll asanalysis is a useful tool for measuring complexity regardless of the specific. Since constants are factored out during asymptotic analysis, you can simply drop the constant multiplier (which on a log is its exponent).
    • Example hardware or platform being used. While a complex subject, there are a
      • f(x) becomesnumber of theorems that will help reduce the task of determining the
  • Log Base Rule: You may omit the base of the log and assume its base-2.
  • Transitivity: if reference function g(x) and the witnesses c and k. By making use then of these reduction theorems, you can produce a polynomial for any arbitrarily. Related to big , if complex code block. In general, well divide our code up into methodsand Im trying to prove that a is less than or equal to (i.e, bounded by) and examine those. These methods will provide terms that will contribute to,we would writeour overall polynomial. Once weve produced a formula that corresponds to the and find some pair of code or method in question, well use the rules below to (1) such that this relationship holds. Using transitivity,
    • reduce big o estimates and determine the most succinct g(x), c, and
    • k. Addition Rule: If a segment of code a(x) is represented by
    • the sum of two disjoint code sections f(x) and g(x), then the
      • Now simply choose c ==8 and k==1

Estimating g(x) Given f(x)

In the following section, indicate what reference function O(a(x)) is equal to the larger of the two : O(f(x)) orwe should use when attempting to prove that O(g(x)) Specifically, In the example main below, foo() is and bar() is is , so main is , and we can pick to be correspondingly.. Use the rules and reference functions above to guide you.

  1. (The term becomes negligible as n moves to infinity, so the Big
  2. O is just the larger of the two terms.) public static void
  3. main(String[] args) { foo(); //x^3 bar(); //x^2 } Product Rule: If a
  4. segment of code is represented by the product of two (nested) code
  5. sections and ), then the is equal to the product of the
  6. two: Specifically, O(a(x)) = O(f(x) * g(x)) In the example main() below,

Counting Operations to Produce Polynomials

In the following section, I will present you with multiple different bodies of code, and it is your job to analyze each code section and build a polynomial that represents the number of abstract operations the code performs. Once were done here, well have built a polynomial that we will analyze further (in terms of the function foo() is called n times, and inside foo(), we iterate, c, and k) in the next section. For the following code segments below, count the operations and produce a corresponding polynomial representation.

over each of the n items. So foo() is O(n)and main calls

public static boolean isEmpty() { return head == null; } 

foo() n times, resulting in O(nn)==O(n2). public static void main(String[] args) {

public static int num_occurrences(int n) { int count = 0; for(int i = 0; i  

for(int a = 0; a Log Exponent Rule: Consider the following logarithm public static void c(int n) { //three loops for(int a = 0; a

. Note that we can rewrite this using the log roll as.

public static boolean isPrime(int n) { if(n == 1) return false; for(int i = 2; i  

Demonstrating | f(x) | k

For each of the polynomials above, pick a reference function Since constants are factored out during asymptotic analysis, you can simply drop and constants c,k such that the the constant multiplier (which on a log is its exponent). Example f(x) bounds becomes Log Base Rule: You may omit the base of the login the most succinct terms possible for Big O.

1. For the function isEmpty() above, what is ...

and assume its base-2. Transitivity: if then . Related to big ,

if and Im trying to prove that a is less than or=

equal to (i.e, bounded by) ,we would write and find some pair

of such that this relationship holds. Using transitivity, Now simply choose c

2. For the function num_occurences() above, what is...

==8 and k==1 Estimating g(x) Given f(x) In the following section, indicate=

what reference function we should use when attempting to prove that is=

. Use the rules and reference functions above to guide you. Counting

Operations to Produce Polynomials In the following section, I will present you

3. For the function c() above, what is...

with multiple different bodies of code, and it is your job to

analyze each code section and build a polynomial that represents the number=

of abstract operations the code performs. Once were done here, well have

built a polynomial that we will analyze further (in terms of ,

4. For the function isPrime() above, what is...

c, and k) in the next section. For the following code segments

below, count the operations and produce a corresponding polynomial representation. public static=

boolean isEmpty() { return head == null; } public static int num_occurrences(int

n) { int count = 0; for(int i = 0; i public

5. For your Bubble Sort, what is...

static void c(int n) { //three loops for(int a = 0; a

public static boolean isPrime(int n) { if(n == 1) return false; for(int=

i = 2; i Demonstrating | f(x) | k For each of

the polynomials above, pick a reference function and constants c,k such that

6. For your Selection Sort, what is...

the bounds in the most succinct terms possible for Big O. 1.

For the function isEmpty() above, what is ... = 2. For the=

function num_occurences() above, what is... = = 3. For the function c()

above, what is... = 4. For the function isPrime() above, what is...

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!