Data Structures and Algorithms in Java
Data Structures and Algorithms in Java
6th Edition
ISBN: 9781119278023
Author: Michael T. Goodrich; Roberto Tamassia; Michael H. Goldwasser
Publisher: Wiley Global Education US
bartleby

Concept explainers

Question
Book Icon
Chapter 6, Problem 1R
Program Plan Intro

Stack:

  • Stack is a non-primitive linear data structure.
  • It is a collection of data of any type where insertion and deletion of data take place at one end called as top of the stack.
  • As all the insertion and deletion happens from top of the stack or at one point, stack is also known as Last In First Out (LIFO) type of data structure.

Expert Solution & Answer
Check Mark

Explanation of Solution

Stack Operations:

Operations performed on the stack are as follows:

  • PUSH
    • Adds item to the collection and increases size of the stack.
  • POP
    • Returns the last item from collection and decreases the size of the stack.
  • TOP
    • Returns last item from the collection without removing it.

Current size of the Stack, S:

If 3 POP operations returned null, then only 7 POP operations out of 10 decrease the size of the stack. Therefore, the current size of stack is 18 elements since PUSH adds elements, TOP doesn't add or remove elements, and POP removes elements.

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
02:20
Students have asked these similar questions
Suppose an initially empty stack S has performed a total of 50 push operations, 31 peek operations, and 32 pop operations, 7 of which return to indicate an empty stack. What is the current size of S?
You are allowed to operate on a stack WORK and a temporary stack TEMP (ifneeded) supporting their ADT operations of PUSH (S,X), POP (S, X) andEMPTYSTACK (S) only, where X represents an element/variable to be pushed in orpopped out of the stack and S represents a stack. You are also permitted to use onevariable if needed to carry out the operations.i) Given n distinct random numbers that are to be pushed into WORK, how canyou find the minimum element that was pushed into it? You are permitted to use alone variable.ii) Given n distinct random numbers that are to be pushed into WORK, how canyou find the maximum element that was pushed into it, all the while ensuring thatthe elements stored in WORK are in their descending order with the maximumelement beginning at the bottom of stack? You are permitted to use a lone variableand a temporary stack TEMP.iii) Given an array A[1: n] of distinct random numbers how can you obtain thesorted list in the array, making use of stacks alone?
You are allowed to operate on a stack WORK and a temporary stack TEMP (ifneeded) supporting their ADT operations of PUSH (S,X), POP (S, X) andEMPTYSTACK (S) only, where X represents an element/variable to be pushed in orpopped out of the stack and S represents a stack. You are also permitted to use one variable if needed to carry out the operations. i) Given n distinct random numbers that are to be pushed into WORK, how canyou find the maximum element that was pushed into it, all the while ensuring thatthe elements stored in WORK are in their descending order with the maximumelement beginning at the bottom of stack? You are permitted to use a lone variableand a temporary stack TEMP.ii) Given an array A[1: n] of distinct random numbers how can you obtain thesorted list in the array, making use of stacks alone?

Chapter 6 Solutions

Data Structures and Algorithms in Java

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education