Skip to content

Fix trie deleteString logic to preserve shared prefix words#3135

Open
sudheerxdev wants to merge 4 commits into
TheAlgorithms:masterfrom
sudheerxdev:sudheerxdev/issue2411
Open

Fix trie deleteString logic to preserve shared prefix words#3135
sudheerxdev wants to merge 4 commits into
TheAlgorithms:masterfrom
sudheerxdev:sudheerxdev/issue2411

Conversation

@sudheerxdev
Copy link
Copy Markdown

Description

Fixes critical bug in trie deleteString function where child pointers were being unconditionally reset, corrupting words that share prefixes.

Changes

  • Only prune nodes when truly empty (no children AND not terminal)
  • Separate deletion success from node pruning logic
  • Add regression test for prefix case (Hell/Hello)
  • Fix signed/unsigned comparison compiler warnings

Testing

  • Existing tests pass
  • Regression test validates that deleting "Hello" preserves "Hell"
  • Clean compilation with -Wall -Wextra

- Only prune child nodes when they are truly empty (no children, not terminal)
- Separate deletion success from node pruning logic
- Add regression test for prefix case (Hell/Hello)
- Replace direct git push with create-pull-request action
- Fixes issue TheAlgorithms#2411: CI unable to push to master
- PR-based approach is safer and aligns with GitHub best practices
- CI now creates automatic PRs for formatting/linting fixes
- Maintainers can review before merge
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.

1 participant