Skip to content

Conversation

@ganesh47
Copy link
Owner

This commit introduces the BtreeP67 class, which provides functionality to convert binary trees to and from a specific string format.

The string representation follows the pattern: value(left_subtree,right_subtree).

  • Leaf nodes are represented by their value alone (e.g., "d").
  • Empty subtrees are represented by an empty string between separators (e.g., "c(,f)" for a node "c" with no left child, or "f(g,)" for a node "f" with no right child).

Key features I implemented:

  • BtreeP67.fromString(String representation): This parses the string and constructs the corresponding binary tree. I've included validation for malformed strings.
  • BtreeP67.toString(): This converts a binary tree into its string representation.
  • equals() and hashCode() methods for both BtreeP67 and its inner Node class to ensure correct structural comparison.

I've also added a comprehensive suite of JUnit 5 tests (BtreeP67Test.java) to verify:

  • Correct parsing of various valid tree strings.
  • Accurate serialization of trees to strings.
  • Robustness of round-trip conversions (string -> tree -> string and tree -> string -> tree).
  • Handling of edge cases (e.g., empty strings, leaf nodes represented as "val(,)").
  • Appropriate error handling for malformed input strings.

This commit introduces the `BtreeP67` class, which provides functionality to convert binary trees to and from a specific string format.

The string representation follows the pattern: `value(left_subtree,right_subtree)`.
- Leaf nodes are represented by their value alone (e.g., "d").
- Empty subtrees are represented by an empty string between separators (e.g., "c(,f)" for a node "c" with no left child, or "f(g,)" for a node "f" with no right child).

Key features I implemented:
- `BtreeP67.fromString(String representation)`: This parses the string and constructs the corresponding binary tree. I've included validation for malformed strings.
- `BtreeP67.toString()`: This converts a binary tree into its string representation.
- `equals()` and `hashCode()` methods for both `BtreeP67` and its inner `Node` class to ensure correct structural comparison.

I've also added a comprehensive suite of JUnit 5 tests (`BtreeP67Test.java`) to verify:
- Correct parsing of various valid tree strings.
- Accurate serialization of trees to strings.
- Robustness of round-trip conversions (string -> tree -> string and tree -> string -> tree).
- Handling of edge cases (e.g., empty strings, leaf nodes represented as "val(,)").
- Appropriate error handling for malformed input strings.
This commit introduces the BtreeP67 class, which provides functionality to convert binary trees to and from a specific string format, addressing problem P67.

The string representation follows the pattern: `value(left_subtree,right_subtree)`.
- Leaf nodes are represented by their value alone (e.g., "d").
- Empty subtrees are represented by an empty string between separators (e.g., "c(,f)" for a node "c" with no left child, or "f(g,)" for a node "f" with no right child).

Key features implemented in BtreeP67.java:
- `BtreeP67.fromString(String representation)`: Parses the string and constructs the corresponding binary tree. Includes validation for malformed strings.
- `BtreeP67.toString()`: Converts a binary tree into its string representation.
- `equals()` and `hashCode()` methods for both `BtreeP67` and its inner `Node` class to ensure correct structural comparison.

A comprehensive suite of JUnit 5 tests (`BtreeP67Test.java`) has been added. These tests have been verified to pass, while the `pom.xml` targets Java 22, ensuring compatibility with matrix testing environments.

The `pom.xml` file remains unchanged by this commit to support the project's matrix testing strategy across different Java versions.
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jun 15, 2025

@ganesh47 ganesh47 merged commit 64d5f54 into main Jun 15, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants