Help with Big Oh assignment. Break out of parse loop after set number of times

Oct 20, 2013 at 6:14am
solved
Last edited on Oct 21, 2013 at 8:50pm
Oct 20, 2013 at 6:52am
solved
Last edited on Oct 21, 2013 at 8:49pm
Oct 20, 2013 at 7:43am
I think you should run more iterations of the same test, and average the times takes. The HDD could be in a state that stalls your program, for example, giving you huge times.

Also; I believe the Big-Oh notation is for theoretical analysis. Actually benchmarking all the statements would be highly dependent on processor.

In my discrete mathematics course, Big-Oh is used to say that an algorithm is "not worst than" the contents of the Big-Oh. Like; how many if-statements will the maximally be in a certain container.
Oct 20, 2013 at 5:59pm
solved
Last edited on Oct 21, 2013 at 8:49pm
Oct 20, 2013 at 6:34pm
There are several problems. The one you are currently noticing is a cache problem -- the first iteration will go slower because once the processor gets your file in the cache it will open and read mor quickly.

You are also reading every line in your file each time... What you are doing with n is asking for random behavior... You are supposed to stop reading at n lines, but you are stopping based upon the value of an uninitialized value, out of bounds, in your character array.
Oct 20, 2013 at 6:52pm
solved
Last edited on Oct 21, 2013 at 8:49pm
Oct 20, 2013 at 7:20pm
solved
Last edited on Oct 21, 2013 at 8:49pm
Oct 20, 2013 at 10:12pm
Your loop needs to terminate under two conditions:

1
2
3
4
5
string line;
while (n-- && getline( fin, line ))
{
    ...
}

Don't loop on EOF.

Hope this helps.

[edit] fixed typo
Last edited on Oct 20, 2013 at 10:13pm
Topic archived. No new replies allowed.