Download presentation
Presentation is loading. Please wait.
1
Jeff West - Quiz Section 16
CSE 143 Section AD Quiz Section 16 8/9/2001 Jeff West - Quiz Section 16
2
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… 8/9/2001 Jeff West - Quiz Section 16
3
Jeff West - Quiz Section 16
Agenda Queue Examples From Last Time Circle Drawing Example Efficiency 8/9/2001 Jeff West - Quiz Section 16
4
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; } 8/9/2001 Jeff West - Quiz Section 16
5
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; } 8/9/2001 Jeff West - Quiz Section 16
6
Circle Drawing Example
The circle drawing program is downloadable from the section AD website under today’s date (8/9/2001). 8/9/2001 Jeff West - Quiz Section 16
7
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… 8/9/2001 Jeff West - Quiz Section 16
8
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(____) 8/9/2001 Jeff West - Quiz Section 16
9
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(____). 8/9/2001 Jeff West - Quiz Section 16
10
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(____). 8/9/2001 Jeff West - Quiz Section 16
11
Efficiency of Binary Search
Binary search deals with an array that is guaranteed to be in sorted order. 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? 8/9/2001 Jeff West - Quiz Section 16
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.