Question

An array of 100 elements is to be sorted using the bubble sort in the modules (the one that tests the return value of floatLaAssume you are working inside the method definition of some instance method of lass B you are writing the statements that defWhich diagram best describes the idea of different derived classes inheriting from the same base class in Java? BaSC DerivediMatch each data structure with its best description. Data is a LIFO: There is only one data item that is naturally fetched (rConsider the following statement: FileInputStream galSource- new FileInputStream(GalaxyData.txt Check the true statements (t

An array of 100 elements is to be sorted using the bubble sort in the modules (the one that tests the return value of floatLargestToTop0 to see if it can return "early".) Check all the true statements about the sort algorithm, i.e., the sort method and its support methods. (Check all that apply.) It will sometimes return (completely sorted) after only 99 data comparisons. It will always require at least one swap. It will always require at least 99 comparisons It will always return (completely sorted) after 99 data comparisons
Assume you are working inside the method definition of some instance method of lass B you are writing the statements that define this method. In order to call an instance method of a class A from inside this instance method of a class B (where B and A are unrelated by inheritance to one-another), you: O must use an object of a third class, a base class of both class A and class B, for dereferencing. O can call the method without any object used for dereferencing. . must use an object of class A for dereferencing the method cal. must use an object of class B for dereferencing the method call
Which diagram best describes the idea of different derived classes inheriting from the same base class in Java? BaSC Derivedi Derived2 Basel Base2 Derived
Match each data structure with its best description. Data is a LIFO: There is only one data item that is naturally fetched (returned) to the client at any given moment, and it is the item most recently stored Queue Data is both LIFO and FIFO: The are potentially two data items that could be naturally fetched (returned) to the client at any given moment, either the the item Stack Data is neither LIFO nor FIFO: Client can naturally fetch (return) any of the many data items stored. Array Data is a FIFO: There is only one data item that is naturally fetched (returned) to the client at any given moment, and it is the oldest (earliest) item stored Deque
Consider the following statement: FileInputStream galSource- new FileInputStream("GalaxyData.txt Check the true statements (there may be more than one) If the file GalaxyData.txt could not be opened for some reason, a FileNotFoundException would be thrown which our client could try and catch. It attempts to open a file named 'GalaxyData.txt for writing/output It attempts to open a file named "galSource" for reading/input О lt attempts to open a file named "GalaxyData.txt' for reading/input. If GalaxyData.txt is successfully opened, then we could use the statement val- myFilein.read) to read a byte from it. O If the file is successfully opened and we read to the very end, the next time we try to read, using val-myFiiein.readO read0 would throw an exception.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

1) Bubble sort has to compare all the elements once to check if they are sorted.

So the answer is it will sometimes return completely sorted array in 99 comparisons. It will always require atleast 99 comparisons.

Bubble sort will keep comparing adjacent elements in the n iterations, n here is 100. Assuming array is already sorted, minimum number of comparisons required is 99 in the first iteration. If no swap occurs we know array is already sorted so it requires atleast 99 comparisons. If the array is already sorted, it will in such cases return completely sorted array in first iteration itself.

It always requires 1 swap is false, if array is sorted no swaps occur

2) The two classes are unrelated by inheritance, unless the method you want to call is static, object is needed to deference the method.

You must use an object of class A for dereferencing the method call.

3) Base class is one and derived classes are many as per the question. So the correct answer is first figure

base class

/ \

derived 1 derived2

4) LIFO - Last in first out

FIFO - first in first out

LIFO structure is stack where push and pop occur from same side

LIFO and FIFO is deque. Double sided queue where push pop occurs from both sides of data structure

Neither LIFO or FIFO is array, you could access any element of array anytime.

FIFO is queue where insert occurs at one end and removal at other end

5) FileInputStream class is used to read a file so the operation is taking input from file. File name is passed to the constructor. If the file doesn't exist it will throw file not found exception.

If "GalaxyData.txt" is opened successfully you could use read method to read a byte but it should be called from the object of FileInputStream which is galSource.read() in this case.

Same is the case with last option, If called from the file object galSource it would give exception at the end as there is no more data to be read.

So the correct answers is option a) throws an exception that can be put in try catch block,

d) it attempts to open a file named "GalaxyData.txt" for reading/input

