Lecture 5/1: Lecture 12 Q&A
Lecture 12 Questions and Answers (Exported from Zoom Q&A log)
Q: will Nick be having QA after lecture?
A1: Yes, I believe so. I (Julie) as also holding office hours today after class
Q: Will Pixar night be recorded?
A1: live answered
Q: can cs 107e be taken instead of cs107
A1: Yes!
Q: Can you guys stream Onward instead of lecture?
A1: I wish!
Q: So does a struct just contain a vector of objects?
A1: I think you may have said that backwards,? the Vector is a collection of objectT structs
Q: What exactly is a struct again?
A1: A struct is a custom variable type that consists of one or more fields with names and types
Q: is the goal to spend the most moneya and get the most weight or use the lease amount of weight to get the most money?
A1: The goal is get the most amount of money while not going over 15kg in the backpack
Q: why do you pass by reference in the function?
A1: Often we are doing that simply for efficiency (to avoid making copy of large data structure) other times it will be because we plan to change the contents within the function
Q: is this similar to the cents problem on the section handout?
A1: Yes! Recursive structure is similar , but for change we had the option of taking several of a coin, for knapsack we only have one radio or one flashlight which we can either take or not
Q: is chris using proper syntax without brackets?
A1: Good catch :-). If the body consists of a single statement, the braces are optional, but it is a good practice to always include them even if they are not required.
Q: is it okay style wise to put the return next to the if statment
A1: I would advise to add braces and move the return down to next line, but the code is corre as is, maybe just a bit terse
Q: Why did Chris chose to do object.size on the outside of the for loop
A1: I think he may be intended to change the size inside the loop? (not sure yet!)
Q: can it also be bestScore + 1, or some infinite value for localBestScore because it will be replaced later on anyways?
A1: If we can find anything better, we will use that value
Q: why do you use a vector instead of a map? or does objectT allow there to be an associated value
A1: objectT can be defined to hold whatever information is needed into one aggregate data unit.
Q: what does .weight do?
A1: live answered
A2: Access the field named weight from the objectT struct (this is akin to accessing the row or col field of GridLocation)
Q: where did .value and .weight come from? are they built in?
A1: live answered
A2: These are members of the objectT struct, which we are able to access diretly
Q: After doing objects.remove(i), are we still able to access values in the originalObject variable?
A1: Yes we made a copyin the originalOjbect variable
Q: will the localBestScore not reset after each recursion?
A1: Each level of the recursion has its own copy of localBestScore, which is distinct from the others
Q: Do we need to choose/unchoose in part 5 of HW 3?
A1: Predict? There is an exhaustive exploration so yes and choose, but depending on how you track state you might not need explicit unchoose step
Q: What does values[] (with the brackets) mean?
A1: Access element at index in a Vector
Q: how would we do this differently if it was a permulation
A1: The pattern Chris is showing is akin to permutation , it picks one of the remaining to add (similar to how permutation picks the next letter to extend soFar)
Q: when we do .insert, it puts the object back into its original place which is objects[0] so it doesn’t shift the entire objects vector?
A1: It removed from index i and then reinserts at index i, so restores the vector to its original condition
Q: Is it possible that he repeat again from the top?
A1: live answered
Q: How would the decision tree for this problem look like? That might make it easier to understand the recursion taking place.
A1: The decision tree is similar to permutation — at each level choose one of items remaining
Q: so don’t do arms length recursion?
A1: Try to avoid, yes, let the code go to the base case and have it handle
Q: connect zoom sound to computer sound
A1: Thanks for the tip!
Q: is this in anyway similar to the neighbors function in maze? But using recursion and the lexicon?
A1: Yes, it does have similarities. Good on ya for noticing!
Q: Hydra works though :)
A1: Yep!
Q: how many parts will be on our next hw?
A1: warmup + 3
Q: can i get clarification on what we’re doing witht he vec original solution?
A1: We are saving it in case we need it later. We are going to try other arrangements and if they don’t work out as bettter, we want to have that original version to go back to
Q: i'm confused at a fundmental level how we're picking all combinations of weights
A1: The pattern he is following is most akni to permutations — at each level of recursion the choice you are making it which of the remaining objects to select and add into the backpack
Q: can homework be released tonight, if possible?
A1: we like to wait until current assignment comes due before releasing the next, please enjoy a few hours of breathing room where you are caught up!
Q: is saving the solution the only difference between our current case and the original one?
A1: yes, updating the best solution as we go is the major difference between this version and the version we started class with
Q: when chris says partitionable does he mean reducible example?
A1: The reducible example was the one shrinking the string, the partitionable was dividing a vector into two equal sum groupings
Q: are we going to go over the object struct or is it in the textbook/will we need it?
A1: objectT is custom struct just for this example, just has two fields, weight and name.
Q: Will we double count the number of solutions? (does the order of putting objects matter?)
A1: I believe in this formulation (which is akin to permutations) it is treating the same set of objects ina different order as a distinct solution.
Q: Are we finding all the solutions that amounts to the best possible value or all the solution whatsoever?
A1: This counts any combination of objects that doesn’t exceed weight is a possible solution, not the best one though
Q: are we optimizing the price? like more weight for less price?
A1: With a fixed weight, you want to find the optimal amount of value (money)
Q: can you please go over the choose/unchoose of this function?
A1: live answered
Q: do we need to know how to write our own structs?
A1: There hasn’t yet been a need for you to define a custom struct, but you are using structs, like GridLocation, and GPoint that we defined
Q: can you re-explain what consitutes the best value
A1: live answered