1 / 10

Tutorial 5 Stack & Queue, Midtest

Tutorial 5 Stack & Queue, Midtest. Stack. Last In First Out (LIFO) Stack implemented using Array with top pointer http://www2.latech.edu/~box/ds/Stack/Stack.html Stack implemented using Single Link List with head pointer Probably the best implementation to date?

eve-vinson
Download Presentation

Tutorial 5 Stack & Queue, Midtest

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. Tutorial 5Stack & Queue, Midtest

  2. Stack • Last In First Out (LIFO) • Stack implemented using Array with top pointer • http://www2.latech.edu/~box/ds/Stack/Stack.html • Stack implemented using Single Link List with head pointer • Probably the best implementation to date? • http://www.cosc.canterbury.ac.nz/people/mukundan/dsal/LinkListAppl.html TOP

  3. Queue • First In First Out (FIFO) • Queue implemented as Circular Array • http://maven.smith.edu/~streinu/Teaching/Courses/112/Applets/Queue/myApplet.html • Queue implemented as Single Link List with Tail Pointer • Head pointer (easy for insert/delete) for dequeue • Tail pointer (only easy for insert) for enqueue • This is because of the pointer directions • Probably the best implementation to date? FRONT BACK

  4. Student Presentation • T3 Main Backup • CaiJingfangChngJiajie, Colin Tan • Li HuanNurLiyanaBteRoslie • Zhang JianfeiTan Kar Ann • Tanvir Islam Jessica Chin ZetSze • T4 Main Backup • Choy QianNing, JLiewHui Sun • GohKhoonHiang Li Yawen • HanyenknoAfi Tan Peck Luan • Ng Xue Lin SherilynWong Suet Teng, Melissa • T5 Main Backup • JoyeetaBiswasOngKian An • TeoSim Yee Stephanie Tan Yan Hao • Wu Shujun Wang Ruohan • Liu Na Zheng Yang • T6 Main Backup • Zhang Chao Wang Shuling • Chua Yu Tong LauraRasheillaBte Rajah • Koh Yi Ting Brenda Low Wei Chen Gerard J • SiddharthaGanZhi Wei James Rule: Student in “Main” column has priority to answer the assigned question If the student sick/disappear/absent/cannot solve, etc2… the “backup” will take over. If both students are attending the session,I will create variants of the question for the “backup” students.

  5. Question 1 (Applications) • Show us 7 applications of Stacks • Show us 7 applications of Queues • Be creative!

  6. Question 2 (Stack: Reorder) • Get algorithm to reorder items using one stack! • Requires thinking on Stack operations: push, pop, top/seek • Derive patterns! • Target Sequence 1 = {1, 2, 3, 5, 4} • Target Sequence 2 = {2, 1, 4, 3, 5} • Target Sequence 3 = {5, 2, 4, 3, 1} • Target Sequence 4 = {1, 4, 3, 2, 5} Only Target Sequence 3 is impossible. See StackTest.java for details

  7. Question 3 (Stack for Sorting) • Find algorithm to sort items using two stacks! • Requires thinking on Stack operations: push, pop, top/seek • Hint: try sorting these simple numbers using two stacks: • {7, 5}  {5, 7} • {1, 5, 3}  {1, 3, 5} • {4, 3, 2, 1}  {1, 2, 3, 4} • Derive patterns and write your algorithm! • Hint: During the sorting process, one stack will have numbers in ascending order and the other in descending order. • See StackSort.java for details

  8. Question 4 (Queue) • What if Queue ADT is implemented using TailedLinkedListbut in different way! • Think about the pros and cons of this strategy! • The ADT Queue “dequeue” operation is performed by “delete head” and ADT Queue “enqueue” operation is performed by “insert from tail” in TailedLinkedList. • Modified operations: • Enqueue: insert from head  straightforward • Dequeue: delete from tail  hard, because adjusting tail pointer is difficult! • No pro, this modified operations are bad! • If you are presented with this kind of question during exam, do not hesitate to answer “there is no pro” rather than leaving your answer blank! • If you insist, you can say that this modified operations can easily tell you “what object is the 2nd last inserted object” …

  9. Student Presentation for Tut 6 • Check your email! • If I send you an email, it means that you are assigned to do next week’s questions…

  10. Midterm Test Tips • Priority: • Java Revisit: low • ADT: Likely embedded in Linked List/Stack/Queue question • Linked List: we spend two weeks here, most likely this appear as the only short question during midterm test • Stack and Queue: definitely appear • Try: • Mixing and matching various data structure implementations: variant of linked list, implementing stacks or queues using funny data structures, etc…

More Related