Class 1 reading


Class 1 reading

Pain and Suffering

None of us were professional web developers before we enter the scores, so we are supposed to be prepared to take some painful process to learn the new knowledges. But the pain to grouth may suprised you. Considering you’ll learn from uncertainty, learn from researches, learn from others, learn from any resources you could to finish the projects. But this is the pain for grouth.

All growth comes with some degree of pain, as it pulls you out of your comfort zone. The greater the growth, the greater the pain. But pain in the service of growth is a good thing, as long as that pain is what’s necessary to achieve the growth that you’re aiming for. And even better than that, this pain is only temporary. It’s what will launch you forward into the next phase of your life.

But this is not suffering. Suffering is pain without purpose. My purose to take this course is to become a spectacular craftsman of software with Python as my tool.

A beginner’s guide to Big O notation

Big O notation is used in Computer Science to describe the performance or complexity of an algorithm.

Big O specifically describes the worst-case scenario, and can be used to describe the execution time required or the space used (e.g. in memory or on disk) by an algorithm.

O(1)

O(1) describes an algorithm that will always execute in the same time (or space) regardless of the size of the input data set.

def isFirstElementNull(elements, value):
    return elements[0] == value

O(N)

O(N) describes an algorithm whose performance will grow linearly and in direct proportion to the size of the input data set. The example below also demonstrates how Big O favours the worst-case performance scenario; a matching string could be found during any iteration of the for loop and the function would return early, but Big O notation will always assume the upper limit where the algorithm will perform the maximum number of iterations.

def containsValue(elements, value):
    for e in elements:
        if e == value:
            return True
    return False

O(N2)

O(N2) represents an algorithm whose performance is directly proportional to the square of the size of the input data set. This is common with algorithms that involve nested iterations over the data set. Deeper nested iterations will result in O(N3), O(N4) etc.

def containsDuplicates(elements):
    for m in range(len(elements)):
        for n in range(len(elements)):
            if (m != n) and elements[m] == elements[n]:
                return True
    return False

O(2N)

O(2N) denotes an algorithm whose growth doubles with each additon to the input data set. The growth curve of an O(2N) function is exponential - starting off very shallow, then rising meteorically. An example of an O(2N) function is the recursive calculation of Fibonacci numbers:

def fibonacci(num):
    if num < 2:
        return num
    return fibonacci(num - 2) + fibonacci(num - 1)