Question: Suppose you have a doubly linked list of Node objects with char data elements. The Node class is provided below. class Node { char data;
Suppose you have a doubly linked list of Node objects with char data elements. The Node class is provided below. class Node {
char data;
Node next; // links to the next node
Node prev; // links to the previous node
}
Consider that head is the reference variable that holds the starting non-null node and tail is the last non-null node of the doubly linked list you have. Obviously, both head and tail are instances of the Node class.
(a) Write a recursive method named isPalindrome that checks whether a sequence of characters in a doubly linked list of Node objects forms a palindrome. The method must return true if the sequence forms a palindrome; otherwise, it should return false. As examples, if the linked list contains {A, C, C, A} or {A, C, A} in a sequence then the isPalindrome method should return true. For a sequence, {A, C, C, B}, the isPalindrome method should return false. You must use the following header.
public static boolean isPalindrome(Node head, Node tail) {
(b) What is the time complexity (big-oh) of the isPalindrome method you have written?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
