In the arabic language, sometimes you need to draw two tiny forward slashes on top of or under letters. For example, the word also in arabic has these slashes on top of the o so also//
now i want to write a spell checker in java that looks into things like this.
- use a 2D array where column1 has all the words that require the slashes but don't include them in it so index00 will be also and column2 has the same words but with the slashes in the appropriate places so index01 will be also//
- use a for loop to go through each line where in each line, we use stringtokenizer to go thru each word comparing it to the words in column1. Once you find it, replace it with column2.
method 2: same 2D array but first you use a regular expression. i create one that has all the words in column1. then i write if (m.find()) change found to true (default false) and exit. then i check if found is true. if it is, i use stringtokenizer. you know the rest
I'm looking for the efficient way to do this as the title says.
Pros of method2 (Yes im starting with 2) using regular expressions saves you the trouble of having to go through the for loop as some lines might be correct the Big O notation of using a regular expressions is at least O(n) just like the while loop which means that it's efficient because a while loop with a for loop in it is On squared
Cons of method2 it might be efficient but the lines and their spelling depends on the user writing them so you might find that you're not really saving much time using this method
As for method1, there's not much to say. Well it depends on your opinion of the pros and cons of method2. You might surprise me and tell me that the notation of regular expressions is worse than O(n) so I might as well stick to the for loop. Only O(n) and I will be entering the for loop anyways.
What do I think? I think that speculating about the performance of code you haven't written yet is not an especially useful thing to do. And I think that the phrase "performance of regular expressions" is a particularly good example of why it isn't useful. Regular expressions covers a vast amount of territory, and trying to claim that everything in that territory has the similar performance (compared to nothing in particular) is just wrong.