CS2204 Homework: Balanced Brackets (Solution)

$ 29.99
Category:

Description

Objectives
Demonstrate a use case for stacks
Work with the collections.deque data type Have a rest week
Background
In this very brief assignment you need to implement a single task/function to decide if a string ( expr ) contains a balanced set of brackets.
There are three types of brackets with matching (opening and closing) character pairs: [] , {} , and () .
Two brackets are considered to be a matched pair if the an opening bracket occurs to the left of a closing bracket of the exact same type. A matching pair of brackets is not balanced if the set of brackets it encloses are not matched.
The expr string can contain arbitrary characters. The non-bracket characters can be safely ignored. The sequence of brackets is balanced if the following conditions are met:
It contains no unmatched brackets.
The subset of brackets enclosed within the confines of a matched pair of brackets is also a
matched pair of brackets.
Examples:
{[()]} is balanced
{[(])} is not balanced
({X}(A[++][–])A)[hello](world) is balanced
Tasks
You need to finish the brackets.py source file. Note: you can use the simple test code provided at the end of the file. Feel free to change/add/delete any testing code. The outputs of this testing code are not going to be graded. The validator program will use your code directly.
1. Implement the is_balanced function as described above and in the documentation string.
Please, try to use the collections.deque datatype as a stack using its .append() / .pop() or the .appendleft() / .popleft() pairs of methods.
Grading
Penalties
Points will be deducted if you fail to set __author__ variable (-10 pts) and for each PEP 8 style errors (-1 pt for each) in your program.
Submission
Please, upload the final version of the following file(s) (and only those files) to Brightspace:
brackets.py

Reviews

There are no reviews yet.

Be the first to review “CS2204 Homework: Balanced Brackets (Solution)”

Your email address will not be published. Required fields are marked *