Q1write a program called linearstringsearchjava that looks

Assignment Help JAVA Programming
Reference no: EM13351141

Q1.

Write a program called "LinearStringSearch.java" that looks for a target string value in an array of string values. Initialize the array with 10 random strings. The target string should be searched from the beginning of the array to the end of the array. Then, modify the algorithm so that after completing the first search from the beginning of the array to the end, a "second search" for the string in the array is conducted, except that the second search starts from the end of the array and moves towards the beginning of the array. 

Print on console, using the index of the target string, which of the two, the beginning-to-end or the end-to-beginning search, found the target string quicker. Ignore outcomes if the target string is not found in the array.  

Assuming that statistics on these two types of searches for the last 1000 runs are made available, discuss whether it is advantageous or not to use the statistics to opt one type of search over the other. For example, the statistics could indicate that out of 1000 search runs, 780 runs produced faster results when searching from end to beginning. Modify the program to include this particular functionality so that 

a)  the algorithm either searches beginning-to-end or end-to-beginning depending on this statistic 

b)  the algorithm updates the statistic using the outcome of the current search - that is, if the current search is faster for an end-to-beginning search, then increment the statistic by 1 to 781; else decrement the statistic by 1 to 779.

Q2.

Cattell-Horn-Carroll's theory attempts to measure intelligence quotient (IQ) in terms of the ten factors listed below. These ten factors take on different values. The IQ is calculated as a sum of the values of the ten factors. Write a Java program to input, calculate, and print the IQ of a person based on this theory. 

- Fluid intelligence (Gf): the broad ability to reason, form concepts, and solve problems using unfamiliar information or novel procedures. 

Input the Gf value interactively from the console. The value of Gf ranges from 1 to 15. 

- Crystallized intelligence (Gc): the breadth and depth of a person's acquired knowledge, the ability to communicate one's knowledge, and the ability to reason using previously learned experiences or procedures. 

Possible values of Gc are 'excellent', 'acceptable', and 'poor'. The value of Gc (excellent, acceptable, or poor) is known and should be encoded in the program by default. if excellent, gc contributes a value of 15 to iq; if acceptable, Gc contributes a value of 8 to IQ; and if poor, Gc contributes a value of 3 to IQ.

 - Quantitative reasoning (Gq): the ability to comprehend quantitative concepts and relationships and to manipulate numerical symbols. 

The value of Gq is 'true' or 'false', and is to be input interactively from the console. If true, Gq contributes a value of 10 to IQ; if false, Gq does not contribute to IQ at all.

- Reading and writing ability (Grw): basic reading and writing skills. 

Possible values of Grw are 'brilliant', 'good', 'normal', and 'poor'. The value of Grw is known and should be encoded in the program by default. If brilliant, Grw contributes a value of 15 to IQ; if good, Grw contributes a value of 10 to IQ; if normal, Grw contributes a value of 6 to IQ; if poor, Grw contributes a value of 2 to IQ. 

- Short-term memory (Gsm): the ability to apprehend and hold information in immediate awareness and then use it within a few seconds. 

Possible values of Gsm are 'good' and 'bad'. Input Gsm values interactively from the console. If good, Gsm contributes a value of 15 to IQ; if bad, Gsm contributes a value of 5 to IQ.

 - Long-term storage and retrieval (Glr): the ability to store information and fluently retrieve it later in the process of thinking. 

The values of Glr are in the range of 1 to 15. The value of Glr is known and should be encoded in the program by default. 

- Visual processing (Gv): the ability to perceive, analyze, synthesize, and think with visual patterns, including the ability to store and recall visual representations. 

The values of Gv are in the range of 1 to 10. The value of Gv is known and should be encoded in the program by default. 

- Auditory processing (Ga): the ability to analyze, synthesize, and discriminate auditory stimuli, including the ability to process and discriminate speech sounds that may be presented under distorted conditions. 

The values of Ga are in the range of 1 to 5. Input the Ga value interactively from the console.

 - Processing speed (Gs): the ability to perform automatic cognitive tasks, particularly when measured under pressure to maintain focused attention. 

Gs can be calculated as a relation to the person's age. The age should be input interactively from the console. The age is in the range from 21 to 75. Gs is calculated using the formulation [100 - age] / 10.

 - Decision/reaction time/speed (Gt): reflect the immediacy with which an individual can react to stimuli or a task. Gt is a function Gs and is calculated by the formula: [10 - Gs].

Q3.

An alternative to bubble sort is bi-directional bubble sort where the algorithm compares each adjacent pair of elements in the input array. The values are swapped as per the comparison function. Bi-directional bubble sort is also known as cocktail shaker sort, shaker sort, or double-direction bubble sort. Given below is a piece of implementation of the same.

public class ShakerSort {

