Advertisement
wavec022

Lesson 3 Notes

Jan 23rd, 2020
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. Lesson 3 Notes
  2.  
  3. Array = a list with a fixed size
  4.  
  5. [[1],[2],[3],[4],[5]]
  6. In Python this is a list of lists
  7. not an array in python
  8.  
  9. in scala we need to say what type of array it is
  10. [45,60,27,3,41] indices 0-4
  11.  
  12. =======
  13.  
  14. val numbers: Array[Int] = Array(45,60,27,3,41)
  15. it is a fixed size
  16. has to hold the same type
  17.  
  18. if we know the index it takes CONSTANT TIME to find elements in arrays
  19.  
  20. if I don't know the index then I'll start at the beginning and look for the given value-- LINEAR TIME
  21.  
  22. Arrays are mutable-- n(2) = 74
  23. updating an array
  24.  
  25. val two = n(2) // ezpz
  26.  
  27. 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
  28. so we will use a list instead!
  29.  
  30. ========
  31.  
  32. 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)
  33. the last one points to nothing / null
  34.  
  35. 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