2014-03-05 - HW

posted Mar 5, 2014, 5:40 AM by Samuel Konstantinovich   [ updated Mar 6, 2014, 9:49 AM ]
Goal: Miscelanery, big O, binary search.

0. Homework: (SUBMIT ON HW SERVER)
Everyone should have a mergesort that works with the int datatype.

Everyone now must make a new mergesort that works with Strings:
It must work as follows. (You must submit Sorts.java zipped)

public class Sorts{

    public static void msort(ArrayList<String> L){ 
    /************************YOUR SORT HERE****************/
    }

    public static String name(){
        /****************EDIT YOUR NAME HERE:****************/
        return "Brown,James";
    }

    //HELPER FUNCTOINS ARE FINE!
}
-Use an array list of Strings as your list data type.
-remember you need to make a lot of changes to make it work
-Comparisons with > < == etc. do NOT work with objects. if(s1<s2){ } does not work with strings!
-use set() get() and compareTo()


Submit the working String mergesort on the hw server. I will set the deadline tonight 1159, if you got it working with ints, it should be reasonable to get it working with an ArrayList of Strings. (You must submit Sorts.java zipped) 

EXTRA CREDIT: Submit your regular int msort, and your optimized int mergesort:  (
public class Sorts{
    public static void msort(int[] L){ 
          /************************YOUR SORT HERE****************/
    }

    public static void msortOpt(int[] L){ 
           /************************YOUR SORT HERE****************/
    }
    public static String name(){
            /****************EDIT YOUR NAME HERE:****************/
            return "Brown,James";
    }
}

1.
-BigO notation:
Formal definition that is beyond what you need for this class:
An algorithm is O( f(n) ) if and only if there is a constant k such that the algorithm runs < k*f(n) for sufficiently large values of n.
This means big O notation defines an upper bound.

Cool stuff: There are more ways to define complexity such as:  Theta(n) and Omega(n) notation.

2.
Linear Search vs. Binary Search 

searching for a value returns the index it can be found at in a list. 
find( 5, {5,4,2} ) -> 0
find( 5, {3,4,5} ) -> 2
find( 9, {5,4,2} ) -> -1  (not found)

Comments