Lecture 4/17: Lecture 6 Q&A


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

Q: Can you play NASA next?

A1: gotchu


Q: How’s your friday going?

A1: good! how’s your day going?


Q: YES NEVERMIND

A1: :)


Q: where are they sending these humans?

A1: to the international space station!


Q: nice!

A1: live answered


Q: can we get a link to the spotify playlist? the only one that pops up is Brahm's one for 106A lol

A1: It is at end of the quick links on the cs106b home page

A2: https://open.spotify.com/playlist/0vxLd6fJpRfMPm0DoXltqH?si=vkTT7-f-RwOIsV-tQzXBTw

also linked form the course website like juli ementioned above!


Q: Is SPACE the same “ “ as it is in Gregg’s code?

A1: It is the space character, e.g. ‘ ‘ (note the single versus double quotes)


Q: nice! thanks

A1:


Q: Is there a way to make the lecture videos downloadable so that I can watch offline if my wifi cuts out?

A1: Nick answered this on Ed — search ther to see the instructions

A2: https://us.edstem.org/courses/335/discussion/27806


Q: Is the Queue data structure only defined in the Stanford Library? Or is there an equivalent in the Standard libraries?</i>

A1: There is an std::queue also

A2: http://www.cplusplus.com/reference/queue/queue/


Q: Does const fix this issue?

A1: Not sure what you mean, if the Queue were const, you would not be able to modify it (i.e. would not be allowed to dequeue()


Q: If you pass a queue into a function will it lose its sense of size like an array or will you still be able to access its size within the function?

A1: It will retain its size


Q: if the for loop printing out the queue skips 1 index every time, shouldn't the queue left behind be {2, 4, 6} rather than {4, 5, 6}?

A1: dequeue always pulls from the front, so the 3 iterations of loop remove 1, 2,3, leaving 4,5,6 in queue


Q: I was thinking for (i = init; const q.size()
)

A1: the test expression of the for loop is reevaluated each time through loop. See slide 14 where Chris pulled the size outside of loop so it not updated as the the queue contents change


Q: are we expected to use postfix in our code?

A1: Do you mean for variable increment? In most cases, prefix and postfix are entirely interchangable


Q: Is it possible for to briefly summarize the push.wordstack correction/clarification that chris made earlier?

A1: I would recommend that you review the lecture video when it is posted. He went over it in the first few mintues


Q: how do you know when to stop popping for each operation?

A1: A binary operator pops the top 2 values


Q: Does this only work two numbers at a time? Would something like 1 2 3 * return 6?

A1: 1 2 3 * is malformed, I think you intend another operator after the * that would apply to the 6 and the 1


Q: Oh! I can test myself. :)

A1:


Q: How do we get this to work in our terminal?

A1: Download the lecture project from the top of the web page with lecture slides (see entry for today under Lectures tab) and open pro file in Qt Creator


Q: Whar is “case” in that example?

A1: live answered


Q: What was "case" under the while loop? What did that mean? Is that like an if?

A1: live answered


Q: what is switch(op)?

A1: live answered


Q: Could you do continue instead of break so it doesn't have to check the other cases?

A1: break jumps out of the switch, skipping all other cases, which sounds like what you are looking for. continue only applies within loops to advance to next iteration


Q: Is the switch op generally better to use than else/if loops?

A1: swtich works well when you have a list of options where the test aobut which case to enter is comparing an integer value to a set of constants, but for anything more complex, if/else is your only option


Q: any idea what time the assignment will be up?

A1: ETA tomorrow afternoon


Q: On assignment 1 it says that hw is due tonight for a bonus but it can also be submitted up until Sunday night. Just wanted to clarify that this still holds.

A1: Yes, our plan is for all assignments to be due end of day Friday, grace period starts then and extends to end of day Sunday


Q: Is it still true that we can turn the assignment in as late as Sunday and just lose the "bonus"? That is what was written at the top of Assignment 1.

A1: Yes, our plan is for all assignments to be due end of day Friday, grace period starts then and extends to end of day Sunday


Q: Baby I got your number

A1: I’m gonna make you mine


Q: What is the inside joke?

A1: Google Jenny 867 5309


Q: does everything in the set have to be the same type

