Stacks & Queues. Kuan-Yu Chen ( 陳冠宇 ) TR-212, NTUST

Similar documents
Queues. Kuan-Yu Chen ( 陳冠宇 ) TR-212, NTUST

Lesson 12: Angles Associated with Parallel Lines

Hash Functions. Kuan-Yu Chen ( 陳冠宇 ) TR-212, NTUST

Similar Polygons Date: Per:

Visit MathNation.com or search "Math Nation" in your phone or tablet's app store to watch the videos that go along with this workbook!

Eureka Math. Grade 7, Module 6. Student File_A. Contains copy-ready classwork and homework

Red-Black, Splay and Huffman Trees

Math 96--Radicals #1-- Simplify; Combine--page 1

File Organization. Kuan-Yu Chen ( 陳冠宇 ) TR-212, NTUST

Multi-way Search Trees

Syntax Analysis Top Down Parsing

Section 1: Introduction to Geometry Points, Lines, and Planes

Section 6: Triangles Part 1

Wisconsin Retirement Testing Preparation

Have students complete the summary table, and then share as a class to make sure students understand concepts.

Data Structure using C++ Lecture 04. Data Structures and algorithm analysis in C++ Chapter , 3.2, 3.2.1

CS 206 Introduction to Computer Science II

STACKS AND QUEUES. Problem Solving with Computers-II

recruitment Logo Typography Colourways Mechanism Usage Pip Recruitment Brand Toolkit

Lecture 3.3 Robust estimation with RANSAC. Thomas Opsahl

EC8393FUNDAMENTALS OF DATA STRUCTURES IN C Unit 3

Copy Material. Geometry Unit 1. Congruence, Proof, and Constructions. Eureka Math. Eureka Math

First Semester - Question Bank Department of Computer Science Advanced Data Structures and Algorithms...

Stacks. Chapter 5. Copyright 2012 by Pearson Education, Inc. All rights reserved

PA3 Design Specification

Assignment 3 Class XII (Computer Science 083) Topic Array

Tranont Mission Statement. Tranont Vision Statement. Change the world s economy, one household at a time.

Lesson 1: Why Move Things Around?

Reliability Considerations in Cyber-Power Dependent Systems

Some Applications of Stack. Spring Semester 2007 Programming and Data Structure 1

Growing Our Own Through Collaboration

Brand Guidelines October, 2014

Multi-view object segmentation in space and time. Abdelaziz Djelouah, Jean Sebastien Franco, Edmond Boyer

Eureka Math. Grade 7, Module 6. Student File_B Contains Exit Tickets, and Assessment Materials

BRAND STANDARD GUIDELINES 2014

CMSC 2833 Lecture Memory Organization and Addressing

Transform Extreme Point Multi-Objective Linear Programming Problem to Extreme Point Single Objective Linear Programming Problem by Using Harmonic Mean

Teacher Assignment and Transfer Program (TATP) On-Line Application Quick Sheets

BRAND BOOK. Copyright 2016 WashU Student Union Student Union Brand Guidebook 1

Visual Identity Guidelines. Abbreviated for Constituent Leagues

HEL HEL HEL HEL VETIC HEL VETIC HEL HEL VETICA HEL HEL ETICA ETIC VETIC HEL VETIC HEL HEL C VETICA ETI- HEL HEL VETI HEL VETICA VETIC HEL HEL VETICA

November 25, Mr. Paul Kaspar, PE City Engineer City of Bryan Post Office Box 1000 Bryan, Texas 77802

Unifi 45 Projector Retrofit Kit for SMART Board 580 and 560 Interactive Whiteboards

Sequence alignment is an essential concept for bioinformatics, as most of our data analysis and interpretation techniques make use of it.

How to Register for Summer Camp. A Tutorial

Stack Applications. Lecture 27 Sections Robb T. Koether. Hampden-Sydney College. Wed, Mar 29, 2017

"Charting the Course... CA-View Administration. Course Summary

PracticeAdmin Identity Guide. Last Updated 4/27/2015 Created by Vanessa Street

T10/05-233r2 SAT - ATA Errors to SCSI Errors - Translation Map

Lesson 1: Construct an Equilateral Triangle

The ABC s of Web Site Evaluation

Algorithms and Data Structures Exercise I

Eureka Math. Geometry, Module 5. Student File_A. Contains copy-ready classwork and homework

Teacher Assignment and Transfer Program (TATP) On-line Teacher Application Quick Sheets

CS 206 Introduction to Computer Science II

BRANDING AND STYLE GUIDELINES

FINAL EXAM REVIEW CH Determine the most precise name for each quadrilateral.

Stacks. Revised based on textbook author s notes.

Section 7: Triangles Part 2

