Ignore case affect character set

72 Views Asked by At

I have created a binary search tree and I want to make it as efficient as possible. When adding nodes I have used equalsIgnoreCase() when comparing it to a String (To prevent duplicates).

When adding two nodes such as: "BOB" and "bob".

For example:

converting "BOB" in to ASCII = 066 079 066

Converting "bob" in to ASCII= 098 111 098

You can see "BOB" and "bob" both have different values due to the uppercase letters.

Would equalsIgnoreCase() accept this as one entry regardless of the capitalisation?

Does this help efficiency?

1

There are 1 best solutions below

0
On BEST ANSWER

This would very likely break your binary tree. There are many values (common ones, even) that come between "bob" and "BOB" in lexicographic order. For instance: anything that starts with a lower-case "a" or an upper-case letter "C" or above. If any one of them were in your tree, then "BOB" would go in one direction at that node ("BOB" < "Dog") while "bob" would go in another ("bob" > "Dog"). That means that you wouldn't even have a chance to compare "bob" and "BOB."

You could get it to work by either: