This report refers to main.js
file present at the root of this repository.
- It take
symbol
as input - It return
true
if input is the symbol otherwise it returnfalse
.
- [Line:27] condition checking, comparison and return statement cost O(1)
- [Line:30] return statement cost O(1)
Overall time complexity = O(1) Overall space copleaxcity = O(1)
- It's a stack function that maintain stack item count.
- And it return open bracket count.
- It have
push()
function which increases the count by one. - It have
pop()
function which decreases the count by one.
- [Line:2] declaration statement cost O(1)
- [Line:3] function call to
isEmpty()
. It compare and return costs O(1) - [Line:6] function call
push()
. Increment statement cost O(1) - [Line:12] function call
pop()
. It call isEmpty() as condition checking statement and decrement statement inside the body both costs O(1)
Overall time complexity = O(1) Overall space copleaxcity = O(1)
- This function first check the open and closing symbol is they are symbol or not. And save it as reference for opening and closing symbol for later use.
- Then it loops over the
inputString
and pick each value and save it invalue
variable. - Then it check if
value
is opening symbol or closing symbol. - If it's opening symbol then it call
push()
function which increasesopenBracketsCount
variable by 1. - And if it's closing symbol then it call pop() function which decreases
openBracketsCount
varable by 1. - And under condition for closing symbol it also call function
isEmpty()
to check if expression is left or not. If expression is finished then it returnfalse
. Otherwise it callpop()
function. - After loop ends it call and reutn
isEmpty()
function.
- [Line:39] Declares function object
stack
cost O(1) - [Line:40] Declares
isOpeningSymbol
variable and callingisSymbol(openingSymbol)
function cost O(1) - [Line:41] Declares
isClosingSymbol
variable and callingisSymbol(closingSymbol))
function cost O(1) - [Line:42] Loop from 0 to
inputString
length with +1 increment cost O(n) - [Line:43] Variable
value
declartion cost O(1) - [Line:44] Condtion checking
isOpeningSymbol(value)
and calling push() onstack
object cost O(1) - [Line:46] Condition checking
isClosingSymbol(value)
cost O(1) - [Line:47] Condition checking
stack.isEmpty()
and return statement cost O(1) - [Line:50] Function call
stack.pop()
cost O(1) - [Line:52] return statement
stack.isEmpty()
cost O(1)
Overall time complexity = O(n) Overall space complexity = O(1)
- max of ( O(1), O(1), O(n) )
- O(n)
- max of ( O(1), O(1), O(1) )
- O(1)
- Click this url Brackets Match
- Node Js is required for running CLI mode.
- Web browser reuired for running GUI mode.
- Download this repository
cd
to the downloaded repository.- Run main.js using command
node main.js
- Download this repository
- Open downloaded repository.
- Double click or open
index.html
file with web browser.