MESSAGE FROM TRUSTED CHOICE

Sample Question Paper

HIM a. LCD error is present and there IS an ABN for the services: a. HIM will add the GA modifier b. Select Refresh Claim

Graphs and Linear Functions

Section 4: Introduction to Polygons Part 1

Formal Languages and Automata Theory, SS Project (due Week 14)

Polynomial Functions I

"Charting the Course... MOC A Planning, Deploying and Managing Microsoft Forefront TMG Course Summary


How to Register for Summer Camp. A Tutorial

Stacks. stacks of dishes or trays in a cafeteria. Last In First Out discipline (LIFO)

Stacks. Chapter 5. Copyright 2012 by Pearson Education, Inc. All rights reserved

Stack. 4. In Stack all Operations such as Insertion and Deletion are permitted at only one end. Size of the Stack 6. Maximum Value of Stack Top 5

Lesson 1: What Is Area?

Eureka Math. Geometry, Module 4. Student File_B. Contains Exit Ticket, and Assessment Materials

Postfix (and prefix) notation

Abstract Data Types. Stack. January 26, 2018 Cinda Heeren / Geoffrey Tien 1

Media Kit & Brand Guidelines

Lecture 4 Stack and Queue

Infix to Postfix Conversion

Industrial Control. 50 to 5,000 VA. Applications. Specifications. Standards. Options and Accessories. Features, Functions, Benefits.

"Charting the Course... Teradata SQL Course Summary

MFAS Geometry CPALMS Review Packet. Congruency Similarity and Right Triangles

Linear Data Structure

Industrial Control. 50 to 5,000 VA. Applications. Specifications. Standards. Options and Accessories. Features, Functions, Benefits.

Ascenium: A Continuously Reconfigurable Architecture. Robert Mykland Founder/CTO August, 2005

Shading II. CITS3003 Graphics & Animation

The Vertex Cover Problem. Shangqi Wu Presentation of CS 525 March 11 th, 2016

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

Brand Standards September 2016 CREATED BY M3 GROUP

The Bucharest University of Economic Studies. Data Structures. ADTs-Abstract Data Types Stacks and Queues

An Introduction to Trees

CS 354 Midterm 1a, 33.33% Monday, October 9th, 2000 Solution

Stack Abstract Data Type

U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2018 TRIMESTER 2 COMP 103 PRACTICE EXAM

Lecture Data Structure Stack

Brand Standards. V1 For Internal Use. Newcastle Systems Brand Standards 1

T.4 Applications of Right Angle Trigonometry

Solano Community College Academic Senate CURRICULUM COMMITTEE AGENDA Tuesday, May 1, :30 p.m., Room 503

infix expressions (review)

TABLE OF CONTENTS. 3 Intro. 4 Foursquare Logo. 6 Foursquare Icon. 9 Colors. 10 Copy & Tone Of Voice. 11 Typography. 13 Crown Usage.

Transcription:

Stacks & Queues Kuan-Yu Chen ( 陳冠宇 ) 2018/10/01 @ TR-212, NTUST

Review Stack Stack Permutation Expression Infix Prefix Postfix 2

Stacks. A stack is an ordered list in which insertions and deletions are made at one end called the top Given a stack SS = (aa 1, aa 2,, aa nn ) aa 1 is the bottom element aa nn is the top element aa nn aa ii is on top of element aa ii 1 add delete top aa nn aa nn aa nn 1 aa 2 aa 1 aa 2 aa 1 aa 2 aa 1 3

Stacks.. By the definition of stack, if we add the elements AA, BB, CC, DD, EE to the stack, in that order, then EE is the first element we delete from the stack Last-In-First-Out 4

Applications. System stack in the case of function calls 5

Applications.. System stack in the case of function calls 6

Applications For a recursive function, the stack can be used to store the processing status Given an Ackerman s function AA(mm, nn), please calculate AA(1,2) nn + 1, iiii mm = 0 AA mm, nn = AA mm 1,1, iiii nn = 0 AA mm 1, AA mm, nn 1, ooooooooooooooooo AA 1,2 = AA 0, AA 1,1 AA 1,1 = AA 0, AA 1,0 AA 1,0 = AA 0,1 AA(1,2) AA(1,1) AA(1,2) AA 0,1 = 2 AA(1,0) AA(1,1) AA(1,2) 7

Applications. For a recursive function, the stack can be used to store the processing status Given an Ackerman s function AA(mm, nn), please calculate AA(1,2) nn + 1, iiii mm = 0 AA mm, nn = AA mm 1,1, iiii nn = 0 AA mm 1, AA mm, nn 1, ooooooooooooooooo AA 1,2 = AA 0, AA 1,1 = AA 0,3 = 4 AA(1,2) AA 1,1 = AA 0, AA 1,0 = AA 0,2 = 3 AA 1,0 = AA 0,1 = 2 AA 0,1 = 2 AA(1,0) AA(1,1) AA(1,2) AA(1,1) AA(1,2) 8

