-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Daniel Dewan Grammar Homework #50
Conversation
@@ -53,7 +57,7 @@ In one sentence, explain why. | |||
|
|||
## A1.2 | |||
|
|||
«replace this with your answer» | |||
O(n) because it has to perform n/2 comparisons because it has to check if the first and the last time are equal, the second and the second to last, etc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right answer, but in fact it has to do many more comparisons than that, because it doesn't know where the end is until it reaches it...
g++ -std=c++11 sentence.cpp | ||
./a.out |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You used a hash table with is great. But your testing wasn't really testing: it just output stuff about sentences. An automated test should know the expected result and make it clear when the function being tested fails to produce it.
Also, a bunch of people wrote code like this:
vector<string> s1 = { "the", "cat", "ate", "EOI" };
vector<string> s2 = {"the", "dog", "ran", "slowly", "EOI"};
vector<string> s3 = {"the", "lazy", "cat", "ran", "slowly", "EOI"};
vector<string> s4 = {"the", "smelly", "dog", "ran", "EOI"};
vector<string> s5 = {"smelly", "dog", "ran", "EOI"};
vector<string> s6 = {"the", "cat", "ate"};
vector<string> s7 = {"the", "cat", "EOI"};
vector<string> s8 = {"the", "smelly", "lazy", "cat", "ate", "EOI"};
vector<vector<string> > sentences;
sentences.push_back(s1);
sentences.push_back(s2);
sentences.push_back(s3);
sentences.push_back(s4);
sentences.push_back(s5);
sentences.push_back(s6);
sentences.push_back(s7);
sentences.push_back(s8);
I don't get it. C++ is already verbose enough without adding to your woes. How about:
vector<vector<string>> sentences {
{ "the", "cat", "ate", "EOI" },
{"the", "dog", "ran", "slowly", "EOI"},
{"the", "lazy", "cat", "ran", "slowly", "EOI"},
{"the", "smelly", "dog", "ran", "EOI"},
{"smelly", "dog", "ran", "EOI"},
{"the", "cat", "ate"},
{"the", "cat", "EOI"},
{"the", "smelly", "lazy", "cat", "ate", "EOI"}
};
(No deduction for that, but -2 for the tests)
-2
In general never add derived files (executables, .obj, etc) to a repository. Other than that, very nice work. I found nothing substantive to comment on; just a small ding on the tests. |
Daniel Dewan
47685941