SP4EHW_IM/HW224fcb07d802dmaster
README.md
Homework 2 - Igor and Mahmoud - SP4E course
The question about the cooperation between the group members
Basically, we work in parallel, since the nature of the questions needs to synchronize the work. About 70% of the work has been implemented together especially when agreeing on the main structure of the program and the classes and methods required. Other details such as filling classes and methods connected we work separately and check when we're done. In c++ we use Code::Blocks IDE for formularizing the structure in general and make it running because it's easier to debug and test on it. After that, we use CMake to build and run our binaries. It could be helpful if you introduced us with EMACS so we work independently of any IDE and how to add similar features in regular IDEs' like intellisense on EMACS.
The files structure goes as the following:
├── ..\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) │ │ │ └── ..\Python_Plot\ │ │ ├── Python_read_plot.py (Test and Plot *.csv, *.psv and *.txt) │ | │ └── Dumperfiles.csv (File that is generated from executing main *.csv) │ | │ └── Dumperfiles.psv (File that is generated from executing main *.psv) │ ├── CMakeLists.txt (The root level) │ └── README.md
CMake Running Instructions
c/p in terminal: >> mkdir build
c/p in terminal: >> cd build
c/p in terminal: >> cmake ..
c/p in terminal: >> make
c/p in terminal: >> cd src/./main
C++ Code Running Instructions:
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)
Python Files Reader and Plotter Instructions:
For the terminal the default running command will be: c/p in terminal >> ipython3 Python_read_plot.py. This command will normally run and test (Dumpfile.csv) in the directory. To read other files:
Argument 0: the file itself (happens when it called);
Argument 1: the data file's name;
Argument 2: to change the delimiter to a non-default one enter 1, otherwise 0. Notting that the default ones are "," for *.csv, "|" for *.psv files.
Argument 3: enter the delimiter if you chose to change it in the first place.
Example:
c/p in terminal >> ipython3 Python_read_plot.py file_name.some_extention 1 "@some_delimiter_one_char@"
Answering the related questions:
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)