Declare Implementation for Stack by Array. aa nn add delete top aa nn aa nn aa nn 1 aa 2 aa 1 aa 2 aa 1 aa 2 aa 1 9

Implementation for Stack by Array.. For push 10

Implementation for Stack by Array For pop 11

Implementation for Stack by Array. For display 12

Implementation for Stack by Array.. For peek 13

Prefix Expression Given a infix expression (AA + BB) CC (DD EE FF), please write down the prefix and postfix expressions Prefix prefix eeeeeeeeeeeeee postfix + CC DD infix AA BB EE FF +AAAAAA DD EEEE 14

Postfix Expression Given a infix expression (AA + BB) CC (DD EE FF), please write down the prefix and postfix expressions Postfix prefix eeeeeeeeeeeeee postfix + CC DD infix AA BB EE FF AAAA + CC DDDDDD 15

Algorithm to Convert Infix to Postfix. 16

Algorithm to Convert Infix to Postfix.. Take AA BB CC + DDDDD FF GG HH for example Infix Scanned Stack Postfix Expression ( A ( A - ( - A ( ( - ( A B ( - ( A B / ( - ( / A B C ( - ( / A B C + ( - ( + A B C / ( ( - ( + ( A B C / D ( - ( + ( A B C / D % ( - ( + ( % A B C / D E ( - ( + ( % A B C / D E 17

Algorithm to Convert Infix to Postfix... Take AA BB CC + DDDDD FF GG HH for example Infix Scanned Stack Postfix Expression E ( - ( + ( % A B C / D E * ( - ( + ( * A B C / D E % F ( - ( + ( * A B C / D E % F ) ( - ( + A B C / D E % F * / ( - ( + / A B C / D E % F * G ( - ( + / A B C / D E % F * G ) ( - A B C / D E % F * G / + * ( - * A B C / D E % F * G / + H ( - * A B C / D E % F * G / + H ) A B C / D E % F * G / + H * - 18

Algorithm to Convert Infix to Prefix 1 19

Algorithm to Convert Infix to Prefix 2. Take (AA BB CC) (AA KK LL) for example Step1: (LL KK AA) (CC BB AA) Step2: LLLLLL CCCC AA Step3: AA BBBB AAAAAA 20

Homeork1: Expression Convertor. Given a infix expression, please convert the expression to both prefix and postfix expressions The implementation must base on stack Please show the results step-by-step Please upload your source codes and a paper report to moodle TA will ask you to demo your program The hard deadline is 2018/10/15 8:00 Infix Scanned Stack Postfix Expression ( A ( A - ( - A ( ( - ( A B ( - ( A B / ( - ( / A B C ( - ( / A B C 21

Homeork1: Expression Convertor.. Given a infix expression, please convert the expression to both prefix and postfix expressions The maximum length of the input expression will always less than 30 Only five operators need to be considered +,,,, % The operands are capital letters (i.e., A~Z) Infix Scanned Stack Postfix Expression ( A ( A - ( - A ( ( - ( A B ( - ( A B / ( - ( / A B C ( - ( / A B C 22

Homeork1: Expression Convertor.. Given a infix expression, please convert the expression to both prefix and postfix expressions (AA BB CC) (AA KK LL) Prefix: AA BBBB AAAAAA Postfix: AAAAAA AAAA LL AA BB CC + DDDDD FF GG HH Prefix: AA + BBBB %DDDDDDDDDD Postfix: AAAAAA DDDDDDD GG +HH 23

Queue. A queue is an ordered list in which insertions take place at one end (rare) and deletions are made at the opposite end (front) Given a queue QQ = (aa 1, aa 2,, aa nn ) aa 1 is the front element aa nn is the rear element aa ii is behind element aa ii 1 aa nn add aa nn rear aa nn 1 front aa 2 aa 1 aa 2 aa 1 delete 24

Queue.. By the definition of queue, if we insert the elements AA, BB, CC, DD, EE in the order, then AA is the first element deleted from the queue First-In-First-Out 25

Job scheduling A fair method Applications Queue 26

Array Representation of Queues Queues can be easily represented using arrays Given a queue Insert an element Delete an element 27

Implementation for Queue by Array. Declare 28

Implementation for Queue by Array..? front rear 2 7 0 1 2 3 4 29

Implementation for Queue by Array... front rear 7 0 1 2 3 4 30

Implementation for Queue by Array. 31

Questions? kychen@mail.ntust.edu.tw 32