Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Lesson 3 Notes
- Array = a list with a fixed size
- [[1],[2],[3],[4],[5]]
- In Python this is a list of lists
- not an array in python
- in scala we need to say what type of array it is
- [45,60,27,3,41] indices 0-4
- =======
- val numbers: Array[Int] = Array(45,60,27,3,41)
- it is a fixed size
- has to hold the same type
- if we know the index it takes CONSTANT TIME to find elements in arrays
- if I don't know the index then I'll start at the beginning and look for the given value-- LINEAR TIME
- Arrays are mutable-- n(2) = 74
- updating an array
- val two = n(2) // ezpz
- If i want to add to an array that's already full I need to make a new one, that would be really warm and bad
- so we will use a list instead!
- ========
- Lists are made up of nodes that are made up of values and stuff-- each is a value and a pointer that points to the next node (as opposed to arrays that are just a pointer to a fixed set of values)
- the last one points to nothing / null
- doesn't take constant time to find stuff in arrays by index-- LINEAR TIME instead
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement