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
An array of 100 elements is to be sorted using the bubble sort in the modules (the one that tests...
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 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...
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, 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 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 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. 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 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. 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 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...