#Order of Operations Strings
1 messages · Page 1 of 1 (latest)
I want to do a ton of if statements but then do not know how many nested parenthesis the input the teacher will do will have. It is supposed to work with up to like 100 nested parenthesis
you have to build a lexicon tree
then visit all nodes and compute in order using a visitor pattern
You have to do lexicon tree? And this is have to recursion? This feels simple and is the second assignment. We have not really covered recursion but are allowed to use it.
Sorry I'm just sort of adverse to do stuff that is not visible. Like recursion stuff is just confuse and I'm hoping to just use the given operation things. I don't quite understand if other methods exist. It just feels simple.
yes traversing / building a treemap is a recursive pattern
if you build a lexicon tree, then visit it, in order, the equation result will be valid as long as it fits in memory
this is comp 6421 stuff 😄
Sorry, I just don't understand and am worried or get the feeling this is far complex.
There is no other way to do this? Is there some resource on this?
The mentors mention recursion too, so I'm a bit worried this is the intended solution. This is like Freshman CS class, second homework on strings and operations
I'm head to help hours for school again. I'm totally worried if I am going to be able to doing this stuff. It is just very hard for me to understand for some reason.
Thanks, I found term for this is "Expression Tree". They basically want us to make one if given string. I can start look for ways to do without recursion. I cannot see myself using recursion on exams, I want to avoid that if possible.
I feel on exams they will ask to write similar programs.
Nevermind. This is difficult. We have not learned loops yet. Loops are in 5 more weeks or so. Since we can't use loops this means this first group of assignments I guess they want us to use recursion.
visitor is already recursive
The other way is to use a push-back stack instead of a tree
and you execute parts in order too
Expression Tree is the same thing yes 🙂
some problems are recursive and cannot be done iteratively unless bound in space-time or height
basically if you were to do things iteratively up to 3
then the maximum amount of parenthesis would be 3 on each side
( ( ( x ) ) )
so if you want to support any height you need recursion, or at least fake it with a fake stack and goto statements
I am surprised they ask you about complex recursions before loops, seems like the wrong way to do this
In theory, you could use a large enough array as a stack and recursion
in which language do you have to implement this?
like is it C, C++, Java, C#, PHP, Python, Lisp, JavaScript, Perl ?
Any language. But the one they probably recommend is like Python. They also have a few weird languages that people used. But I was less worried about language and more about the actual way to do this because they basically want to use only the operation keyword things we learned in class.
Yeah. I was thinking of only if statements and a huge list thing.
But they said it should handle up to as many as want. I dunno but I get the feeling if it can do 1000 nested parenthesis they want it to be able to do 1001
well, with EVAL() you don't need any implementation 😄
well you can do a loop with a push back stack and a switch statement (if/else)
It is literally just dealing with infinite nested parenthesis thing.
Can't do loops. We are not allowed loops
fair enough
I regret taking this class. Just found rate my prof says this one loves recursion and there's more to come.
Oddly this problem seems easy for my fellows
They just did the recursion part. The hardest part I assume is figuring out how to get the correct number of nested parenthesis for where to start.
The rest after that is fairly easy.
I'm just hoping the help hours tomorrow they can just helping me. Sorry for sounding so in the dark.
The problem just feels so simple compared to a few of the others. Like before this we did some basic lists with prints and input taking and operations.
Although first homework had booleans which was difficult for a lot as those needed something messy. It just feels like this problem is easy and that I'm just missing something. The assignment was due like a few days ago anyways.
I swear if it is this, it will be weird.
Some students doing recursion. Others doing this.
Because this eval works.
I mainly came here to ask if there was any other way to do this. I guess I am confirmed I just have to tackle the recursion.
Thanks for clarify. This is flat out impossible with tons of 'if statement'
After figuring out some simple cases of like 3 - (2 - 1) and 3 - ((2 - 1) - 1) or something then it should be good to go. And the main challenge is recursion I guess.
Thanks for help! I get the feeling there is going to be some 'gotcha' or 'trick' revealed and that this homework was some prank or something. This is like second homework Freshman Python such. But it is like fundamental algorithms and problem solving such now.
Online GDB is online ide with compiler and debugger for C/C++. Code, Compiler, Run, Debug Share code nippets.
it works, it's missing divide and multiply
but it's using a Deque and an array
I can assume once it works for these following two expressions then it is done:
3 - (2 - 1)
3 - (3 - (2 - 1))
Like imagining just writing something that works for one nested that also deals with two so it sort of domino effect can do the rest.
Sorry for miscommunication, mainly like if to do this recursive the main issue is where to start
And if it can handle those two cases then theoretically it should be done I guess.
this custom eval() is recursive
another issue is that it use loops inside 😄
They said there is a part 2 for this homework not yet released that will be graded
for look-ahead
This part is not yet graded as if they haven't given everything needed to solve it yet
But they said it is solvable. Sorry for not remembering clearly.
I don't want it just post it. I was more here to understand problem solving and concepts
you could do look-ahead with recursion also...
In my Java class, we build an OOP parser
so expression tree and then traverse it to calculate
In object-oriented programming and software engineering, the visitor design pattern is a way of separating an algorithm from an object structure on which it operates. A practical result of this separation is the ability to add new operations to existing object structures without modifying the structures. It is one way to follow the open/closed p...
Is CS mostly recursion ?
I am very worried.
Sorry this might not be the right place to ask
Like just in general. If most problems require it like this one.
And how does one sort of get better at solving recursion problems. It just feels like there's no pattern to them. Nothing I can memorize or some formula for it?
And unfortunately the program either works or it doesn't, no real in between
For recursion there's no real way to get partial credit sort of.
I am not entirely sure why you hate recursion
3! = 3 * 2 * 1 * 1
recursion is just State array[32]; and some conditions and goto in "simpler languages"
in assembly, you use the stack pointer and push stuff on the stack and call and pop and vice-versa
CS is a lot of things including recursion, DSA, algo, regexp, design, documentation, testing, architecture 😄
otherwise, just do simple "web page" 🤷♂️
I guess this is solved. I had teacher just walk through essentially writing the recursion. Was told before the exam we would get like a 'word bank' of three types of simple recursion to copy so we don't have to derive stuff ourselves.
Like they didn't expect us to create the recursion ourselves yet.
I asked what the loops Homework is. Was told starter code will be C. The loops homework also has "pointers, memory, and simple threading"
This is like overview freshman intro cs.
We will looping through memory and such and doing fork and such they gave small summary.