How to calculate the time and space complexity of an algorithm c++?

I have spent lots of time trying to find a complete explanation about the manner to define the time and space complexity of an algorithm and about what can i do when the time and space complexity are given and i should write the code corresponding to the restrictions , which i find very difficult. Please help me with a link to a good source.
First, have a look at this simple example:
https://en.wikipedia.org/wiki/Analysis_of_algorithms#Evaluating_run-time_complexity

Tutorial: http://www.leda-tutorial.org/en/official/ch02s02s03.html

Some more examples: http://stackoverflow.com/questions/487258/plain-english-explanation-of-big-o


For the algorithms and data structures in the standard library, the complexity is specified by the standard (IS).

For instance, std::vector<>::push_back() Complexity: amortized constant O(1).
http://en.cppreference.com/w/cpp/container/vector/push_back

Or: std::nth_element() Complexity: average linear O(N)
http://en.cppreference.com/w/cpp/algorithm/nth_element
Topic archived. No new replies allowed.