Course Overview CSE 331 Section 2 James Daly Syllabus • Found on class website: cse.msu.edu/~cse331 • Discussion on Piazza • Grades on D2L Grading • • • • • Two midterms exams (15% each) Final exam (25%) Homework (15%) Projects (25%) Class participation (5%) Homework / Projects • There will be about 5 homeworks and 4 projects over the semester • Homeworks are due in class on Thursdays • Projects due on Handin on Friday midnight • You may discuss with others, but you must do your own work • You are responsible for code you post online Goals • Teach basic data structures and algorithms • You should understand how and when to use each • Which structures are in common libraries • Notation for using them • Tradeoffs versus other structures • Quantify how good an algorithm is • Common methods for improving algorithms Array Lists • • • • Fixed size Random access Fast append Slow insert 1 2 3 4 / Language Class C++ vector C# List Java ArrayList Linked Lists • • • • 1 Variable size Sequential access Fast append and prepend Fast insert 2 3 Language Class C++ list C# LinkedList Java LinkedList / Stack • Access the top element • Both add and remove • Last In, First Out 4 3 Language Class C++ stack C# Stack Java ArrayDeque, LinkedList 2 1 Queue • Access the oldest item • Remove the head • Add to the tail • First In, First Out Language Class C++ queue C# Queue Java ArrayDeque, LinkedList, Queue (interface) 1 2 3 4 Example: Sorting • Input: A sequence of n numbers <a1, a2, …, an> • Output: a reordering <a1’, a2’, …, an’> such that a1’ ≤ a2’ ≤ a3’ ≤ … ≤ an’ • Example: 50 100 1 0 => 0 1 50 100 Insertion Sort 60 1 60 50 55 70 80 60 60 Insertion Sort 1 50 55 60 70 80 Insertion Sort 5 2 4 6 1 3 Insertion Sort 5 2 4 6 1 3 Insertion Sort 2 5 4 6 1 3 Insertion Sort 2 4 5 6 1 3 Insertion Sort 2 4 5 6 1 3 Insertion Sort 1 2 4 5 6 3 Insertion Sort 1 2 3 4 5 6 Insertion Sort Algorithm • InsertionSort(A): • for j = 2 to len(A): • key ← A[j] • i←j–1 • while i > 0 and A[i] > key: – A[i + 1] ← A[i] –i←i–1 • A[i + 1] ← key