1 / 13

Agenda

Agenda. See schedule HW5 (mini-programming project) due Next Wed. 16th Quiz 6 (double quiz- 50 minutes) will be Next Mon. 14th. Chapter 3. Data Structures Stacks & Queues Array vs. Linked Lists Resizable arrays Binary Search leads to Binary Trees Priority Queues lead to Binary Heaps.

abiola
Download Presentation

Agenda

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Agenda • See schedule • HW5 (mini-programming project) due Next Wed. 16th • Quiz 6 (double quiz- 50 minutes) will be Next Mon. 14th

  2. Chapter 3 • Data Structures • Stacks & Queues • Array vs. Linked Lists • Resizable arrays • Binary Search leads to Binary Trees • Priority Queues lead to Binary Heaps

  3. Stacks & Queues • Stacks • FILO (First In – Last Out) • O(1) push • O(1) pop • Ensuring efficient push and pop means that iteration may not be possible.

  4. Stacks & Queues • Queues • FIFO (First In – First Out) • O(1) push or enqueue • O(1) pop or dequeue • Ensuring efficient push and pop means that iteration may not be possible.

  5. Queue q; Stack s1, s2; q.push(1) s1.push(2) s2.push(3) q.push(s2.pop()) q.push(4) s2.push(5) s1.push(6) s2.push(q.pop()); s1.push(s2.pop()); s2.pop() s1.push(s2.pop()); Stacks & Queues

  6. Arrays Constant-time access of kth item Binary search can be implemented on sorted arrays O(n) insertion O(n) deletion O(n) merging and resizing Linked List O(n)-time to access kth item on average Binary search can NOT be implemented on sorted linked lists O(1) insertion O(1) deletion O(1) merging Arrays vs. Linked Lists

  7. Resizable Arrays • Given an array with a capacity of M • Insert N1 items • What if N1 > M? • Resize array to N1 (stupid) • Resize array to 2*N1 (smart) • Why?

  8. Resizable Arrays Insertions Copies Total 1 0 1 i m i 1 1 2 1 2 3 m m i m m m i 1 3 4 m m m m i 1 4 5 m m m m m i 1 5 6 Sum 21

  9. Resizable Arrays Ins Copies Total 1 1 i m i 1 1 2 1 1 i m m m i 1 3 4 i 1 1 i 1 1 Sum 10

  10. Binary Trees • Tries to combine binary search with the advantages of linked lists.

  11. Binary Trees http://www.cs.jhu.edu/~goodrich/dsa/trees/btree.html • Insertion = Find + Raw Insert • O(log n) + O(1) = O(log n) • Deletion = Find + Raw Delete + Find Replacement • O(log n) + O(1) + O(log n) = O(log n)

  12. Binary Heaps • Arise from priority queues • Enqueue should be as efficient as possible • Dequeue will always remove the minimum/maximum item.

  13. Binary Heap http://ciips.ee.uwa.edu.au/~morris/Year2/PLDS210/heaps.html

More Related