Question: Please show all your output afterwards. 1.) Several modern programming languages provide a variable-size list data-type such as the one provided in the Python programming
Please show all your output afterwards.
1.) Several modern programming languages provide a variable-size list data-type such as the one provided in the Python programming language. This flexibility comes at the expense of performance. Our goal in this exercise is to study the overhead associated with Python lists. Write a Python program that repeatedly appends to a list and measures time it takes to append the element, you should notice that occasionally, appending will take significantly more time than usual. Note that in a traditional array, where array size is fixed, adding/setting value of any element will always take the same amount of time. Comment on your findings in a few statements, make sure to show a table with observed insertion times.
2.) Several programming languages support 2-dimensional arrays, since addresses in the native hardware is in fact linear (i.e., 1D), the programming language is responsible for mapping the 2D address into a 1D address. In the this exercise, you are asked to write a function that maps a 2D address (i.e., i and j) into a 1D linear address, in addition to row and column, the function takes the base address of the 2D array and number of columns. (Refer to slide chapter 6/slide 36), below is a simplified version of the formula:
linear_address for (i, j) = base_address + (i *n) + j, where n represents numer of columns in the 2D array, assume indices start at zero:
Function prototype: def to_linear_address(i, j, base_address, n)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
