Lecture 4/20: Lecture 7 Q&A


Lecture 7 Questions and Answers (Exported from Zoom Q&A log)

Q: Can you please play Face to Face

A1: queued up!


Q: no by Rex Orange County please*** (after Julie’s of c)

A1: probably won’t make it today, but top of the queue on wednesday, i promise!


Q: one of the only one’s I still know is 8675309

A1: live answered


Q: the sound quality on Chris’ end is kind of poor

A1: It’s coming in ok to me now, is it staying bad for you or has cleared up?


Q: To rejog my memory is sets or maps analogous to dictionaries ?

A1: Maps have key, value pair, so that is the analog to Python dictionary


Q: Chris’ sound has cleared up now, thanks !

A1: Great, thanks for checking back in


Q: The default value is zero I'm assuming? If so is it always? Just checking.

A1: It is the default value for the particular type of value. For example, the default value for a string is the empty string, for Vector it would be an empty Vector, for integer it is value 0


Q: are you adding only the values then to voteTally? how are you sure of its corresponding key?

A1: There is no way to add a value without putting it under a key, i.e. it is always map[key] = value or map.put(key, value)


Q: what does ifstream mean?

A1: file input stream


Q: what is » ?

A1: live answered


Q: what is the » in input » word

A1: live answered


Q: I dont know what happened but the audio is bugging, it had Chris and Nick talking over each other

A1: There was something a little glitchy for a minute, but seems to have resolved. Ok on your end, too?


Q: yes its fixed now

A1: Great, thanks for checking back in


Q: does it matter where the & goes? eg. Vector& v vs. Vector &v?</i>

A1: Means same thing, can go either place.


Q: We used a vector.sort funciton last assignment couldn’t we use that here fro max

A1: Yes, we could! But it is going to take time to sort — is that more than the time we would spend looking for max?


Q: What's the difference between v.size and v.length? Also, why is the type int and not size_t?

A1: Our collection ADTs use the operation .size() to return the count of elements. String calls a similar operation .length(). The subtle difference between signed/unsigned is more of an isue for 107, we’re trying to mostly ignore that distinction for now


Q: Is that object or assemly code?

A1: Assembly is the text representation, object code is the same instuctions in binary encoding


Q: would n^2 be relevant?

A1: Yes! A quadratic term would grow much more steeply than linear one


Q: So this is kind of related to limits in math/calculus?

A1: Yes! Way to see the connection


Q: Is that an O (like OMG) or a 0 (like 1000)?

A1: OMG. (from greek Omega)


Q: So is a while loop significantly more efficient than the for loop in terms of operations?

A1: Not necessarily. If they both iterate N times, the fact that a for loop has say 4 operations per iteration and while loop has only 2, would be comparing 4N to 2N and since constants are ignored, we consider both linear O(n)


Q: does he mean that the (if (currentMax) statement )happens n-1 times?

A1: Each value in the vector is compared to the current max


Q: why did we erase the if line?

A1: oops, I did not see that happen. The if statement should have stayed in, it happens N-1 times (once for each element in vector after the first)


Q: is this what we fixed on perfect.ccp?

A1: Yes, exactly! Thanks for noticing :-)


Q: each for loop = n times?

A1: Yes but because nested inside one another, it does another set of N iterations of the inner loop for each iteration of outer


Q: What about VR image processing? does that relate beacuse its 3D?

A1: Yes — many algorithms that operate in 3D have a cubic nature.


Q: so loops are quadratic or raised to a power, but how can we implement log(n) or constants?

A1: We get logarithmic growth for an operation that divides in half — binary search — we will get there, hang on


Q: If exponents make our alogarithm slower, can going the other side I mean n roots make our alogarithm faster

A1: Yes, exactly!


Q: the insert function complexity depends on the data structure right? It's not default O(n)

A1: Yes, absolutely correct! good point!


Q: Are the constant time functions the same as the primitive functions?

A1: Effectively yes. they may have higher constant terms, but they are independent of size of input


Q: How often do we create functions that actually have O(1)

A1: It is rare but awesome when we can — hashing is a great example. It turns out that push pop on Stack are O(1) so are enqeueue, dequeue on Queue


Q: In the real world ^ not just 106B

A1:


Q: why do vector.add and vector.append take such different time? should we keep using add instead of append to save time?

A1: add is fast because it adds to end, insert is slow because it moves everything over. If you don’t care where the new element ends up, added to the end is much more efficent


Q: Chris can you please go over the Vote Tally Map example?


Q: can it differentiate or do you have to specift(ex. if char == ‘m’)


Q: That was helpful thanks!


Q: can it tell between char and string?


Q: sorry! is “MMMRRRSS” different than “M M M R R R S”


Q: thanks!


Q: have a great day, thanks!


Q: could you explain again how pixar went about solving n^3 behaviour?


Q: can you explain linear search vectors again?


Q: so interesting!! thank you! have a good day!


Q: so 1 for loop is linear but 2 for loops are quadratic?


Q: how can we apply log(n) to that?


Q: awesome, thank you so much!