Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Lecture 15: Big O Notation (Wednesday) Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science Test See Web for Details Don’t be deleted!

Similar presentations


Presentation on theme: "1 Lecture 15: Big O Notation (Wednesday) Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science Test See Web for Details Don’t be deleted!"— Presentation transcript:

1 1 Lecture 15: Big O Notation (Wednesday) Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science Test See Web for Details Don’t be deleted! Tuition fees are due.

2 2 Revision - Circular Linked Lists Beer Wine Milk head Textbook, pp. 187ff

3 3 Dummy Head Nodes Textbook, pp. 189ff Wine Milk head

4 4 StackQueue FIFO First in First Out LIFO Last in First Out

5 5 Queue ADT void createQueue ( ) boolean isEmpty ( ) void enqueue ( Object newItem ) Object dequeue () void dequeueAll () Object peek () Textbook, p. 299

6 6 Queues Basic ADT Queue Operations "Circular" Array Implementation Linked List Implementation "Circular" Linked List Implementation Queue ADT implement with List ADT

7 7 Array Implementation items: 153 0 front: 0123 4567 Textbook, pp. 306ff 2 back:

8 8 0 1 2 34 5 6 7 153 0123 4567 3 5 1 Textbook, pp. 306ff

9 9 0 1 2 34 5 6 7 3 5 1 “Circular Array” – Go clockwise from front to back. items: 0 front: 2 back: Java Code, Textbook, pp. 308ff

10 10 0 1 2 34 5 6 7 33 56 11 List the items in the queue in front to back order. items: 6 front: 1 back: 12211298 76 39 12

11 11 0 1 2 34 5 6 7 33 56 11 What does the picture look like after executing enqueue(13) followed by dequeue(), followed by another dequeue()? items: 6 front: 1 back: 12211298 76 39 12

12 0 1 2 34 5 6 7 33 56 11 How can we tell when the queue is full? How can we tell when the queue is empty? items: 6 front: 1 back: 12211298 76 39 12

13 13 Queues Basic ADT Queue Operations "Circular" Array Implementation Linked List Implementation "Circular" Linked List Implementation Queue ADT implement with List ADT

14 14 Linked List Implementation 3 5 1 firstNode Textbook, pp. 302ff, lastNode

15 15 Circular Linked List 3 5 1 Java code, textbook, pp. 305ff, lastNode

16 16 ADT List Implementation Java Code, Textbook, pp. 263ff 1. 1 2. 5 3. 3 4. 5. 6.

17 17 Algorithm Efficiency Challenges in Measuring Efficiency Counting Operations Growth Rates of Functions Big O Notation Examples General Rules

18 18 public Node reverseListWithoutSizeGiven(Node head){ //what is this scenario & what do you do here? if(head == null){ //…} //what is this scenario & what do you do here? elseif(head.getNext() == null){ //…} //what is this scenario & is the solution correct? else{ Node prev = head; Node curr = prev.getNext(); head.setNext(null); while(curr != null){ prev = curr; curr = prev.getNext(); prev.setNext(head); head = prev; } return head; } Solution (for discussion) to question given for homework yesterday.

19 19 Challenges


Download ppt "1 Lecture 15: Big O Notation (Wednesday) Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science Test See Web for Details Don’t be deleted!"

Similar presentations


Ads by Google