Skip to content

YuriiJavaDev/JavaBasics_Task_93_V0.2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Edge-to-Center Palindrome Check (JavaBasics_Task_93_V0.2)

📖 Description

This project implements the "Two Pointers" algorithm to verify if a character array is a palindrome. It avoids creating additional memory structures by comparing elements from the start and end of the array, progressively moving toward the center.

📋 Requirements Compliance

Manually verify a palindrome by iterating from edges to the center.

Requirements:

  • No secondary array (Space complexity: $O(1)$).
  • Use two pointer variables: left (start) and right (end).
  • Compare values at these pointers within a while loop.
  • If values match: increment left, decrement right.
  • If values mismatch: set isPalindrome to false and break.
  • Handle both even and odd length arrays correctly.

🚀 Architectural Stack

  • Two-Pointer Strategy: An optimized approach that validates symmetry without array reversal.
  • Short-Circuit Termination: Utilizing the break statement for immediate execution halt upon detecting a mismatch.

🏗️ Implementation Details

  • The "Meeting Point": For an array of size $n$, the pointers will either cross (even length) or meet at the exact center index (odd length).
  • Index Safety: The loop terminates naturally when the right pointer becomes smaller than the left pointer, preventing any ArrayIndexOutOfBoundsException.

📋 Expected result

Array to check: [a, b, c, b, a]
Is it a palindrome? true

💻 Code Example

Project Structure:

src/com/yurii/pavlenko/
                └── EdgeToCenterPalindrome.java # Main Entry Point & Logic

Code

package com.yurii.pavlenko;

import java.util.Arrays;

public class EdgeToCenterPalindrome {
    public static void main(String[] args) {

        char[] original = {'a', 'b', 'c', 'b', 'a'};
        int left = 0;
        int right = original.length - 1;
        boolean isPalindrome = true;

        while (left <= right) {
            if (original[left] == original[right]) {
                left++;
                right--;
            } else {
                isPalindrome = false;
                break;
            }
        }
        System.out.println("Array to check: " + Arrays.toString(original));
        System.out.println("Is it a palindrome? " + isPalindrome);
    }
}

⚖️ License

This project is licensed under the MIT License.

Copyright (c) 2026 Yurii Pavlenko

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files...

License: MIT

About

This is a tutorial project. JavaBasics_Task_93_V0.5 Implementing memory-efficient palindrome check using edge-to-center two-pointer logic. 090226_0900

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages