Daily Reading 1
Big O, pain, and mutability.
In the context of the reading “Pain and Suffering,” describe the main challenges faced by beginners when learning Python and suggest at least two strategies for overcoming these obstacles.
Be ready to improvise, research, and adapt. You are entering into a programming language that is, most likely, entirely alien to you, and you will need to learn fast. But remember that you have the sum of all human insight at your fingertips. Search on the internet for anything an everything that confuses you through the process. As a beginner, there’s thousands upon thousands of others right there with you, who previously had to solve any and every problem you can imagine.
Forgive yourself. The rapid and extensive pace of the class means you are going to make mistakes, you are going to be overwhelmed by the monumental tasks in front of you, but freezing in fear achieves nothing. Chip away at it. Hold back the fear, and make progress.
After reading “Beginners Guide to Big O,” explain the concept of time complexity and space complexity.
The time complexity of a function refers to how long an operation takes based on the number of inputs a function has, not in terms of processing time, but how the number of total steps of logic changes. High time complexity would be a function that must perform a rapidly increasing number of steps based on the input, while a function with no time complexity would take the same amount of processing steps no matter how many inputs are received.
Space complexity is fundamentally similar to time complexity, but is instead a measurement of how the memory used by the computer varies based on the number of inputs of a function. A function with high space complexity rapidly balloons in required memory as the number of inputs increases, where a function with no space complexity will never change in the amount of memory required, no matter the number of inputs.
Based on the “Names and Values in Python” reading, explain the difference between mutable and immutable data types in Python.
A mutable data type is a datatype that can be modified in place. An example would be creating a list, and then changing the third value present in the list, without deleting the entire list and creating a new one. Because you are able to change the values present inside a list, lists are a mutable data type.
An immutable data type is a datatype where the values contained can not be modified in any way after creation. Python’s tuples are an example of an immutable data type, as attempting to change the second value in an existing tuple to a new one will result in an error.
Python is notable for having mutable aliasing, where any changes to a value held as a variable will spread those changes to any other variables that reference the same thing. If X refers to 1, and Y refers to X, then assigning a new value to X will also make Y refer to the new value as well.
This can lead to confusion however, as this behavior does NOT apply to data types that are immutable, such as strings. Behind the scenes, if you were to have X combine two strings together, X would actually cease referring to the original string, and instead refer to a newly created string that consists of the combined string you requested. However, this means that if Y was defined and referred to X prior to this change occurring, Y will still refer to X’s original value, the pre-combined string.