Data Structures and Algorithms in Java
Data Structures and Algorithms in Java
6th Edition
ISBN: 9781119278023
Author: Michael T. Goodrich; Roberto Tamassia; Michael H. Goldwasser
Publisher: Wiley Global Education US
bartleby

Videos

Expert Solution & Answer
Book Icon
Chapter 5, Problem 20C

Explanation of Solution

Recursive method to rearrange an array of integers:

Create the method rearrange() that accepts the input parameter as “a”, “start”, and “end” to rearrange the array integers that all even numbers appears before the odd numbers.

//Define the rearrange() method

public static int[] rearrange(int[] a, int start, int end)

{

  //Check whether "start" is equal to "end"

  if (start==end)

  //Return the array value

  return a;

/*Otherwise, check and rearrange odd number after the even number. */

  else

  {

  //Loop executes until length of array value

  for(int i=start; i<=end; i++)

  {

/*Check whether mod of array value by "2" is not equal to "0". */

  if(a[i]%2!=0)

  {

/*Call the swap() method to rearrange the array values. */

  swap(a, i, end);

  //Display the rearranged array values

  System.out.println(Arrays.toString(a));

/*Recursively call rearrange() method by passing the parameters of "a", "i", and "end-1" and then return it */

  return rearrange(a,i,end-1);

  }

  }

  }

/*Recursively call rearrange() method by passing the parameters of "a", "end", and "end" and then return it */

  return rearrange(a,end,end);

}

Create the method swap() that accepts the input parameter as “a”, “a1”, and “a2” to swap the array integers.

//Define the swap() method

private static void swap(int[] a, int a1, int a2)

{

/*Declare the temporary variable to hold the array value...

Blurred answer
Students have asked these similar questions
Don't use chatgpt or any other AI
Don't use chatgpt or any other AI
Given a relation schema R = (A, B, C, D, E,G) with a set of functional dependencies F {ABCD BC → DE B→ D D→ A}. (a) Show that R is not in BCNF using the functional dependency A → BCD. (b) Show that AG is a superkey for R (c) Compute a canonical cover Fc for the set of functional dependencies F. Show your work. (d) Give a 3NF decomposition of R based on the canonical cover found in (c). Show your work. (e) Give a BCNF decomposition of R using F. Show your work.
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:9781305503922
Author:Patrick M. Carey
Publisher:Cengage Learning
Introduction to Big O Notation and Time Complexity (Data Structures & Algorithms #7); Author: CS Dojo;https://www.youtube.com/watch?v=D6xkbGLQesk;License: Standard YouTube License, CC-BY