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

solved
Last edited on
solved
Last edited on
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.
solved
Last edited on
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.
solved
Last edited on
solved
Last edited on
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
Topic archived. No new replies allowed.