Tutorial 5 Stack & Queue, Midtest. Last In First Out (LIFO) Stack implemented using Array with top pointer –http://www2.latech.edu/~box/ds/Stack/Stack.htmlhttp://www2.latech.edu/~box/ds/Stack/Stack.html.

Slides:



Advertisements
Similar presentations
Stacks and Queues. Not really data structures – More of an enforcement of policy – Can be implemented using an array or linked list – Can store just about.
Advertisements

Stacks using Linked Lists. Stack Data Structure As we already know, stacks are linear data structures. This means that their contexts are stored in what.
Data Structure HKOI training /4/2010 So Pak Yeung.
§3 The Stack ADT 1. ADT A stack is a Last-In-First-Out (LIFO) list, that is, an ordered list in which insertions and deletions are.
Review of Stacks and Queues Dr. Yingwu Zhu. Our Focus Only link-list based implementation of Stack class Won’t talk about different implementations of.
Stacks, Queues, and Deques. 2 A stack is a last in, first out (LIFO) data structure Items are removed from a stack in the reverse order from the way they.
 Abstract Data Type Abstract Data Type  What is the difference? What is the difference?  Stacks Stacks  Stack operations Stack operations  Parsing.
Sorting (2nd part) & Binary Search Tree
Stacks.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (4) Data Structures 11/18/2008 Yang Song.
COMP 110 Introduction to Programming Mr. Joshua Stough.
Stacks, Queues, and Deques
1 Stack Data : a collection of homogeneous elements arranged in a sequence. Only the first element may be accessed Main Operations: Push : insert an element.
Stacks, Queues, and Deques. A stack is a last in, first out (LIFO) data structure –Items are removed from a stack in the reverse order from the way they.
Algorithms and Data Structures Representing Sequences by Arrays and Linked Lists.
Important Problem Types and Fundamental Data Structures
Stacks, Queues, and Deques
Tutorial 5 Linked List Variations, Stack, & Queue.
Tutorial 7 Sorting & Complexity Analysis (Almost) always asked in exam! e.g. a. Derive algorithm for this problem! b. What is the time complexity of your.
Data Structures Winter What is a Data Structure? A data structure is a method of organizing data. The study of data structures is particularly important.
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 5: Stacks and Queues.
Stacks and queues Basic operations Implementation of stacks and queues Stack and Queue in java.util Data Structures and Algorithms in Java, Third EditionCh04.
Stacks and Queues Introduction to Computing Science and Programming I.
Adapted from instructor resources Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights.
Tutorial 4 Linked List, Stack, & Queue. Linked List: Revision The concept of ADT List ADT List using Array –Pro & cons  Discussed in T02Q3 and today.
September 05 Kraemer UGA/CSCI 2720 Lists – Part I CSCI 2720 Eileen Kraemer The University of Georgia.
Data Structures (part 2). Stacks An Everyday Example Your boss keeps bringing you important items to deal with and keeps saying: “Put that last ‘rush’
Tutorial 10 Heap & Priority Queue. Heap – What is it? Special complete binary tree data structure –Complete BT: no empty node when checked top-down (level.
Final Exam Review CS Total Points – 60 Points Writing Programs – 50 Points Tracing Algorithms, determining results, and drawing pictures – 50.
Foundation of Computing Systems Lecture 3 Stacks and Queues.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
Cousin of the Stack.  An abstract data type (container class) in which items are entered at one end and removed from the other end  First In First.
1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.
Stacks and Queues. Announcements USACO Open competition results are out o Congrats to Johnny for scoring 2nd in the US USACO Finalists are also announced.
Tutorial 3 - Linked List. Linked List: Revision The concept of ADT List ADT List using Array –Pro & cons  Discussed in T02Q3 and today in Q1! ADT List.
Understanding General Software Development Lesson 3.
Data Structures. Abstract Data Type A collection of related data is known as an abstract data type (ADT) Data Structure = ADT + Collection of functions.
April 27, 2017 COSC Data Structures I Review & Final Exam
Linear Data Structures
Give Eg:? Queues. Introduction DEFINITION: A Queue is an ordered collection of element in which insertions are made at one end and deletions are made.
Data Structures David Kauchak cs302 Spring Data Structures What is a data structure? Way of storing data that facilitates particular operations.
Stacks and Queues CMSC 201. Stacks and Queues Sometimes, when we use a data-structure in a very specific way, we have a special name for it. This is to.
Final Exam Review CS Total Points – 20 Points Writing Programs – 65 Points Tracing Algorithms, determining results, and drawing pictures – 50.
Exam 2 Review CS 3358 Data Structures. 90 Total Points – 50 Points Writing Programs – 25 Points Tracing Algorithms, determining results, and drawing pictures.
Required Background for ECOE 556. What do I need to catch up with? Basic data structures (Chapter 10) –Stack –Queue –Linked list –Array –Records (e.g.
List Structures What is a list? A homogeneous collection of elements with a linear relationship between the elements linear relationship - each element.
Stack, Queues, and Priority Queues: Linked List Based
1 Lecture 9: Stack and Queue. What is a Stack Stack of Books 2.
Chapter 3 Lists, Stacks, Queues. Abstract Data Types A set of items – Just items, not data types, nothing related to programming code A set of operations.
1 Data Organization Example 1: A simple text editor –Store the text buffer as a list of lines. –How would we implement the UNDO operation? Example 2: Parsing.
CSC 172 DATA STRUCTURES. A TALE OF TWO STRUCTURES.
Queues.
Week 4 - Monday CS221.
G.PULLAIAH COLLEGE OF ENGINEERING AND TECHNOLOGY
G64ADS Advanced Data Structures
Set Collection A Bag is a general collection class that implements the Collection interface. A Set is a collection that resembles a Bag with the provision.
Chapter 15 Lists Objectives
March 29 – Testing and Priority QUeues
CSC 172 DATA STRUCTURES.
Principles of Computing – UFCFA3-30-1
Exam 2 Review CS 3358 Data Structures.
Stacks, Queues, and Deques
Exam 2 Review CS 3358 Data Structures.
Stacks, Queues, and Deques
אחסון (אירגון) מידע DATA DATA DATA Link Link Link … …
Exam 2 Review CS 3358 Data Structures.
Queues A first-in, first-out or FIFO data structure.
Mutable Data (define mylist (list 1 2 3)) (bind ((new (list 4)))
Data Structures and Algorithms for Information Processing
Stacks, Queues, and Deques
Presentation transcript:

Tutorial 5 Stack & Queue, Midtest

Last In First Out (LIFO) Stack implemented using Array with top pointer – Stack implemented using Single Link List with head pointer –Probably the best implementation to date? – Stack TOP

Queue First In First Out (FIFO) Queue implemented as Circular Array – 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? FRONTBACK

Student Presentation T3MainBackup 1.Cai JingfangChng Jiajie, Colin Tan 2.Li HuanNur Liyana Bte Roslie 3.Zhang JianfeiTan Kar Ann 4.Tanvir IslamJessica Chin Zet Sze T4MainBackup 1.Choy Qian Ning, JLiew Hui Sun 2.Goh Khoon HiangLi Yawen 3.Hanyenkno AfiTan Peck Luan 4.Ng Xue Lin SherilynWong Suet Teng, Melissa T5MainBackup 1.Joyeeta BiswasOng Kian An 2.Teo Sim Yee StephanieTan Yan Hao 3.Wu ShujunWang Ruohan 4.Liu NaZheng Yang T6MainBackup 1.Zhang ChaoWang Shuling 2.Chua Yu Tong LauraRasheilla Bte Rajah 3.Koh Yi Ting BrendaLow Wei Chen Gerard J 4.SiddharthaGan Zhi Wei James 4 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.

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

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

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 7

Question 4 (Queue) What if Queue ADT is implemented using TailedLinkedList but 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 2 nd last inserted object” … 8

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

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…