1 / 26

Stack & Queue

Stack & Queue. Stack is an abstract data type and data structure based on the principle of Last In First Out(LIFO).Queue is an ordered collection of items which is based on the principle of First In First Out(FIFO). Course Name: Networking Level(UG/PG): UG

borna
Download Presentation

Stack & Queue

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. Stack & Queue Stack is an abstract data type and data structure based on the principle of Last In First Out(LIFO).Queue is an ordered collection of items which is based on the principle of First In First Out(FIFO). • Course Name: Networking Level(UG/PG): UG • Author(s) : Phani Swathi Chitta • Mentor: Aruna Adil *The contents in this ppt are licensed under Creative Commons Attribution-NonCommercial-ShareAlike 2.5 India license

  2. Learning Objectives After interacting with this Learning Object, the learner will be able to: • Explain the working operations of Stack and Queue

  3. Definitions of the components/Keywords: • Stack: • A stack is an ordered list in which all insertions and deletions are made at one end, called the top. • A stack can have any abstract data type as an element, but is characterized by two fundamental operations, called push and pop. • The push operation adds a new item to the top of the stack, or initializes the stack if it is empty. If the stack is full and does not contain enough space to accept the given item, the stack is then considered to be in an overflow state. • The pop operation removes an item from the top of the stack. A pop either reveals previously concealed items, or results in an empty stack, but if the stack is empty then it goes into underflow state (It means no items are present in stack to be removed). • A stack pointer is the register which holds the value of the stack. The stack pointer always points the tops value of the stack. • A stack is a restricted data structure, because only a small number of operations are performed on it. • Elements are removed from the stack in the reverse order to the order of their addition. 1 2 3 4 5

  4. Definitions of the components/Keywords: 1 • Stack example: Plates kept over each other (Stack of plates). • Stack Applications: • 1. Matching Balancing Parentheses • 2. Evaluating a postfix expression • 3. Depth first search of graphs • Queue: • A queue is an ordered list in which all insertions take place at one end, the rear, while all deletions take place at the other end, the front. • The elements are removed in the order of their insertion • Head pointer always points to the front of the queue, from where elements can be removed • Tail pointer always points to the end of the queue, where a new element can be inserted • Queue Examples: • 1. People standing in a queue for reservation • 2. Operating systems maintain a queue of processes that are ready to execute 2 3 4 5

  5. Definitions of the components/Keywords: 1 • Glossary: • Data Structure – A data structure is a specialized format for organizing and storing data. General data structure types include the array, the file, the record, the table, the tree and so on. • In programming, a data structure may be selected or designed to store data for the purpose of working on it with various algorithms. • Stack – A stack is an ordered set in which all insertions and deletions are made at one end called stack pointer S. • Abstraction – Abstraction is the process of taking away or removing characteristics from something in order to reduce it to a set of essential characteristics. • Object - An object is a software bundle of variables and related methods • Element – It defines the data object or item that is inserted at the top of the stack or head of queue. • List – List is an ordered group of similar types of objects or items. • Ordered List – List is a collection of similar types of objects or items that is having a specific numerical order or ranking. • Stack Pointer S – It always points to the top element of the stack that can be removed. • Push – It inserts the given item at the top of the stack. • Pop – It removes the top most element from the stack. 2 3 4 5

  6. Definitions of the components/Keywords: 1 • Glossary: • Pointer Value – It displays the value of the pointer S of the stack. • Stack Overflow – It defines the error, when tried to push into a fully filled stack. • Stack Underflow – It defines error, when tried to pop from an empty stack. • Queue – A queue is an ordered set in which all insertions take place at one end, the Tail, while all deletions take place at the other end, the Head. • Tail – It always points to the value of the pointer Tail (T) of the queue, where a new element can be inserted. • Head - It always points to the value of the pointer Head (H) of the queue, from where elements can be removed. • Pointers Value – It displays the value for the pointer Head (H) and Tail (T) of the queue. • Enqueue – It inserts the given item at the location pointed by pointer Tail (T). • Dequeue – It removes the element which is pointed by pointer Head (H). • Queue Overflow – It defines the error, when tried to push into a fully filled queue. • Queue Underflow – It defines error, when tried to pop from an empty queue. 2 3 4 5

  7. Master Layout 1 1 Stack Queue 2 Fig. A Fig. B 3 • Give two buttons STACK and QUEUE to select the operation • Give PAUSE and RESTART buttons • Give dropdown box to select the size from 1- 10 and the default size is 5 • Give a box to enter the value of the item 4 5

  8. Step 1: Stack 1 2 3 4 5

  9. Step 2: 1 2 3 4 5

  10. Step 3: 1 “ STACK IS IN OVERFLOW STATE BECAUSE IT IS FULL” 2 3 4 5

  11. Step 4: 1 2 3 4 5

  12. Step 5: 1 2 3 4 5

  13. Step 6: 1 • “ STACK IS IN UNDERFLOW STATE BECAUSE IT IS EMPTY” 2 3 4 5

  14. Step 7: Queue 1 2 3 4 5

  15. Step 8: 1 2 3 4 5

  16. Step 9: 1 “ QUEUE IS IN OVERFLOW STATE BECAUSE IT IS FULL” 2 3 4 5

  17. Step 10: 1 2 3 4 5

  18. Step 11: 1 2 3 4 5

  19. Step 12: 1 • “ QUEUE IS IN UNDERFLOW STATE BECAUSE IT IS EMPTY” 2 3 4 5

  20. Electrical Engineering Slide 1 Slide 3 Slide 21-25 Slide 26 Introduction Definitions Analogy Test your understanding (questionnaire)‏ Lets Sum up (summary)‏ Want to know more… (Further Reading)‏ Interactivity: In this LO demo itself is interactive session. Try it yourself 20 Credits

  21. Questionnaire 1 1. If the characters ‘D’, ‘C’, ‘B’, ‘A’ are pushed in a stack(in that order), and then popped one at a time, in what order will they be removed? Answers: a) ACBD b) ABDC c) ABCD d) None 2 3 4 5

  22. Questionnaire 1 2. If the characters ‘D’, ‘C’, ‘B’, ‘A’ are inserted/enqueued in a queue(in that order), and then deleted/dequeued one at a time, in what order will they be removed? Answers: a) ABCD b) DCBA c) DCAB d) CDBA 2 3 4 5

  23. Questionnaire 1 3. One example of stack operation: Answers: a) Luggage checking in airports b) CDs in a case 2 3 4 5

  24. Questionnaire 1 4. One example of queue operation: Answers: a) Luggage checking in airports b) CDs in a case 2 3 4 5

  25. Questionnaire 1 5. The operation for adding an entry to a stack is traditionally called : Answers: a) add b) append c) insert d) push 2 3 4 5

  26. Links for further reading Reference websites: http://en.wikipedia.org/wiki/Stack_%28abstract_data_type%29 http://en.wikipedia.org/wiki/Queue_%28data_structure%29 http://www.cmpe.boun.edu.tr/~akin/cmpe223/chap2.htm http://www2.roguewave.com/support/docs/hppdocs/stdug/10.html Books:

More Related