Data Structures, Algorithms, & Applications Richard Newman (based on course by Sartaj Sahni)
Clip Art Sources www.barrysclipart.com www.livinggraphics.com www.rad.kumc.edu www.graphicmaps.com
What The Course Is About Data structures : representation and manipulation of data. All programs manipulate data. So all programs represent data Data manipulation requires an algorithm. Data: Streets in a city. Mapquest. Manipulation: Do something with the data. Add a new street. Close a street. Make a street one way. Find route from your home to nearest gas station. Input/output data. Data representation: simple variables…int, float array variables… int [], float [] Others to be studied in this course. Algorithm…sequence of steps that results in the performance of a specific task (find nearest gas station to home).
What The Course Is About Algorithm design methods needed to develop programs that do the data manipulation. The study of data structures and algorithms is fundamental to Computer Science. What we do in this course will be used in most of the follow-up courses you will take. Essential to become expert in what we do this semester. Else, you will be handicapped in later courses.
Prerequisites Java Asymptotic Complexity Big Oh, Theta, and Omega notations Java review … Chapter 1 Performance Analysis … Chapter 2 Asymptotic complexity … Chapter 3
Web Site www.cise.ufl.edu/~nemo/cop3530/ www.cise.ufl.edu/cop3530sp04/ www.cise.ufl.edu/~sahni/cop3530/ Handouts, syllabus, text, source codes, exercise solutions, lectures, assignments, past exams, past exam solutions, TAs, etc. Check twice weekly (48 hr apart)
Assignments Assignment guidelines Submission procedures Do Assignment 0 by next Friday. Must follow guidelines and submission procedures. Else there will be chaos. Submit jar files via CourseWorX night before class, hardcopy in class. Design and code documentation required for TA to assist in debugging.
Source Codes Read download and use instructions. Must have Java 1.2 or higher. See ProgramIndex.htm, AllNames.html and other html files produced by Javadoc for Java codes.
Discussion Sections Go to any one TA will answer your questions TA will go through a few exercises from the book Web site lists what is done in each meeting of the discussion section M 8,9 T 8,9,11 – all in CSE-221 W 3 – in TUR 2346
Organization of Text Three parts Part I … Chapters 1-4, Background Part 2 … Chapters 5-17, Data Structures Part 3 … Chapters 18-22, Algorithms Each chapter … concepts + applications
Grades 25% for assignments 25% for each test (3 exams) Exam 1 – Feb 15 Exam 2 – Mar 31 Exam 3 – Apr 29 7:30 am
Grades (Rough Cutoffs) B+ >= 75% B >= 70% C+ >= 65% C >= 60% D+ >= 55% D >= 50%
Classic Problem: Sorting Rearrange a[0], a[1], …, a[n-1] into ascending order. When done, a[0] <= a[1] <= … <= a[n-1] 8, 6, 9, 4, 3 => 3, 4, 6, 8, 9 Strictly speaking, nondecreasing order: 2, 2, 3, 6, 8, 8, 10.
Sort Methods Insertion Sort Bubble Sort Selection Sort Count Sort Shaker Sort Shell Sort Heap Sort Merge Sort Quick Sort First 5 are simple (conceptually and to program). First 4 done in chapters 2 and 3. Shaker sort and shell sort are in the enrichment section of the text’s Web site. The remaining three are done in the algorithm design chapters of the text.
Insert An Element Given a sorted list/sequence, insert a new element Result 3, 5, 6, 9, 14
Insert an Element 3, 6, 9, 14 insert 5 Compare new element (5) and last one (14) Shift 14 right to get 3, 6, 9, , 14 Shift 9 right to get 3, 6, , 9, 14 Shift 6 right to get 3, , 6, 9, 14 Insert 5 to get 3, 5, 6, 9, 14
Insert An Element // insert t into a[0:i-1] int j; for (j = i - 1; j >= 0 && t < a[j]; j--) a[j + 1] = a[j]; a[j + 1] = t;
Insertion Sort Start with a sequence of size 1 Repeatedly insert remaining elements
Insertion Sort Sort 7, 3, 5, 6, 1 Start with 7 and insert 3 => 3, 7
Insertion Sort for (int i = 1; i < a.length; i++) {// insert a[i] into a[0:i-1] // code to insert comes here } Top-down approach to program development – pseudocode in comments
Insertion Sort for (int i = 1; i < a.length; i++) {// insert a[i] into a[0:i-1] int t = a[i]; int j; for (j = i - 1; j >= 0 && t < a[j]; j--) a[j + 1] = a[j]; a[j + 1] = t; } Turn pseudocode into code.
Correctness Program verification Testing Debugging Mathematical (logical) correctness Cleanroom development Testing Black box White (clear) box Debugging Strategies
Next – Lecture 2 Read 3.5 Complexity of insertion sort