1 give the big o for the followinga n2 6n 32b n 6c

Assignment Help JAVA Programming
Reference no: EM13381842

1) Give the Big O for the following:

a. n2 + 6n + 32

b. n +6

c. Analyze the code below for integer n:           

while (n > 0) {

   n = n/10; // Integer division

}

2) Explain in your own words - when is it appropriate to implement a static method? Give an example as part of your answer.

Answer: The best time to use a static method would be if a method needs to be in a class, but not  tied to an object: 
Example : class Languages {   public static void main(String[] args) {     display();  
 }     
static void display()      
 {     
System.out.println("Java is my favorite programming language.");   } 
}

3) Consider the following method with integer value x.

                  public static test(int x)

                               {

                               x += 2;

                               }

Suppose y has a value of 10, then the method is activated test(y) what is the value of y after this activation? The Value of Y will be 5.

4) Consider this code that creates some Location objects with coordinates x=10 and y=20:

                  Location a, b, c;

                  a = new Location(10,20);

                  b = new Location(10,20);

                  c = b;

                  ...

After this code executes, what are the values of these boolean expressions?

a) a= =b

b) a.equals(b)

c) a= =c

d) a.equals(c)

e) b= =c

f) b.equals(c)

Also, explain the difference between == and the equals method for the Location class.

5) Write a code fragment (in Java) that creates an array 50 integers, and initializes each cell to the same value as its index number (i.e. [0] = 0, [1] = 1, etc.).  [hint: use a loop]

6) What happens if you call new but the heap is out of memory?

7) Draw a picture of memory after these statements:

    int[ ] m = new int[2];

    m[0] = 0;

    m[1] = 1;

    int[ ] p = m;

    p[0] = 4;

    p[0] = 5

8) Consider the method:

                  public static test2(int[ ] b)

                  {

                               b[0]++;

                  }         

Draw a picture of memory after these statements (also show what is printed out)

                               int[ ] x = new int[100];

                               x[0] = 2;

                               foo(x);

                               System.out.println(x[0]);

9) Describe (in English) the steps for inserting a new item at the head of a linked list? Make sure you consider all possible incoming conditions.

10) Write out the following method as a static method for the IntNode class (similar to the book: use data & link) public static int count10s (IntNode head)

               // Precondition:  Head is a reference to a linked list of integers,

               // condition of the list is unknown (empty or not)

               // Postcondition: Method returns number of 10s found in the linked list.

               // list is unchanged.

11)  Write out the following method as a static method for the IntNode class (similar to the book:  use data & link)

public static void insertAtTail (IntNode head, int value)

            // Precondition:  Head is a reference to a linked list of integers,

// condition of the list is unknown (empty or not), int refers to value to be // added to the list at the END.

// Postcondition: List will have an additional node with the value placed in // it.

[Note] - break this into two parts - finding the right spot and then inserting.  The insert you already described up above - you just need to look for the last node; that node's link can be looked at as the "head" to your new node.  Don't forget to watch for empty case.

12)  The following is a code fragment used to count the # of occurrences of a specific "target" integer in an array.

         int i;

               int answer = 0;

               for (i = 0; i < data.length; i++)

               if (data[i] == target)

                  answer++;

Answer of course is the # of times the target is found in the array.  Rewrite the code so that it works correctly when the data array is an array of objects and target is a non-null reference to an object with an equals method.

13)  Suppose that the variable head is a reference to the head node of a linked list of objects. Each node has an instance variable called link (which is a reference to the next node) and another instance variable called data (which is an Object that's stored in the node). Write a few lines of code to count the number of occurrences of a specific non-null target Object on the list. At the end of your code, a variable called answer should indicate how many times the target appears in the array. Use target.equals to test for equality.

Reference no: EM13381842

Questions Cloud

Assume you are a consultant reporting to willis who charged : assume you are a consultant reporting to willis who charged you to examine the management issues facing blue sky
Part anbspnbspnbspnbspnbsp1 m mod nnbspnbsp will have : part anbspnbspnbspnbspnbsp1. m mod nnbspnbsp will have values ranging fromnbsp 0 to n.nbspnbspnbspnbspnbspt or f2. 42
What are the four types of business ownership describe each : what are the four types of business ownership? describe each of them your response should be at least 200 words in
Writing assignment identifying the hypothesisconsider a : writing assignment identifying the hypothesisconsider a social issue in which you are interested. it could be human
1 give the big o for the followinga n2 6n 32b n 6c : 1 give the big o for the followinga. n2 6n 32b. n 6c. analyze the code below for integer n
1outline andwrite a verbal presentation for one of the : 1.outline andwrite a verbal presentation for one of the benefits provided to you as a student at csu.your response
What was the main cultural and intellectual trends in the : what was the main cultural and intellectual trends in the interwar
Write a two to three 2-3 page paper in which you1 examine : write a two to three 2-3 page paper in which you1. examine the risks and explain how they were managed.2. compare the
1 suppose a banks balance sheet looks as : 1. suppose a banks balance sheet looks as followsnbspnbspnbspnbspassetsliabilitiesreservesnbspnbsp

Reviews

Write a Review

JAVA Programming Questions & Answers

  Study the code and implement the operator overloading

The Table Q3 on the next page is the code of a class named Circle. Study the code and implement the operator overloading for these relational operators ( , >=) for the Circle class. Then, write a test program that creates two instances of the Circle ..

  You must also do the work of sorting

You must also do the work of sorting in the method. You cannot just call another library method. Use loops to show the data in the original array as well as the repopulated array in ascending order.

  Critics of american often that teacher''s unions represent

Which organization has proposed a set of standards for both elementary level and secondary-level teachers? According to the latest info.,  teachers will be most needed in which of the following areas: Critics of American often argue that teacher's un..

  Record managing system application

Build a student record managing system application

  Write a reference class called ctatrain

writing a reference class that consist of the 2nd and 3rd instance variables below. my class should consist of an array of values in the 2nd instance variable

  Task 1university grading system maintains number of tables

task 1university grading system maintains number of tables to store retrieve and manipulate student marks. these tables

  Given an aerodynamic body you have learned in aerodynamics

given an aerodynamic body you have learned in aerodynamics and flight mechanics how to apply the numerical source panel

  Write a java program called salesinfominer

Write a Java program called SalesInfoMiner that reads in a file of products, stored in text format. The program must then read in information about past sales transactions and output all the products to a new file, sorted by product description,..

  Write a recursive function that finds and returns the sum

Write a recursive function that finds and returns the sum of the elements of an int array. Also, write a program to test your function.

  Find the solution of all these java question

find the solution of all these java question

  Write a method called add uneven arrays

Write a method called addUnevenArrays that takes two arrays, a and b, and returns a new array, c, with alength that is the maximum of the lengths of a and b. Each c[i] is the sum of the corresponding elementsof a and b if both elements exist.

  One-dimensional array to solve the

In C#, Use a one-dimensional array to solve the following problem. A company pays its salespeople on a commission basis. The salespeople each receive $200 per week plus 9 percent of their gross sales for that week. For example, a salesperson who gros..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd