110 likes | 239 Views
CSE 143 Section AD. Quiz Section 16. Announcements. Quiz – Stacks, Queues, Efficiency Homework 5 Demo sign-up… Final Review Sessions next Wednesday and Thursday nights – most likely 7pm both nights, location TBA 8 more days until our summer vacation…. Agenda. Queue Examples From Last Time
E N D
CSE 143 Section AD Quiz Section 16 Jeff West - Quiz Section 16
Announcements • Quiz – Stacks, Queues, Efficiency • Homework 5 Demo sign-up… • Final Review Sessions next Wednesday and Thursday nights – most likely 7pm both nights, location TBA • 8 more days until our summer vacation… Jeff West - Quiz Section 16
Agenda • Queue Examples From Last Time • Circle Drawing Example • Efficiency Jeff West - Quiz Section 16
Copy Constructor FlightQueue::FlightQueue(FlightQueue& other) { front = back = NULL; Node* curOfOther = other.front; while(curOfOther != NULL) { insert(curOfOther -> myFlight); curOfOther = curOfOther -> next; } } Jeff West - Quiz Section 16
insert void FlightQueue::insert(const Flight& newFlight) { Node* addMe = new Node; addMe -> myFlight = newFlight; addMe -> next = NULL; if(front == NULL) front = back = addMe; else { back -> next = addMe; back = addMe; } } Jeff West - Quiz Section 16
Circle Drawing Example • The circle drawing program is downloadable from the section AD website under today’s date (8/9/2001). Jeff West - Quiz Section 16
Efficiency • The idea is to get the “big picture”… • If you are running some function on an array of N elements, what does the running time look like… • Drop the lowest terms and constants to get the “big picture”… • Take the worst case… Jeff West - Quiz Section 16
Efficiency Examples • N3 + 2N + 5 = O(N3) • 9N5 + 8N4 + 3N + 17 = O(N5) Heck, what about these ones? N4 + 18N! + 12N3 = O(____) 2N + 12N – 19 = O(____) Jeff West - Quiz Section 16
Efficiency of a Nested Loop for(int i = 0; i < size; i++) for(int j = 0; j < 100; j++) for(int k = j; k < size; k++) cout << “Argh, what fun”; Total cost is O(____) + O(____) + O(____) The algorithm grows like O(____). Jeff West - Quiz Section 16
Efficiency of Linear Search int Find(int A[], int N, int x) { for(int i = 0; i < N; i++) { if(A[i] == x) return i; return –1; } A linear search like this grows like O(____). Jeff West - Quiz Section 16
Efficiency of Binary Search Binary search deals with an array that is guaranteed to be in sorted order. 1 19 27 36 49 57 62 How much extra effort does it take to search if you double the size of the array? How much effort is saved if you halve the size of the array? Jeff West - Quiz Section 16