|
|
|
|
|||
Introduction to Algorithms and Data Structures, Spring 2005, Episode 1 | |||
|
|
|
||
|
|
Lecture, February 4Subject : Introduction (Slides). Sorting. InsertionSort. Correctness proofs with loop invariants. Running time estimates. Growth rates of functions. Theta-, Big-Oh-, and Omega-notation.Text : Browse pages 3–4, CLRS Chapter 1, Sections 2.1 and 2.2. Chapter 3. Browse Appendix A.1. Comment : In chapter 2 the algorithmic concepts are the most important. Focus in chapter 3 should be on the Big-Oh-notation. Time : Friday, February 4, 9:00 - 12:00. Room : 2A12 Assignments
The mandatory assignments should be handed in no later than February 16 at 13.00. The mandatory assigments should be placed in your teaching assistent box, or send to the TA by email. Programming assignmentsAssignment 1.1This assignment deals with an experimental study of the performance time of InsertionSort. In Java the performance can me measured using the method System.currentTimeMillis().Example: ... long t= System.currentTimeMillis(); sort(A); t = System.currentTimeMillis()-t; System.out.println("T= "+t); ... Here you find the program source for a program that measures the performance time for sorting 1000 integers.
Assignment 1.2[see also exercise CLRS 2.1-3 p. 21] In the lecture we have claimed that sorted data is more easy to handle automatically than unordered data. Exercises 1.2 and 1.3 let you perform an evaluation of this claim. Implement a function A[linear_search(A,x)]==xif You should not modify the array during execution. Remember that numbers in the array are unsorted. Assignment 1.3[see also exercise CLRS 2.3-5 p. 37] A BINARY-SEARCH is an efficient method of searching in the sorted array of elements a1,...,am. We begin searching from the middle element of the array. Let j be the index of this element. If aj equals the desired element x then return j and terminate. Otherwise if aj is greater than x then search recursively in the left sub-array: a1,...,aj-1. If aj is smaller than x then search recursively in the right sub-array: aj-1,...,am. If the sub-array to search is empty, then terminate returning -1. This algorithm serves as a foundation for many data structures, which we will be studied in the course later on. Implement a function Remember that you should not modify the array during search. Also
you should avoid copying fragments of arrays. Use recursion, or
better, a while loop and two integer variables Finally run linear_search and binary_search on randomly generated arrays of various sizes (including huge arrays) and draw a graph of execution times. Evaluate the results. |
|
|
|
|
last updated February 3, 2005 |