From charlesreid1

 
(13 intermediate revisions by the same user not shown)
Line 3: Line 3:
=Notes=
=Notes=


==Goodrich Python Chapter 5 Notes==
==Notes from Goodrich et al Data Structures in Python Chapter 5==


=Questions=
Chapter 5 of the Goodrich Python book covers array and array-based sequences (lists and arrays), and all of it is language-specific.


==Goodrich Python Questions==
See [[Arrays/Python]]


See also [[Arrays/Python]]
==Notes from Goodrich et al Data Structures in Java Chapter 4==


===exploring relationship between list length and size===
Chapter 4 of the Goodrich Java book focuses on arrays, arraylists, and resizing. It is, like above, language-specific and therefore on its own page.


'''Question 5-1: execute the code fragment, and compare the results to those in the book.'''
See [[Arrays/Java]]


The code fragment starts with an empty list, dynamically growing the list by appending items to the end, and showing how the size of the list is doubled each time the list gets bigger.
=Questions=
 
This also demonstrates the importance of declaring a list size if you know it! It's really expensive to keep resizing a list. (Remember the days of Matlab - you'd get an order of magnitude savings in time simply by declaring the array straight out.
 
Key function:
* <code>sys.getsizeof(data)</code> to get the size of a list in bytes
 
The code populates the list with None (null) objects, which take up as much space as pointers to addresses in memory (64 bits on a 64 bit memory/computer)
<pre>
import sys
data = []
n = 50
for k in range(n+1):
    a = len(data)
    b = sys.getsizeof(data)
    print("Length: {0:3d}\tSize in bytes: {1:6d}".format(a,b))
    data.append(None)
</pre>


<pre>
See [[Arrays/Python#Questions]] for answers to questions from Goodrich et al, Data Structures in Python, Chapter 5
import sys


<pre>
List of pages:
$ python list_length_sizeof.py
* [[Arrays/Python/Sizeof]]
Length:   0 Size in bytes:    72
* [[Arrays/Python/DynamicArray]]
Length:  1 Size in bytes:    104
* [[Arrays/Python/CaesarCipher]]
Length:  2 Size in bytes:    104
Length:  3 Size in bytes:    104
Length:  4 Size in bytes:    104
Length:  5 Size in bytes:    136
Length:  6 Size in bytes:    136
Length:  7 Size in bytes:    136
Length:  8 Size in bytes:    136
Length:  9 Size in bytes:    200
Length:  10 Size in bytes:    200
Length:  11 Size in bytes:    200
Length:  12 Size in bytes:    200
Length:  13 Size in bytes:    200
Length:  14 Size in bytes:    200
Length:  15 Size in bytes:    200
Length:  16 Size in bytes:    200
Length:  17 Size in bytes:    272
Length:  18 Size in bytes:    272
Length:  19 Size in bytes:    272
Length:  20 Size in bytes:    272
Length:  21 Size in bytes:    272
Length:  22 Size in bytes:    272
Length:  23 Size in bytes:    272
Length:  24 Size in bytes:    272
Length:  25 Size in bytes:    272
Length:  26 Size in bytes:    352
Length:  27 Size in bytes:    352
Length:  28 Size in bytes:    352
Length:  29 Size in bytes:    352
Length:  30 Size in bytes:    352
Length:  31 Size in bytes:    352
Length:  32 Size in bytes:    352
Length:  33 Size in bytes:    352
Length:  34 Size in bytes:    352
Length:  35 Size in bytes:    352
Length:  36 Size in bytes:    440
Length:  37 Size in bytes:    440
Length:  38 Size in bytes:    440
Length:  39 Size in bytes:    440
Length:  40 Size in bytes:    440
Length:  41 Size in bytes:    440
Length:  42 Size in bytes:    440
Length:  43 Size in bytes:    440
Length:  44 Size in bytes:    440
Length:  45 Size in bytes:    440
Length:  46 Size in bytes:    440
Length:  47 Size in bytes:    536
Length:  48 Size in bytes:    536
Length:  49 Size in bytes:    536
Length:  50 Size in bytes:    536
</pre>


See [[Arrays/Java#Questions]] for answers to questions from Goodrich et al, Data Structures in Java, Chapter 3




Line 98: Line 31:


{{DataStructuresFlag}}
{{DataStructuresFlag}}
[[Category:Arrays]]

Latest revision as of 01:08, 6 June 2017

Notes on arrays and array-like structures.

Notes

Notes from Goodrich et al Data Structures in Python Chapter 5

Chapter 5 of the Goodrich Python book covers array and array-based sequences (lists and arrays), and all of it is language-specific.

See Arrays/Python

Notes from Goodrich et al Data Structures in Java Chapter 4

Chapter 4 of the Goodrich Java book focuses on arrays, arraylists, and resizing. It is, like above, language-specific and therefore on its own page.

See Arrays/Java

Questions

See Arrays/Python#Questions for answers to questions from Goodrich et al, Data Structures in Python, Chapter 5

List of pages:

See Arrays/Java#Questions for answers to questions from Goodrich et al, Data Structures in Java, Chapter 3