Question

Give a real world CS problem that can be solved using stacks or queues faster or easier. Please explain how the problem can b
0 0
Add a comment Improve this question Transcribed image text
Answer #1

One of the real world problem that can solved using Stack is Checking whether the paranthesis is balanced or not in a Code editor.

For example "{}" this is an example of a balanced paranthesis.Since the stack is last in First out Data structure.This property is used to solve the above problem as in the case of balanced parantheses opening parantheses is followed by its closing counterpart.If that is not the case then the Parantheses is not balanced.

To solve this problem using stack we will insert the opening parantheses into the stack and when the closing parantheses is encountered we will check the top of the stack if that corresponds to the same opening parantheses then we will pop the stack.

else we will return false.

At the end of parsing the document we will see if the stack is empty or not,If it is not empty then that means parantheses is not balanced.

If stack is not used for this problem then this would become tedious as we have to keep track of individual opening parantheses and when ever closing parantheses is encountered then we have to check the previous parantheses.This can be done using arrays also.But the computation would become bit complicated.

Add a comment
Know the answer?
Add Answer to:
Give a real world CS problem that can be solved using stacks or queues faster or...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 5. (34 pts) Stacks and Queues a. Stacks and queues are similar and different. For each of stack a...

    5. (34 pts) Stacks and Queues a. Stacks and queues are similar and different. For each of stack and queue, give a drawing showing how each would be stored in an array and a linked list. Use your first name (or usual nickname) as the data put into the container as an example for your pictures. Label the accessible element. (4 pictures; 16 pts) the text and lecture. (10 pts) You will not receive full credit without appropriate stack pictures....

  • Queues and Stacks Purpose: To review queues and stacks in Java, and to use the built-in...

    Queues and Stacks Purpose: To review queues and stacks in Java, and to use the built-in Stack class and Queue interface. The Stack class is a generic class containing these methods: public void push(E value) - pushes a new value onto the Stack public E pop() - pops the next value off of the stack and returns it; throws EmptyStackExceptionl if stack is empty public E peek() - returns the next value on the Stack but does not pop it...

  • Overview For this assignment, we will practice using stacks and queues. In this exercise, you will...

    Overview For this assignment, we will practice using stacks and queues. In this exercise, you will create two stacks and a queue to keep track of cars using a parking lot. We will use the nature of the stacks and queues to solve the problem. Specifications Rules FIU has opened a new valet parking lot next to the PC building that requires a special decal to park. If the car does not have the correct parking decal, the driver should...

  • Overview For this assignment, we will practice using stacks and queues. In this exercise, you will...

    Overview For this assignment, we will practice using stacks and queues. In this exercise, you will create two stacks and a queue to keep track of cars using a parking lot. We will use the nature of the stacks and queues to solve the problem. Specifications Rules FIU has opened a new valet parking lot next to the PC building that requires a special decal to park. If the car does not have the correct parking decal, the driver should...

  • 3) Stacks vs Queues: a) A Circular Array is a common data structure for a buffer...

    3) Stacks vs Queues: a) A Circular Array is a common data structure for a buffer (a type of queue). Why is this advantageous over a regular array? (Hint: think about common queue operations and what they do to an array). b) Show a traversal of the following tree using a stack: 26 1 25 2 17 3 2. (19 7 1 (The numbers under the bubbles are a node number, not the data. ) c) Why would using a...

  • PLEASE DONT COPY PASTE EXISTING SOLUTIONS Practice problem on stacks and queues. Thanks :) Write a...

    PLEASE DONT COPY PASTE EXISTING SOLUTIONS Practice problem on stacks and queues. Thanks :) Write a method called divideStack that takes a stack of integers as a parameter and divides it into negatives and positives.The numbers in the stack must be arranged so that all negatives appear on the bottom of the stack and all positives appear on the top. The order of the numbers does not matter as long as all negatives appear lower in the stack than all...

  • Create a real world scenario that would involve a vector field and create a problem to...

    Create a real world scenario that would involve a vector field and create a problem to be solved involving the vector field and the real world scenario. You must give a formula for the vector field, describe the various variables involved, and explain what the solution to your problem would be finding. Do NOT actually solve the problem you create.

  • Explain the topological ordering problem and show how it can be solved for directed acyclic graphs....

    Explain the topological ordering problem and show how it can be solved for directed acyclic graphs. Give an example to illustrate it. ~Can you explain clearly and with A LOT of information. Thanks. Hi, cs summer students

  • HI USING C++ CAN YOU PLEASE PROGRAM THIS ASSIGNMENT AND ADD COMMENTS: stackARRAY: #include<iostream> #define SIZE...

    HI USING C++ CAN YOU PLEASE PROGRAM THIS ASSIGNMENT AND ADD COMMENTS: stackARRAY: #include<iostream> #define SIZE 100 #define NO_ELEMENT -999999 using namespace std; class Stack { int arr[SIZE]; // array to store Stack elements int top; public: Stack() { top = -1; } void push(int); // push an element into Stack int pop(); // pop the top element from Stack int topElement(); // get the top element void display(); // display Stack elements from top to bottom }; void Stack...

  • Describe two approaches to implementing stacks or queues. Some advantages and disadvantages of one over the...

    Describe two approaches to implementing stacks or queues. Some advantages and disadvantages of one over the other? What it the array position of the root of a binary tree? If m is the position of the parent of a complete binary tree what is the position of the left son? State the binary search tree condition. Show how the nodes of a binary search tree Implemented by a linked list look if the following nodes are inserted sequentially: 43, 17,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT