In Class: Week 14


Wednesday:

Create a week14 subdirectory in your cs21/class directory and copy over some starting point files:
    $ cd
    $ cd cs21/class
    $ pwd
      /home/your_user_name/cs21/class
    $ mkdir week14
    $ cd week14
    $ pwd
      /home/your_user_name/cs21/class/week14
    $ cp ~newhall/public/cs21/week14/* .
  
  1. let's look at the merge sort algorithm

Monday:

We will continue with the linked list classes from last week (in linkedlist.py)

You can copy over code I wrote in class last week from:

$ cp ~newhall/public/cs21/week12/tias* .

  1. Finish FindNode.

  2. Implement insertSorted and test.
    insertSorted(elm):
    (0) create a new node with elm as it data field
    (1) if the list is empty, add this as the new head and tail node 
    (2) else if value <= head node value:
        insert new node at head of list
    (3) else if value >= tail node value:
        insert new node at tail of list
    (4) else insert new node somewhere between two nodes in the list
        (a) Find the insertion spot
            we need to traverse with curr and prev pointers
        (b) insert new node between into the linked list between prev and curr  
    
  3. Answer these questions:
    1. How many steps (what is the big-O of) does it take to search for an element in a linked list?
    2. How many steps to insert at head? How many steps to insert n elements (all adding by insert at head)?
    3. How many steps to insert 1 element in sorted order into a linked list? How many steps to insert n elements in sorted order into a linked list? Remember that big-O is worst case analysis not best-case.
    4. How many steps to access the ith element in a python list? How many steps to access the ith element in a linked list?
    5. Can you do binary search on a linked list? If so, does it have the same big-O as binary search on a python list?