
Concept explainers
Explanation of Solution
Recursive method to arrange the elements is less than or equal to “n”:
Create the method arrangingElements() that accepts the input parameter as “a”, “n”, “low”, and “high” to arrange the elements is less than or equal to “n” before any integer greater than “n” by calling this method recursively.
Method definition:
//Define the arrangingElements() method
public static void arrangingElements(int a[], int n, int low, int high)
{
//Check whether the "low" is greater than "high"
if(low > high)
{
/*Check whether the "low" is less than array length and "a[low]" is greater than "a[a.length-1]".*/
if(low < a.length && a[low] > a[a.length - 1])
{
/*Assign the "a[low]" value to temporary variable. */
int temp = a[low];
/*Assign the "a[a.length-1]" value to "a[low]". */
a[low] = a[a.length - 1];
//Assign the "temp" value to "a[a.length-1]"
a[a.length - 1] = temp;
}
//Return it
return;
}
/*Otherwise, call arragingElements() method recursively to arrange the elements is less than or equal to "n" before any integer greater than "n". */
else
{
//Check whether the "a[low]" is less than "n"
if(a[low] < n)
//Increment "low" by "1"
low++;
/*Otherwise, check whether "a[low]" is equal to "n". */
else if(a[low] == n)
{
/*Check whether "a[a.length-1]" is not equal to than "n". */
if(a[a.length - 1] != n)
{
/*Assign the "a[low]" value to temporary variable. */
int temp = a[low];
/*Assign the "a[a.length-1]" value to "a[low]". */
a[low] = a[a.length - 1];
/*Assign the "temp" value to "a[a.length-1]"> */
a[a.length - 1] = temp;
}
//Otherwise, increment "low" by "1"
else
low++;
}
//Otherwise, swap the array elements
else
{
/*Assign the "a[low]" value to temporary variable. */
int temp = a[low];
//Assign the "a[high]" value to "a[low]"
a[low] = a[high];
//Assign the "temp" value to "a[high]"
a[high] = temp;
//Decrement "high" by "1"
high--;
}
/*Call arrangingElements() method recursively to find the elements are less than or equal to "n". */
arrangingElements(a, n, low, high);
}
}
Explanation:
In the above code,
- In the arrangingElements() method,
- It accepts the input parameter as “a”, “n”, “low”, and “high”...

Want to see the full answer?
Check out a sample textbook solution
Chapter 5 Solutions
Data Structures and Algorithms in Java
- Show all the workarrow_forward[5 marks] Give a recursive definition for the language anb2n where n = 1, 2, 3, ... over the alphabet Ó={a, b}. 2) [12 marks] Consider the following languages over the alphabet ={a ,b}, (i) The language of all words that begin and end an a (ii) The language where every a in a word is immediately followed by at least one b. (a) Express each as a Regular Expression (b) Draw an FA for each language (c) For Language (i), draw a TG using at most 3 states (d) For Language (ii), construct a CFG.arrow_forwardQuestion 1 Generate a random sample of standard lognormal data (rlnorm()) for sample size n = 100. Construct histogram estimates of density for this sample using Sturges’ Rule, Scott’s Normal Reference Rule, and the FD Rule. Question 2 Construct a frequency polygon density estimate for the sample in Question 1, using bin width determined by Sturges’ Rule.arrow_forward
- Generate a random sample of standard lognormal data (rlnorm()) for sample size n = 100. Construct histogram estimates of density for this sample using Sturges’ Rule, Scott’s Normal Reference Rule, and the FD Rule.arrow_forwardCan I get help with this case please, thank youarrow_forwardI need help to solve the following, thank youarrow_forward
- reminder it an exercice not a grading work GETTING STARTED Open the file SC_EX19_EOM2-1_FirstLastNamexlsx, available for download from the SAM website. Save the file as SC_EX19_EOM2-1_FirstLastNamexlsx by changing the “1” to a “2”. If you do not see the .xlsx file extension in the Save As dialog box, do not type it. The program will add the file extension for you automatically. With the file SC_EX19_EOM2-1_FirstLastNamexlsx still open, ensure that your first and last name is displayed in cell B6 of the Documentation sheet. If cell B6 does not display your name, delete the file and download a new copy from the SAM website. Brad Kauffman is the senior director of projects for Rivera Engineering in Miami, Florida. The company performs engineering projects for public utilities and energy companies. Brad has started to create an Excel workbook to track estimated and actual hours and billing amounts for each project. He asks you to format the workbook to make the…arrow_forwardNeed help completing this algorithm here in coding! 2arrow_forwardWhats wrong the pseudocode here??arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageNew Perspectives on HTML5, CSS3, and JavaScriptComputer ScienceISBN:9781305503922Author:Patrick M. CareyPublisher:Cengage Learning
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage LearningSystems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage Learning