   public static void ShakerSort(int[] a) {

      for (int p = 1; p <= a.length / 2; p++) {  // phase p of Shaker sort

         // first do left-to-right bubbling pass

         for (int i = p - 1; i < a.length - p; i++)

            if (a[i] < (a[i+1]))

               myswap(a, i, i + 1);

           // now do right-to-left bubbling pass

         for (int i = a.length - p - 1; i >= p; i--)

            if (a[i] < (a[i-1]) < 0)

               myswap(a, i, i - 1);

      }

   }

}

 Suppose we are to sort the elements [6,5,2,8,3,1]. The number of phases is computed as 3 (as per the code above). In the left to right bubbling pass of the first phase, the pair (6,5) is compared and swapped to get the array [5,6,2,8,3,1]. Next the pair (6,2) is compared and swapped to get [5,2,6,8,3,1]. The next comparison (6,8) causes no swap. When 8 and 3 are compared, a swap is done to get [5,2,6,3,8,1]. The final comparison of this pass is (8,1). Following the swap, we get [5,2,6,3,1,8]. Now the right-to-left pass begins. The pair (3,1) is compared first, a swap is done, and we get the array [5,2,6,1,3,8]. Next the pair (6,1) is compared, and we get [5,2,1,6,3,8]. At the end of the right-to-left pass we have [1,5,2,6,3,8]. Phase 2 works on the segment [5,2,6,3]. After the left-to-right pass, we have [2,5,3,6]; and after the right-to-left pass, we have [2,3,5,6]. The third phase works on the segment [3,5].

 Suppose we start with an array a[0: n-1] of elements to be sorted. After the left-to-right bubbling pass of phase 1, the largest element is in the rightmost position. So the right-to-left pass needs to be concerned only with elements in positions 0 through n-2 of the array. Following the right-to-left pass, the smallest element is in position 0 of the array.

Consequently, the next phase needs to be concerned only with the elements in positions 1 through n-2.

 In general, the left-to-right pass of phase p of shaker sort needs to be concerned only with elements in positions p-1 through n-p, and the right-to-left pass of this phase needs to be concerned only with elements in positions n-p-1 through p. 

Use the code given above to develop the program as "ShakerSort.java" and identify its complexity. Discuss its advantages compared to a regular bubble sort. What happens when n is odd?

Q4.

Implement the following application using a singly linked list. This application accepts from console and stores a list of 10 names (first name followed by last name) of your friends in the singly linked list. The order of arrival of these names determines the sequence of names in the linked list.

Implement a method that sorts the original sequence into a new sequence based on the alphabetical order of the last names. Modify the program using a doubly-linked list data structure, and add a method that searches for the first name of a friend.  

Finally, discuss what would happen when you link the last entry in the list with the first entry of the list.

Reference no: EM13351141

Questions Cloud

Risk management has become ever more important in planning : risk management has become ever more important in planning organizing and managing projects events and continuous
In this assignment you will be asked to implement a card : in this assignment you will be asked to implement a card game. you will need to make several design decisions for your
Prepare a web application and write the code also event : prepare a web application and write the code also event planning document base on below the codition.online
If you are using the blackboard mobile learn app please : if you are using the blackboard mobile learn app please click view in browser. technical project address bookthis
Q1write a program called linearstringsearchjava that looks : q1.write a program called linearstringsearch.java that looks for a target string value in an array of string values.
Part-1power and politics in your organisationthe historic : part-1power and politics in your organisationthe historic enron scandal of 2002 highlights the devastating effects of
Throughout the module you may participate in activities and : throughout the module you may participate in activities and complete assignments that will help prepare you to complete
An important role is played by development and training in : an important role is played by development and training in organizations effectiveness. this makes the process of
The business strategy game bsg is basically a pc-based : the business strategy game bsg is basically a pc-based approach devised to highlight the actual-world character of the

Reviews

Write a Review

JAVA Programming Questions & Answers

  Displays the number of days in a month

Create a program that displays the number of days in a month. Use a 12-element one-dimensional array to store the number of days in each month (use 28 for the number of days in February).

  Design and implementation of a hangman game

Design and Implementation of a Hangman game

  Class named stock to model a stock

Write a class named Stock to model a stock. The properties and methods of the class are shown in Figure 6.22. The metho changePercent computes the percentage of the change in the current vs. the previous closing price.

  Prepare executable program and a dictionary program

Prepare executable program and a dictionary Program.

  Write a functions that takes an array of doubles

1. Write a function that is passed a single integer and then calculates the factorial of that number. A factorial is the product of the integer times all of the integers below it stopping at 1. So n!= n*(n-1)*(n-2).......3.2.1

  Make a fourth button called special

Make a fourth button called "special" that does something else notdescribed in the assignment, such as change the background color.

  Java program to write-read data from user using i-o function

Write java program to write and read data from user using I/O functions. Describe class with data members name[20],emp_id,basic pay,net pay.calculate all the allowances.

  1 linked listsin this problem you will write a class that

1 linked listsin this problem you will write a class that implements an ordered list of strings. your class will able

  Program that uses random instead of scanner to play

Write a Java Program that uses Random instead of Scanner to play many rounds of Rock Paper Scissors. The user and computer will each randomly pick one and common rules of winning apply

  Socket programming in java tcpgoal in this project we will

socket programming in java tcpgoal in this project we will develop a web server in two steps. in the end you will have

  Ask the user to enter a positive non-zero integer value.

Write a program which aske the user to Enter a positve non-zero integer value. if the value enterd zero or negative print as error message and end the program; otherwise, use the integer to call a method displayPattern(n) which must display the follo..

  What is the average response time for this system?

A web server receives a request every 50ms and processes web requests every 8 ms. Using queuing theory, 1. What is the average response time for this system?

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