1 / 31

Problem of the Day

Problem of the Day. Bezout acquired 19 camels through his trading skill, “Of the collected camels,” it said in the late merchant’s will, “Exactly half go to my first son , Abdul, One-fourth to Wasim , one-fifth to Rasul , Call a wise man to distribute — don’t sell or kill .”

brina
Download Presentation

Problem of the Day

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. Problem of the Day Bezout acquired 19 camels through his trading skill,“Of the collected camels,” it said in the late merchant’s will,“Exactly half go to my first son, Abdul,One-fourth to Wasim, one-fifth to Rasul,Call a wise man to distribute — don’t sell or kill.” How does the Wise Man do it?

  2. Problem of the Day Bezout acquired 19 camels through his trading skill,“Of the collected camels,” it said in the late merchant’s will,“Exactly half go to my first son, Abdul,One-fourth to Wasim, one-fifth to Rasul,Call a wise man to distribute — don’t sell or kill.” How does the Wise Man do it?The Wise Man adds his own camel (making 20 to distribute)Abdul gets 10 (20 * 0.5)Wasim gets 5 (20 * 0.25)Rasul gets 4 (20 * 0.2) & Wise Man gets his camel back (20 – 10 – 5 – 4 = 1)

  3. CSC 212 – Data Structures Lecture 25: DeQues

  4. Stack Memory Aid Roses are red andviolets are blue Implementpush,peek,&pop And you’re a Stack too!

  5. Stack Interface public interface Stack<E> extends Collection {public Epeek()throws EmptyCollectionException;public Epop() throws EmptyCollectionException;public void push(E element); }

  6. Queue Memory Aid

  7. Queue Memory Aid It’s hard writing rhymes with enqueue, dequeue, and first

  8. Queue Memory Aid

  9. Queue ADT public interface Queue<E> extends Collection {public Efirst()throws EmptyCollectionException;public Edequeue() throws EmptyCollectionException;public void enqueue(E element); }

  10. Stacks vs. Queues • Access data with Stack in LIFO order • LastIn-First Out ordering is unfair (unless late) • Data accessed in Queue using FIFO order • FirstIn-First Out is first-come, first-served

  11. Stacks vs. Queues • Access data with Stack in LIFO order • LastIn-First Out ordering is unfair (unless late) • Data accessed in Queue using FIFO order • FirstIn-First Out is first-come, first-served Order read if Queue

  12. Stacks vs. Queues • Access data with Stack in LIFO order • LastIn-First Out ordering is unfair (unless late) • Data accessed in Queue using FIFO order • FirstIn-First Out is first-come, first-served Order read if Queue Order read if Stack

  13. Still Have Limits • Cannot access both sides of either Collection • Transplant waiting lists • Help center phone banks • My Grandpa dealing cards for money • Stack only works with one end • Add & remove from top of the Stack • Queuelimits how each side used • Front provides access& removal of elements • Must use the Queue’s end to add elements

  14. Deque ADT • Pronounced “deck” (like on a house) • Mnemonic for Double Ended QUEue • dequeue ≠ dequeand do not sound alike • Structure that provides access to both ends • Combines Stack & Queueconcepts • Is also able to add elements to start

  15. Deque Interface public interface Deque<E> extends Collection { /* first()*/ public EpeekFirst()throws EmptyCollectionException; /* peek()*/ public EpeekLast()throws EmptyCollectionException; /* dequeue()*/ public EremoveFirst()throws EmptyCollectionException; /* pop()*/ public EremoveLast()throws EmptyCollectionException; /* push() or enqueue()*/ public addLast(Eelem); /* brand new method!*/ public addFirst(Eelem); }

  16. VIPs versus Losers

  17. Linked-list based Deque • Class defines fields aliased to first & last nodes • Doubly-linked list enables O(1)time for all methods • Add elements by adding new Node at end • Move end node & set next/previous to remove element rear head

  18. Linked-list based Deque • Class defines fields aliased to first & last nodes • Doubly-linked list enables O(1)time for all methods • Add elements by adding new Node at end • Move end node & set next/previous to remove element rear head retVal

  19. Linked-list based Deque • Class defines fields aliased to first & last nodes • Doubly-linked list enables O(1)time for all methods • Add elements by adding new Node at end • Move end node & set next/previous to remove element rear head retVal

  20. Linked-list based Deque • Class defines fields aliased to first & last nodes • Doubly-linked list enables O(1)time for all methods • Add elements by adding new Node at end • Move end node & set next/previous to remove element rear head retVal

  21. Linked-list based Deque • Class defines fields aliased to first & last nodes • Doubly-linked list enables O(1)time for all methods • Add elements by adding new Node at end • Move end node & set next/previous to remove element rear head retVal

  22. Linked-list based Deque • Class defines fields aliased to first & last nodes • Doubly-linked list enables O(1)time for all methods • Add elements by adding new Node at end • Move end node & set next/previous to remove element rear head newElem

  23. Linked-list based Deque • Class defines fields aliased to first & last nodes • Doubly-linked list enables O(1)time for all methods • Add elements by adding new Node at end • Move end node & set next/previous to remove element rear head newNode newElem

  24. Linked-list based Deque • Class defines fields aliased to first & last nodes • Doubly-linked list enables O(1)time for all methods • Add elements by adding new Node at end • Move end node & set next/previous to remove element rear head newNode newElem

  25. Linked-list based Deque • Class defines fields aliased to first & last nodes • Doubly-linked list enables O(1)time for all methods • Add elements by adding new Node at end • Move end node & set next/previous to remove element rear head newNode newElem

  26. Linked-list based Deque • Class defines fields aliased to first & last nodes • Doubly-linked list enables O(1)time for all methods • Add elements by adding new Node at end • Move end node & set next/previous to remove element rear head

  27. Why Doubly-Linked? • Did you see why doubly-linked list is important? rear head

  28. Why Doubly-Linked? • Did you see why doubly-linked list is important? • New or next node aliased by Queue’s fields • Stack set up so we only ever move to next node rear head

  29. Why Doubly-Linked? • Did you see why doubly-linked list is important? • New or next node aliased by Queue’s fields • Stack set up so we only ever move to next node • Dequemovesforward&backward; needs dual links rear head

  30. Your Turn • Get into your groups and complete activity

  31. For Next Lecture • Project #1 is due by 11:59PM tomorrow • Can use 1 or both virtual extensions on this project • Check with me if uncertain how many you’ve used • Midterm #2will be in class on Monday

More Related