Data structures and algorithms

Assignment Help JAVA Programming
Reference no: EM131124

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: EM131124

Questions Cloud

Love canal case : The report analyzes the Love Canal disaster case of in Niagara Falls,
Role of the government in the financial markets : Write a Term paper on role of the government in the financial markets
Principles and tools for financial decision-making : Principles and tools for financial decision-making. Analyse the concept of corporate capital structure and compute cost of capital.
Materials and processes in design : A modern new building project by an architectural consultancy requires that the interior contains some product designs. The building is an information centre that also houses a restaurant and a cafeteria. Most importantly, the consultancy wants yo..
Data structures and algorithms : Code analysis and programming.
Engineering ethics concepts and cases : Engineering ethics concepts and cases
Case study- hartford penn-cann service, inc : Hartford Penn-Cann Service, Inc., operated a gas station, restaurant, and truck wash directly across the highway from a gas station and truck stop operated under the name "Hartford 65."
Abafm landscaping corporation prototype : The ABAFM (First Letter of all Group Member's Names) Landscaping Corporation is situated at 1 Park Place Drive Markham, Ontario. It was assimilated in Ontario in the year of 2012. Currently there are 10 full-time and 10  part-time/seasonal employees...
Abafm landscaping corporation prototype : The ABAFM (First Letter of all Group Member's Names) Landscaping Corporation is situated at 1 Park Place Drive Markham, Ontario. It was assimilated in Ontario in the year of 2012. Currently there are 10 full-time and 10  part-time/seasonal employees...

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Build the gui layout of the game

Build the Build the GUI layout of the game in java.

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Develop a reliable transfer protocol over udp

Develop a reliable transfer protocol over UDP. Focus on a Stop- and-Wait protocol.

  Create classes implement java interface

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

  Socket programming in java: tcp

In this project we will develop a Web server in two steps. In the end, you will have built a multi-threaded Web server that is capable of processing multiple simultaneous service requests in parallel.

  Determine if strings are equal

Complete the recursive method match in the code below which will determine whether or not two strings match.

  Implement avl tree

Implement AVL trees that allows both iterative traversal and recursive traversal.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Write a recursive instance method

Write a recursive instance method

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