1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Bingel [31]
3 years ago
6

A 'array palindrome' is an array which, when its elements are reversed, remains the same (i.e., the elements of the array are sa

me when scanned forward or backward) Write a recursive, boolean-valued method, isPalindrome, that accepts an integer-valued array, and a pair of integers representing the starting and ending indexes of the portion of the array to be tested for being a palindrome. The function returns whether that portion of the array is a palindrome. An array is a palindrome if: the array is empty (0 elements) or contains only one element (which therefore is the same when reversed), or the first and last elements of the array are the same, and the rest of the array (i.e., the second through next-to-last elements) form a palindrome.

Computers and Technology
1 answer:
tia_tia [17]3 years ago
8 0

Answer:

Here is the JAVA program:

class Main {    

static boolean isPalindrome(int array[], int starting, int ending) {  /*a boolean method that takes an integer-valued array, and a pair of integers representing the starting and ending indexes of the portion of the array to be tested for being a palindrome */

   if (starting >= ending) {  //base case

       return true;     }  //returns true

   if (array[starting] == array[ending]) {  //recursive case

       return isPalindrome(array, starting + 1, ending - 1);     }  //calls isPalindrome recursively to find out palindrome

   else {  

       return false;    }  }  //returns false if array is not palindrome

 

   public static void main (String[] args) {  //start of main function

   int array[] = { 1,2,3,2,1};  //creates an array

   int size = array.length;   //computes the size of array

 System.out.print(isPalindrome(array, 0, size - 1));    } } //calls method to test array for being  a palindrome

Explanation:

The program works as follows:

array = { 1,2,3,2,1}

starting = 0

ending = size-1 = 5-1 = 4

if (starting >= ending) condition evaluates to false because starting i.e. 0 is not greater or equal to ending i.e. 4. So the program moves to the next if part

if (array[starting] == array[ending])

This becomes:

if (array[0] == array[4])

The element at 0th index is the first element of the array i.e. 1 and the element at 4th index of array is the last element of array i.e. 1. So both these elements are equal so the following statement executes:

return isPalindrome(array, starting + 1, ending - 1);

Now the starting and ending become:

starting+1 = 0+1 = 1

ending-1 = 3

if (starting >= ending) base condition evaluates to false because starting  is not greater or equal to ending. So the program moves to the next if part

if (array[starting] == array[ending])

This becomes:

if (array[1] == array[3])

The element at 1st index is 2 and the element at 3rd index of array is 2. So both these elements are equal so the following statement executes:

return isPalindrome(array, starting + 1, ending - 1);

Now the starting and ending become:

starting+1 = 1+1 = 2

ending-1 = 2

if (starting >= ending) base condition evaluates to true because starting  is  equal to ending. So the following statement executes:

       return true;    

This means the function returns true and this shows that array is a palindrome.

The screenshot of the program and its output is attached.

You might be interested in
How does a junction table handle a many-to-many relationship?
faltersainse [42]

Answer:

two" (and any subsequent words) was ignored because we limit queries to 32 words.

Explanation:

please mark as brainliest

7 0
3 years ago
Paragraph talking about why i chose bill gates
AlekseyPX

Answer:

Bill Gates

Explanation:

Bill Gates is known as one of the richest entrepreneurs in the world. He is responsible for creating the largest computer and technology business in the world, Microsoft. In the company's early days, no one would have thought that it would change both America and the world from that point on.

When Gates first created Microsoft,

Middle class Americans could now purchase a personal computer that would not put a set back in their bank account.As soon as personal computers started hitting the mainstream market, the demand for improvement began. People wanted their machines to boot up faster, have larger memory, have improved programming, and be easier to use. Luckily Gates already knew the people would have these needs, so development was already underway.

7 0
3 years ago
Cual es el procedimientos para asistir en el transporte publico a personas discapacitadas
artcher [175]

Answer:

Una discapacidad física o motora en una o más partes del cuerpo obstaculiza las acciones y / o movimientos de la persona con discapacidad. La discapacidad puede surgir porque las partes del cuerpo no han crecido completamente o están dañadas (anomalías físicas) o porque las funciones físicas están alteradas (anomalías funcionales).

En la mayoría de los casos, se proporciona una ayuda a las personas con discapacidades físicas graves para que puedan desenvolverse más fácilmente en la sociedad. Alguien con una discapacidad motora severa en las piernas a menudo usa una silla de ruedas. Las personas con una discapacidad motora de las manos (pérdida de la motricidad fina) o de los brazos pueden compensar esto con un manipulador o ayudas especializadas en tareas, como un dispositivo para comer o un dispositivo para girar las hojas.

Así, todos estos elementos deben ser posibles de ser insertados en los medios de transporte público como forma de ayudar a estas personas a trasladarse por estos medios, es decir, los autobuses, trenes, etc., deben estar adaptados para poder recibir allí a pasajeros en sillas de ruedas o con necesidades motoras especiales.

7 0
2 years ago
Which of the following statements is true of infrastructure?
bazaltina [42]

Answer:

Examples of infrastructure include transportation systems, communication networks, sewage, water, and electric systems. Projects related to infrastructure improvements may be funded publicly, privately, or through public-private partnerships.

3 0
2 years ago
I need help, thank you
BabaBlast [244]

Answer:

umm I think it's C it's between that one and d so the 1st and 4th but leaning more towards C

6 0
2 years ago
Other questions:
  • Which of the following is a useful policy to minimize waste and mistakes?
    6·1 answer
  • What are the 5 general terms of the fair use rule
    9·1 answer
  • A(n) ____ is a request for specific data from a database.
    9·1 answer
  • A page with no meaningful content that is full of ads and the webmaster makes money from if someone clicks on them is called____
    7·1 answer
  • The stream cipher described in Definition 2.1.1 can easily be generalized to work in alphabets other than the binary one. For ma
    10·1 answer
  • Do You assign the Needs Met rating before assigning the page quality (PQ) rating?
    11·1 answer
  • Meaning of ‘integrity of data’
    14·2 answers
  • How network diagram help in scheduling a project? Draw activity network diagram as per given
    7·1 answer
  • What is added to brining liquid to add flavour​
    6·1 answer
  • Write the function definition for a function called list_total that accepts a list of integers
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!