diff --git a/HW2/README.md b/HW2/README.md index 02d3249..e8b5420 100644 --- a/HW2/README.md +++ b/HW2/README.md @@ -1,20 +1,48 @@ +# Homework 2 - Igor and Mahmoud - SP4E course + +The files structures is as the following: + HW2 + | + \______src (The source files for all *.cc and *.hh files) + | | + | | + | \______ CMakeLists.txt (for making binaries of excutables) + | | + | \______ main.cc (The main file) + | | + | \______ Series.cc and Series.hh(The series classes) + | | + | \______ DumperSeries.cc and DumpeSeries.hh (The printting/writing classes) + | + \______ CMakeLists.txt (The root level) + | + \______ README.md + + When running main from the terminal, input arguments are the following: + Argument 1: 0-> Compute arithmetic series; 1-> Compute Pi + Argument 2: Number of iterations + Argument 3: Frequency + Argument 4: Delimiter + Argument 5: 0-> Print to screen; 1->Print to file + Argument 6 : Precision of the output to the screen + for example (c/p in Terminal= ./main 1 500 20 ',' 1 5) This will compute PI series with freq of 20 up to 500 iterations. The generated files will be from .csv format with a precision of 5 decimals. If there's no input, default values are used: (1,10,1,',',1,5) Before using variables unsigned int current_index; double current_value; the efficency of program was rather low. That was due to the fact that, every time a method dump of one of the DumperSeries child classes would initiate a next step of its for loop, the compute method of the one of the Series child classes would need to perform it's for loop from beginning up to the step N. However, if the current_index is stored, when the dump method's for loop goes to next step, the compute method's for loop needs to perform just one for loop for the current_index++ and add one value to the already stored current_value. This is very useful, especially when we are dealing with the high iteration number. I.e. in dump method's step from 55-56, the compute method loop needs to perform just one step of for loop instead of repeating the "old" 55 + the new 56th. Basically, we are preventing the recomputation of the whole series. Speaking from the time complexity point of view, that would mean that in the first case the complexity is O(n^2) because for every i-th step of first loop it goes through i steps in the second loop. After making the mentioned changes, the complexity decreases to O(2N), since for every additional i-th step of the first loop it needs to run just one step of the nested loop. In case of summing terms reversely, at the first iteration of the first loop n steps would have to be performed at the nested loop. After that for every i-th step of the first loop, one step of the nested loop would have to be performed. Thus the resulting complexity of the series would be O(2n+(n-1))=O(3n-1)