ASU 101: The ASU Experience Computer Science Perspective Aviral Shrivastava Compiler Microarchitecture Lab Arizona State University
Why is ASU an NAU?
Today’s Question What major CS theorem did someone claimed to have proved recently? P=NP?
Homework Write a sorting program in any language you want, and post the solution on your blog. Should take a bunch of numbers as input. Should print them out in increasing order. Also let me know how much time it took you to do the assignment Deadline: Sunday 05 Sept 2010.
Sorting Input: Output IsSorted(A, n) Array of n numbers, a[0] … a[n-1] Array of the same n numbers, such that For each i=0 to n-2, a[i] <= a[i+1] IsSorted(A, n) Definitely need this ability O(n)
Random Sort In loop If array not sorted Else Pick any two elements at random, and swap them to put them in the right order Else Exit Random sort is not algorithm; Perm sort is an algorithm.
Permutation Sort In a loop If array not sorted Else Permute the elements Else Exit; Random sort is not algorithm; Perm sort is an algorithm.
Algorithm An 'algorithm' is a method for solving a problem expressed as a finite sequence of instructions. Proof of correctness: always give the right answer and never give a wrong answer Proof of termination: always be completed in a finite number of steps, rather than in an infinite number
How fast can you sort? Permutation sort takes O(n * n!) time Can sort in O(n2) time Need at least O(n log n) time
How do you know problem is hard? If solving it takes too much time. We kind of felt that O(N! * N) is a bit much complexity How about O(N2)? O(N10)? Where do we draw the line? Meet the Computer Scientist Nightmare So “Polynomial” ~ “easy” & “exponential” ~ “hard” 2n eventually overtakes any nk however large k is.. How do we know if a problem is “really” hard to solve or it is just that I am dumb and didn’t know how to do better? 2n
Exponential growth n n2 n3 n10 2n 1 2 10 100 1000 1010 1024 10000 106 10100 ~1030 1000000 109 101000 ~10300 108 1012 1010000 ~103000 1020 1030 ~103000000000
How to explain to your boss as to why your program is so slow… I can't find an efficient algorithm, I guess I'm just too dumb. I can't find an efficient algorithm, because no such algorithm is possible. I can't find an efficient algorithm, but neither can all these famous people.
Homework Write a sorting program in any language you want, and post the solution on your blog. Should take a bunch of numbers as input. Should print them out in increasing order. Also let me know how much time it took you to do the assignment Deadline: Sunday 05 Sept 2010.