Lecture 4/22: Lecture 8 Q&A


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

Q: Nick mentioned ODAs on Monday. What are those?

A1: I’m not sure I follow what you’re asking about… Can you elaborate?


Q: Just to confirm do else if statements work differntly in C++ and python?

A1: If-else in python and C (syntax a little different but control flow, behavior is same)


Q: Will we need structs for sssignment 2?

A1: Yes, GridLocation is a struct used in the maze problem


Q: May have been the IGs my bad. I think I’m confusing the acronyms with another class

A1: Yes, IGs are interactive grading sessions, where you meet with your section leader to go over your assignment grade. Those start this week for assignment 1


Q: is this still binary search?

A1: Yes


Q: Does the code for a binary search slightly differ depending on if the initial amount of numbers is even or odd?

A1: Not really, no. You pick the middlemost element so for an even count input you actually have the choice of two, but for odd there is exactly one index that is middle


Q: Might have missed this, but why do we call this Big O stuff?

A1: It is from greek omega


Q: What is the base for the exponential example?

A1: Depends on the algorithm, assume 2 for the purpose of this comparison


Q: how do we identify which type of Big O we’re using in most of the programs we write

A1: It is the sum of the statement counts (loops, etc.) and the cost hidden in the function calls (how much time Set add takes and so on) Chris went through this in Monday’s lecture and we’ll do some practice problems in this weeks section.


Q: What is control flow exactly?

A1: Control flow is the path that execution takes through your code (i.e. into this function, into this if, iterate this loop, etc)


Q: How is this different from a while(true) loop with a break?

A1: live answered


Q: do we need recursion on assignment 2?

A1: No, no recursion on assignment 2


Q: why did he use “person” as the variable type

A1: The idea was some sort of struct that represents a Person


Q: is this how the pow function in C++ works?

A1: Probably not. For efficiency, it is likely to operate iteratively or perhaps even using a lookup table.


Q: what if n is negative?

A1: Raise your hand, and let’s have you ask that live!


Q: I'm a little confused on why we're using recursion for this specific problem.

A1: We sometimes start with simple examples that we could do iteratively, to illustrate how recursion works without getting too complex


Q: Why can power() call itself without crashing? Calling a function inside of itself kind of seems like defining a word by using the word itself in the defintion.

A1: Agreed — it works because it eventually stops the chain, when it gets to the base case and that stops the process from repeating endlessly


Q: Would you get to the base case after it overflows?

A1: N decrements by one each level of the recursion, so it will eventually return N == 0, which is where we hit the base case and stop


Q: what makes a for loop a better solution for this particular problem?

A1: live answered


Q: How do you successfully come up with best possible base case

A1: Practie :-)


Q: hey chris, can you go over the first recursion example again


Q: when will we learn to write the part of code that is usually given to us in assignments


Q: Can you please go over power(5, 3) step by step please?


Q: like when stepping through code during debugging , the other files of code that the program goes to


Q: the one before


Q: could you explain the faster power function again? why is it is faster than just taking the regular power equation?


Q: can you explain the faster power function


Q: Could you explain how you got 9 on the last recursion question? Thank you!


Q: like how the returning works ^^


Q: great thank you!!


Q: how is it just not returning 1??


Q: Thank you!


Q: thanks!