1 what makes a program easy to modify2 describe the order

Assignment Help JAVA Programming
Reference no: EM13347205

1. What makes a program easy to modify?

2. Describe the order of magnitude of the following code section using Big(O) notation.

j = 1;

While (j < N)

{

  j = j * 2);

}

3. What are the benefits we accrue by using a Java interface construct to formally specify the logical level of ADTs?

4. Suppose we have a linked list of Strings, as defined in the textbook, named presidents. Suppose it contains three nodes, with the first node holding "Adams", the second node "Washington", and the third node "Kennedy". What would be output by the following code:

LLStringNode temp = presidents;

while (temp != null)

{

temp = temp.getLink();

}

System.out.println(temp.getInfo());

5. Suppose a collection object is defined to hold elements of class Object, and you use it to store String objects. Describe what you must do when you retrieve an object from the collection and intend to use it as a String.

6. Show what is written by the following segment of code, given that item1, item2, and item3 are int variables, and stack is an object that fits our abstract description of a stack. Assume that you can store and retrieve variables of type int on stack.

item1 = 1;

item2 = 0;

item3 = 4;

stack.push(item2);

stack.push(item1);

stack.push(item1 + item3);

item2 = stack.top();

stack.push (item3*item3);

stack.push(item2);

stack.push(3);

item1 = stack.top();

stack.pop();

System.out.println(item1 + " " + item2 + " " + item3);

while (!stack.isEmpty())

{

  item1 = stack.top();

stack.pop();

System.out.println(item1);

}

7. Explain the relationship between dynamic storage allocation and recursion.

8. Analyze the factorial method and answer the following questions:

int factorial (int n)

{

if (n > 0)

return (n * factorial (n - 1));

else

if (n == 0)

return 1;

}

a. What is the base case?

b. What is the general case?

c. What are the constraints on the argument values?

d. What does the method do?

9. What are the three interfaces we defined related to our Queue ADT?

10. Describe in general terms the approach we use to implement an unbounded queue based on an array.

11.  What does it mean for a class's equals and compareTo methods to be "consistent"?

12.  Questions a-e below refer to the following figure:

464_Code analysis and programming..png

a. What are the ancestors of node J?

b. What are the descendants of node T?

c. What are the descendants of node B?

d. What is the order in which the nodes are visited by a preorder traversal?

e. What is the order in which the nodes are visited by a postorder traversal?

13.  If a heap is used to implement a priority queue, what is the big O efficiency of the enqueue operation, assuming the size of the priority queue is N?

14.  What would be the order of the following list after two iterations of the "inner" part of the Insertion Sort algorithm?

13         4          16         19         2          15         12         3          23         20

15.  Suppose we are using Merge Sort to sort the following list of numbers. What would be the order of the list immediately before the execution of the merge method in the original (non-recursive) call to mergesort?

13         4          16         19         2          15         12         3          23         20

16.  Programming Sorting Algorithms: For this section, use the Sorts.java test harness.

a. Describe an approach to modifying the Sorts.java program so that after calling a sorting method the program prints out the number of swaps needed by the sorting method.

b. Implement your approach.

c. Test your new program by running the selectionSort method. Your program should report 49 swaps.

d. Now, modify your program to also output the number of comparisons (compares) needed. You must include one or more statements to increment your counter within the sorting methods themselves. For each of the listed methods, make and test the changes needed, and list both the number of swaps and the number of compares needed by the Sorts program to sort an array of 50 random integers.

selectionSort     swaps:____       compares:____

bubbleSort        swaps:____       compares:____

shortBubble      swaps:____       compares:____

insertionSort     swaps:____       compares:____

Reference no: EM13347205

Questions Cloud

Executive summary the report analyzes the love canal : executive summary the report analyzes the love canal disaster case of in niagara falls new york. love canal used by the
Assignment write a term paper on role of the government in : assignment write a term paper on role of the government in the financial markets or analysis of the federal
Part a dividend policy morning star conducted a search to : part a dividend policy morning star conducted a search to reveal the top dividend-paying stocks on the ftse 350. the
A three designs a modern new building project by an : a three designs a modern new building project by an architectural consultancy requires that the interior contains some
1 what makes a program easy to modify2 describe the order : 1. what makes a program easy to modify?2. describe the order of magnitude of the following code section using bigo
Engineering ethics course where we have to select a case : engineering ethics course where we have to select a case related to civil engineering with reference to it and discuss
1the smiths purchased a new home from jc construction in : 1.the smiths purchased a new home from jc construction in sunnyvale subdivision. they signed a standard purchase
Servicesfollowing are the services which are delivered by : servicesfollowing are the services which are delivered by abafm landscaping corporationlandscape design and
Servicesfollowing are the services which are delivered by : servicesfollowing are the services which are delivered by abafm landscaping corporationlandscape design and

Reviews

Write a Review

JAVA Programming Questions & Answers

  Method splitstack that takes a stack

Write a method splitStack that takes a stack of integers as a parameter and splits it into negatives and non-negatives. The numbers in the stack should be rearranged so that all the negatives appear on the bottom of the stack and all the non-negat..

  Write a program in java that reads contents of two vectors

Write a program in Java that reads contents of two vectors, and then displays the sum of these two vectors. The program should prompt the user to enter the size of the vectors first.

  Write a program that takes as input student scores

Write a program that takes as input student scores from a file and outputs the average for each student to a file.

  A jsp expression can contain any java expression

A JSP expression can contain any Java expression that evaluates to a

  Demonstrates conditions under which the compareto() method

Write an application that demonstrates conditions under which the compareTo() method retrun a positive number, a negative number, and a zero when used to compare two Strings, Save the file as CompareStringValues.java. Lab Assignment

  Solution for the problem and mention algorithms

Explain the purpose of the program as detail as possible and develop a solution for the problem and mention algorithms to be used and list data structures to be used in solution.

  Writing a program to have it generate random words

How would I go about writing a program to have it generate random words with a letter missing for a child to guess? Maybe it would have three letters, then four, next five, and so on until maybe 10 letters. Please keep in mind that I'd like it to wor..

  Write java program to display results in java applet

Write down the java program which displays following results in java applet. Permits the user to enter three numbers (use JOptionPane for this) and prints out average of those value on screen.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Information from the user and prints a payroll statement

Write a program that accepts the following information from the user and prints a payroll statement

  The frantic pipe layer game

Design the Frantic Pipe Layer game

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

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