Browse Source

updating readme with notes from IntList class.

Charles Reid 2 years ago
parent
commit
41f677e67d
2 changed files with 66 additions and 1 deletions
  1. 1
    1
      lists/IntList.java
  2. 65
    0
      lists/README.md

+ 1
- 1
lists/IntList.java View File

@@ -80,7 +80,7 @@ public class IntList {
80 80
 		tail = null;
81 81
 	}
82 82
 
83
-	public String toString() throws IxException { 
83
+	public String toString() { 
84 84
 		StringBuffer result = new StringBuffer();
85 85
 		IntNode next = head;
86 86
 		result.append("[  ");

+ 65
- 0
lists/README.md View File

@@ -0,0 +1,65 @@
1
+# Lists
2
+
3
+## Abstract List Type
4
+
5
+The list abstract data type (ADT) implements the following methods:
6
+* size
7
+* isEmpty
8
+* first
9
+* last
10
+* addFirst
11
+* addLast
12
+* removeFirst
13
+
14
+Other convenience methods:
15
+* remove
16
+* removeFirst
17
+* removeLast
18
+* removeElement
19
+
20
+## Mistakes Learnings Tricks
21
+
22
+Use the `Integer` class when processing integers!
23
+
24
+When you have a String and you want an integer:
25
+* Integer.parse("525")
26
+
27
+When you have an integer and you want a String:
28
+* Integer.toString(str)
29
+
30
+In general, you can also use the String class to turn the object into a String:
31
+* `String.valueOf(o)`
32
+
33
+Linked List specific details:
34
+* Need to handle cases where you are adding to an empty list, or removing last item from list
35
+* Especially when using tail pointer, be aware of what it is pointing to and when it needs to be updated.
36
+
37
+Linked list methods should automatically become a list of bookkeeping things to do.
38
+* Add method: consider adding to an empty list, non-empty list
39
+* Add at index i:
40
+	* What are all possible cases?
41
+	* i is too big, i is too small
42
+	* the list is empty 
43
+	* i is a special case
44
+	* how can we fold any of these cases into other cases (list empty -> i too small)
45
+
46
+
47
+
48
+Size of linked list:;
49
+* Number of bytes: 
50
+	* See [https://charlesreid1.com/wiki/Java/Memory](https://charlesreid1.com/wiki/Java/Memory)
51
+	* 8 bytes per reference to memory (64 bit)
52
+	* 16 bytes of object overhead
53
+* Size estimation:
54
+	* 1000-integer linked list should theoretically use up:
55
+	* 1000 nodes x ( 4 bytes per integer + 8 bytes per ref + 16 bytes object overhead )
56
+	* 28,0000 bytes ~ 28 kB
57
+	* What's the power of 2 that would correspond to that? 
58
+	* 1000 integers ~ 1024 integers ~ 2^10 integers
59
+	* Round it up to 8 bytes per integer, 8 bytes per ref, 16 bytes per object overhead)
60
+	* 2^5 = 32 bytes per integer
61
+	* 32 x 8 = 2^5 * 2^3 = 2^8 = 256 bits = 256 zeroes and ones
62
+	* 10 GB / 10 kB/obj = 10x10^6 / 10 = 10^6
63
+
64
+
65
+