CS130-lecture-20200902

Concerning the survey from last class #

The differences between an array and a linked list:

  • Access: arrays can access an spot instantly, linked lists need to iterate from the head until they reach the target.
  • Size: arrays are fixed in size, linked lists can become bigger or smaller

Stacks can be implemented using a linked list or an array. FILO

Queues can be implemented using a linked list or a circular array. FIFO

Recursion #

IMAGE

Recursive functions must have a base case, otherwise you will get an infinite loop!

IMAGE

IMAGE

  1. f1 has no base case
  2. f2 doesn’t reduce the problem to the base case (no n - 1)
  3. f3 needs to check the base case first
  4. f4 recursive call is infinite when n > 0

IMAGE

Algorithm analysis #

IMAGE IMAGE IMAGE IMAGE IMAGE IMAGE IMAGE IMAGE