emory-courses / dsa-java

Data Structures and Algorithms in Java
https://emory.gitbook.io/dsa-java/
42 stars 55 forks source link

[HW#2] Whitespace Handle #151

Closed LukHan99 closed 3 years ago

LukHan99 commented 3 years ago

In the note's of the homework, Dr. Choi wrote that "Whitespaces are not allowed as input; thus, you should trim all input strings." so I just want to make sure that does this sentence mean: inputs consist of only spaces like " " are not allowed as input, but the empty string "" and inputs with a combination of characters and spaces like "ap p l e " are allowed. For inputs like "ap p l e ", we should trim it and consider "apple" as the prefix.

Also, if my above logic is true, does it mean that we need to write exception catch blocks to catch inputs which consists of only spaces like " ", or we should just ignore this case since it will not be tested? Thanks!

lujiaying commented 3 years ago

The edge case is good. I am glad to see you are trying to make the code robust.

I think for this homework, it is not necessary to process "ap p l e" into "apple" because there are many other possible situations leading this merging into a bad decision. "ap p l e" typically will be recognized as multiple words"ap", "p", "l", "e'. For trim, it only eliminates leading and trailing spaces, but not the middle spaces.

In other words, auto-complete is designed to complete a prefix that not contain whitespace. For your case like "ap p l e" or only space, I think you can write exception catch or other statements to prompt that the input is not valid.

jdchoi77 commented 3 years ago

@LukHan99 by trimming means that you need to remove whitespaces before and after the real word, not in between.