Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1). The elements of an integer -valued array can be set to 0 (i.e., the array ca

ID: 3536479 • Letter: 1

Question


1).

The elements of an integer -valued array can be set to 0 (i.e., the array can be cleared) recursively as follows:

An array of size 0 is already cleared;

Otherwise, set the first element of the array to 0, and clear the rest of the array Write a voidmethod named clear that accepts an integer array , and the number of elements in the array and sets the elements of the array to 0.

2).

A 'array palindrome' is an array which, when its elements are reversed, remains the same (i.e., the elements of the array are same 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.

Help please!!!

Explanation / Answer

1.
void clearArray(int [] arr,int size){

if(size==0)

return;

arr[size-1]=0;

clearArray(arr,size-1);

}


2.

boolean isPalindrome(int [] array,int start,int end){

if(start>=end)

return true;

else if(array[start]!=array[end])

return false;

else

return isPalindrome(array,start+1,end-1);

}