A1: Yes. All of the collections are homogenous with regard to element type


Q: what is the difference between empty() and isEmpty()?

A1: the name of the operation on string is called empty, a similar operation on queue, stack, vector, etc is called isEmpty


Q: can you manually type a set using some form of bracket?

A1: live answered


Q: Can we nest sets in sets?

A1: Yes, you can!


Q: At a low level, why is a set faster than a vector?

A1: You’ll have to wait about 4 weeks before we can tell how it’s so darn smart


Q: a bit of an under the hood question but what makes the sets so make compared to other data types?

A1: You’ll have to wait about 4 weeks before we can tell how it’s so darn smart (hint: sorting and/or hashing)


Q: Sets don't have indexes?

A1: Nope


Q: Is this in contrast to Python

A1: sorry, I am missing the context for your question. can you clarify?


Q: Can we also nest maps in maps, vectors in vectors, etc.?

A1: Yes!


Q: Can you convert a vector into a set?

A1: you could do a foreach loop over the vector and add each to the set, any duplicate elements would be coalesced


Q: what does boolalpha on the print function do again?

A1: It changes the format for printing a boolean from the default numeric representation (0/1) and outputs as string names (true/false)


Q: I thought .size returns size_t type

A1: .size on string does return size_t, but our collections specify return type of int. The distinction between signed and unsigned is more of a CS107 topic, keep progessing and you’ll get all the gory details


Q: to print a boolean, wouldn't it be simpler to convert it to a string? or is that not possible

A1: If you want to print a boolean result true/false, boolalpha is an easy way to get that.


Q: can you pick the type of “sorting order”

A1: You control ordering by changing the comparison operation for the element type. The mechanics of this are a bit advanced for this course, but CS106L will go through that.


Q: Exciting! I can’t wait to go fast. Vroom vroom :)

A1: Me too!


Q: can you add a set and a hash set?

A1: Yes, you can


Q: Is there an operand for the symmetric difference?

A1: No built-in, but you could construct with a compound expression


Q: Will != return false if only some of the elements match?

A1: yes. for two collections to be equal must contain exactly same elements, anything else is not equal


Q: Why would AB- BC (sets) yield A and not AC?

A1: Yes, difference is elements in first that are not in second. It sounds like you are looking for symmetric difference? You could construct that out of a compound expression, but there is no built-in for that


Q: is it good practice to not indent ifdef?

A1: Generally you don’t — preprocesor directives operate outside the normal C++ language flow


Q: if you added a duplicate word to a set, would it just ignore it?

A1: Yes, add an element already in the set has no effect


Q: Why were there no curly brackets on that if statement?

A1: If there is only one statement, the curly braces are optional, but it is allowed (good even) to always use the curly braces even when they are not strictly required


Q: So if this was a set, we wouldnt need the if statement that makes sure a word doesnt repeat wouldnt be necessary?

A1: Yep, you could remove it and it would have no change if the data type were a set


Q: why does he use #define again?

A1: Advanced ninja powers :-). Don’t worry too much, it’s specific to this kind of example where we want to have parallel versions of the same code


Q: how does “while (input » word) {“ work?

A1: the extraction operator (») returns a boolean result that indicates whether the word just read was the last one in the file (you have hit end of file or error)


Q: Can a linked list be considered a map?

A1: a Map might be implemented using a map


Q: random mac question: how does chris switch between applications so quickly; it looks like a panel of applications on his view

A1: Command-tab


Q: can maps store different data types?

A1: All keys are homogenous type, all values are homogenous type, but those types can be set to what you need (i.e. int keys, string values or string keys and Vector values and so on)


Q: awesome thanks!

A1:


Q: what is the
on m[key]?

A1: Typo :-) We will remove it later


Q: what does the br stand for in value
?

A1: Typo, we will fix on the slides!


Q: lol great content today

A1: Thanks, Chris is killin it!


Q: are you able to nest maps like you can nest dicts in python?

A1: Yes!


Q: Are there any unsorted maps?

A1: HashMaps are unsorted


Q: is there debugging in OH or no

A1: live answered


Q: yes we love today’s content!! thanks chris

A1: live answered


Q: where is the next Q&A?

A1: live answered