Add a comment
Know the answer?
Add Answer to:
An array of 100 elements is to be sorted using the bubble sort in the modules (the one that tests...
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
  • Chapter 4 describes the ADT Sorted List using an array implementation with a maximum of 25...

    Chapter 4 describes the ADT Sorted List using an array implementation with a maximum of 25 items. The pseudocode for the ADT Sorted List Operations are provided on page 210. Use this information to create an ADT for handling a collection of Person objects, where each object will contain a Social Insurance Number (validate this), a first name, a last name, a gender and a data of birth. This implementation should prevent duplicate entries – that is, the Social Insurance...

  • Program with generic merge sort and binary search method help. The programming language I'm using is...

    Program with generic merge sort and binary search method help. The programming language I'm using is Java. This program should show understanding generic merge sort methods and generic binary search methods in java. The execution should include at least 5 found items including one from the first three items in the sorted array and one from the last three items in the sorted array as well as at least two items not found Create a generic merge sort method that...

  • Java Object Array With 2 Elements In 1 Object

    1. Create a UML diagram to help design the class described in Q2 below. Do this exercise before you attempt to code the solution. Think about what instance variables will be required to describe a Person class object; should they be private or public? Determine what class methods are required; should they be private or public?2. Write Java code for a Person class. A Person has a name of type String and an age of type integer.Supply two constructors: one will be...

  • #include <stdio.h> // Define other functions here to process the filled array: average, max, min, sort,...

    #include <stdio.h> // Define other functions here to process the filled array: average, max, min, sort, search // Define computeAvg here // Define findMax here // Define findMin here // Define selectionSort here ( copy from zyBooks 11.6.1 ) // Define binarySearch here int main(void) { // Declare variables FILE* inFile = NULL; // File pointer int singleNum; // Data value read from file int valuesRead; // Number of data values read in by fscanf int counter=0; // Counter of...

  • DI Question 2 1.5 pts Which situations allow the client main() in the file my_program.py to access a method name, say f...

    DI Question 2 1.5 pts Which situations allow the client main() in the file my_program.py to access a method name, say func(), alone, as in x-func) without dereferencing it using prepended name like modname.func or x = some object. func () or x-SomeClass.func() O func) is defined in some module, say, "modname.py" and modname is imported into my_program.py using: from modname import func() is an instance method or a class method in a class, say SomeClass, defined in the same...

  • In Java(using BlueJ) Purpose Purpose is to practice using file input and output, and array list...

    In Java(using BlueJ) Purpose Purpose is to practice using file input and output, and array list of objects. Also, this lab specification tells you only what to do, you now have more responsibility to design how to do it. Problem description You are given a text file called 'Students.txt' that contains information on many students. Your program reads the file, creating many Student objects, all of which will be stored into an array list of Student objects, in the Students...

  • Modify the sorts (selection sort, insertion sort, bubble sort, quick sort, and merge sort) by adding code to each to tally the total number of comparisons and total execution time of each algorithm. E...

    Modify the sorts (selection sort, insertion sort, bubble sort, quick sort, and merge sort) by adding code to each to tally the total number of comparisons and total execution time of each algorithm. Execute the sort algorithms against the same list, recording information for the total number of comparisons and total execution time for each algorithm. Try several different lists, including at least one that is already in sorted order. ---------------------------------------------------------------------------------------------------------------- /** * Sorting demonstrates sorting and searching on an...

  • In Java(using BlueJ) Purpose Purpose is to practice using file input and output, and array list of objects. Also, this lab specification tells you only what to do, you now have more responsibility to...

    In Java(using BlueJ) Purpose Purpose is to practice using file input and output, and array list of objects. Also, this lab specification tells you only what to do, you now have more responsibility to design how to do it. Problem description You are given a text file called 'Students.txt' that contains information on many students. Your program reads the file, creating many Student objects, all of which will be stored into an array list of Student objects, in the Students...

  • Can someone help me with the main class of my code. Here is the assignment notes....

    Can someone help me with the main class of my code. Here is the assignment notes. Implement project assignment �1� at the end of chapter 18 on page 545 in the textbook. Use the definition shown below for the "jumpSearch" method of the SkipSearch class. Notice that the method is delcared static. Therefore, you do not need to create a new instance of the object before the method is called. Simply use "SkipSearch.jumpSearch(...)" with the appropriate 4 parameter values. When...

  • Please try to write the code with Project 1,2 and 3 in mind. And use java language, thank you very much. Create an Edit Menu in your GUI Add a second menu to the GUI called Edit which will have one me...

    Please try to write the code with Project 1,2 and 3 in mind. And use java language, thank you very much. Create an Edit Menu in your GUI Add a second menu to the GUI called Edit which will have one menu item called Search. Clicking on search should prompt the user using a JOptionPane input dialog to enter a car make. The GUI should then display only cars of that make. You will need to write a second menu...

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