Professional Documents
Culture Documents
FDSA Lab6
FDSA Lab6
• Make sure to debug your code after every task or after every code block to avoid having to debug
your entire file at once in the last minute.
The Balanced Parentheses problem is a very important problem in Computer Science. We have given you a tougher
problem to solve: “Balanced Brackets” problem. Allowed brackets are only parentheses ‘(‘, ‘)’ and curly-braces ‘{‘,’}’.
Implement the isBalanced() method. Try to follow along the pseudo code given below to come up with a valid
solution in C++. You should get the output as shown below: (Use Array Implementation of Stack here)
if (!isBracket(token))
continue;
// if the token is an opening bracket, PUSH the token into the stack
// ………………………………………………………………… TASK 1 ………………………………………………………………………
Output:
INPUT
Write down the runtime complexity of the code you run in this task in your note book. (TASK 6)
Program 3: (Prog3.cpp attached)
Stock Span Problem is yet another interesting problem. An efficient way to solve this problem is by using Stack.
However, solving this problem using Stack is tricky. You need to implement findSpans() method. Try to go through
the pseudo code given below to come up with a valid solution. The method returns an array containing the span of
i’th day for the given stockPrice array. You should get the output as shown below: (You are free to use either Array
or Linked List implementation of stack here)
// PUSH this day index into the stack ………………………… TASK 10 ………………
}
return spans;
}
Output:
----------------------------