emory-courses / dsa-java

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

Announcement Clarification #185

Closed TFloyd1989 closed 3 years ago

TFloyd1989 commented 3 years ago

I was just wondering if I concatenate the null character in my code. If the prefix is empty, I make the prefix equal to an empty space "" which I then get the children of. I'm pretty sure this is the root node. For the first iteration of my BFS, I do prefix + key in a loop, which I think concatenates the root character. I have also included a screenshot.image

marvinquiet commented 3 years ago

The new announcement if for those who accidentally concatenate the string up to the root (which is null) and return as a list. In this way, only by asserting can they find the error, and simply printing won't help.

In your case, it seems that the logic is correct, but

(1) It seems that you did not trim the word with there is a whitespace (2) what will you get when you simply use "she" as your prefix? From my end, there are exceptions in your output.

TFloyd1989 commented 3 years ago

I trim the word earlier in my code in line 35 if the string is not blank, and I used the prefix she while testing which never gave me any errors.

TFloyd1989 commented 3 years ago

Screenshot (64) This is the output for she with no changes to my code

marvinquiet commented 3 years ago

May I know what does that 's}' represent? Also, could you drag it a bit more or paste it here so that I can see the whole return list?

marvinquiet commented 3 years ago

Oh, I see, the 's}' is your candidate, could you please share all the output then?

TFloyd1989 commented 3 years ago

Screenshot (66) Screenshot (65) Here are all of the tests and results

TFloyd1989 commented 3 years ago

(All testing done with original code)

marvinquiet commented 3 years ago

Could you please try changing your candidate to null and see what happened?

TFloyd1989 commented 3 years ago

I get a null pointer exception

marvinquiet commented 3 years ago

When testing your code with null as candidate, this is what I get

image

So according to textbook you did not deal with followings:

Your program should be able to handle prefixes or candidates that do not exist in the dictionary.
All picked candidates should be introduced as real words to the trie.
Whitespaces are not allowed as input; thus, you should trim all input strings.
TFloyd1989 commented 3 years ago

Understood, is this where I lost a lot of points?

marvinquiet commented 3 years ago

Yes, you may want to fix that error within two lines of code change before 1pm

TFloyd1989 commented 3 years ago

We are only allowed to modify 2 lines in the total code?

marvinquiet commented 3 years ago

You don't need to insert null into this. For a null candidate, you just return the candidates for the prefix as usual and it should be solved with 1 line.

Yes, in total, 2 lines at most

TFloyd1989 commented 3 years ago

For example, if a given candidate sh has the candidates shell and sheep, getcandidates should return shell and sheep if pickcandidates contains null? Also, what if sh has no candidates at all?