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
Which is a good example of kinetic energy
Alexandra [31]

Answer: A. Flying a paper airplane.  

5 0
3 years ago
Read 2 more answers
Assslainsdffddsvvdesdssbhasasco5m
alexandr402 [8]
Hahahahaha I wanna was the day I wanna was the last time I got to
8 0
3 years ago
Read 2 more answers
A system developer needs to provide machine-to-machine interface between an application and a database server in the production
nordsb [41]

Answer:

The correct option is (d) Use a service account and prohibit users from accessing this account for development work

Explanation:

Solution

As regards to the above requirement where the application and database server in the production environment will need to exchange the data once ever day, the following access control account practices would be used in this situation:

By making use of a service account and forbids users from having this account for development work.

The service account can be useful to explicitly issue a security context for services and thus the service can also access the local and the other resources and also prohibiting the other users to access the account for the development work.

Submitting an adhoc request daily is not a choice as this is required daily. Also, the servers can be different and cannot be put in one place. and, we cannot make use of the read-write permission to the members of that group.

7 0
3 years ago
What are the five types of pointing devices?
choli [55]

Answer:

mouse, track ball, stick, touch pad, tablet

6 0
2 years ago
When pasting a circle drawn by the presentation software drawing tool into a spreadsheet, that circle will go into the selected
ivann1987 [24]
The answer is ............................ False
6 0
3 years ago
Read 2 more answers
Other questions:
  • Jesse is writing a physics quiz about the motion of a roller coaster cart. He has a clip art illustration of a cart rolling hori
    9·2 answers
  • Which Computer career field enables you to create and design interactive multimedia products and service
    5·2 answers
  • The most likely reason that company computers connected to the Internet should use anti-virus protection software is..?
    5·1 answer
  • >>> import math >>> print(math.Pi) 3.141592653589793 >>> def print_volume(): print ("What is the radi
    12·1 answer
  • With a _____ network connection, the computers and other devices on the network are physically connected via cabling to the netw
    13·1 answer
  • A power supply unit for a computer converts:
    7·1 answer
  • Select the two statements below that are true. Press on the info button for
    13·1 answer
  • What are the three basic classes of application
    14·2 answers
  • You are setting up a home network for your friend. She has students visiting her home regularly for lessons and wants to provide
    14·1 answer
  • If you want to share information with individuals who are internal to your organization, which type of network would you want to
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!