Fundamental Data Structures: T1: Stack Implementation In this task, you will implement a stack data structure in Python. Create a Python class named Stack that will have the following methods: __init__(self): Initialize an empty stack. push(self, item): Push an item onto the stack. pop(self): Pop and return the top item from the stack. If the stack is empty, return an appropriate message. peek(self): Return the top item from the stack without removing it. If the stack is empty, return an appropriate message. is_empty(self): Check if the stack is empty and return True or False. size(self): Return the number of elements in the stack. T 2: Using the Stack In this task, you will use the stack you implemented to solve a common problem: checking if a string containing parentheses, brackets, and curly braces is balanced. Write a Python function is_balanced(expression) that takes a string containing parentheses, brackets, and curly braces and returns True if the symbols are balanced and False otherwise. You can use a stack to help with this task. T 3: Test your Stack Test your stack implementation and the is_balanced function with various test cases to ensure they work correctly. Submission Note: 1. Post the code “is_balanced function”, screenshots of output. Make sure your code is executable.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Fundamental Data Structures:

T1: Stack Implementation In this task, you will implement a stack data structure in Python.
Create a Python class named Stack that will have the following methods:
__init__(self): Initialize an empty stack.
push(self, item): Push an item onto the stack.
pop(self): Pop and return the top item from the stack. If the stack is empty, return an appropriate message.
peek(self): Return the top item from the stack without removing it. If the stack is empty, return an appropriate message.
is_empty(self): Check if the stack is empty and return True or False.
size(self): Return the number of elements in the stack.
T 2: Using the Stack In this task, you will use the stack you implemented to solve a common problem: checking if a string containing parentheses, brackets, and curly braces is balanced.
Write a Python function is_balanced(expression) that takes a string containing parentheses, brackets, and curly braces and returns True if the symbols are balanced and False otherwise.
You can use a stack to help with this task.
T 3: Test your Stack Test your stack implementation and the is_balanced function with various test cases to ensure they work correctly.


Submission Note:
1. Post the code “is_balanced function”, screenshots of output. Make sure your code is executable.  

Expert Solution
steps

Step by step

Solved in 7 steps with 1 images

Blurred answer
Knowledge Booster
Stack
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education