Lecture 21 Zoom Q&A


Q: Will there be assignments alongside the final project?

A1: there’s 1 more assignment after the one that went out yesterday


Q: is there 7 assignments plus the personal project?

A1: yes


Q: Does front not have a data value?

A1: live answered


Q: So if front points to null there are zero elements in the list, right?

A1: correct


Q: So if we declare Node * temp = front; can we call temp = front and then temp = front-> if we want the second value in the list?

A1: Correct (assuming that the list is not empty)


Q: Why is it that in the doubly linked list, the front and back have data values, where as in the singly linked list, the front is just a pointer?

A1: The front and back are just pointers (in this diagram they are not drawn with boxes) they do not have data values, you would have to access front->data to access the data from the first node


Q: Can we assign front and back to different sides ( left vs right)? Or is it always front on the left.

A1: The convention is front on the left, but the decison is up to you


Q: Could you keep track of a 'median' value, and figure out which direction would be most efficient to insert a new value?

A1: You could but as long as you are inserting this is subject to change, so the optimization may not be worth it

A2: Yes! (and that is basically what binary trees do!)


Q: How do we determine which node is curr?

A1: live answered


Q: shouldn’t newNode -> prev = curr -> Prev make newNode -> prev point to the node which has data 42?

A1: live answered


Q: how computationally expensive is it to use doubly linked list vs just linked list?

A1: live answered


Q: okay you drew the arrow to the 17 i was confused


Q: Just wanted to confirm, the code in the addding a node adds the 3 in between 42 and 17?

A1: I believe the plan was to insert the new node in front of curr, yes.


Q: How would you parenthesize curr->prev->next to add clarity and keep the same functionality?

A1: (curr->prev)->next


Q: is it possible for a pointer to point to two different nodes, or is it possible for a node to have two different pointers pointing to it?

A1: No on the first, but yes on the second question


Q: with linked list on a general note, are we trading speed with memory use?

A1: live answered


Q: how come we can say curr->prev->next = newNode instead of curr->prev->next = &newNode

A1: &newNode gets the address of the pointer, a double *, we just want a pointer to the ListNode, its address, a single *


Q: is this tree defined the same as it is in graph theory (i.e. no cycles?)

A1: live answered


Q: are there doubly linked trees and is there any point to having one?

A1: Yes, it is possible for a child to link back to parent. This technique is not commonly used.


Q: do leaves have height 0 then?

A1: live answered


Q: are trees automatically in sorted order?

A1: live answered

A2: No there is no default ordering for trees


Q: Can you desribe a tree as injective but not surjective? Or is this type of classification not possible/incorrect?

A1: I’m not sure what you are mapping from and to?


Q: To clarify, from any parent node to its children, it would be injective but not surjective?

A1: Each child is only pointed to be one parent, but parent is not mapped to only and only one child


Q: What is the definition of a cycle?

A1: live answered


Q: why wasn't the bottom level left-filled first? like why does "written" have no left node but has a right node?

A1: live answered


Q: please repeat the difference between a tree and a incomplete heap?

A1: live answered


Q: Do we do something after traversing @ every step? Or just traverse after doing something the first time?

A1: In this example, we are printing the data from each node as we traverse


Q: is the big O of traversing a binary tree 2^n where n is # of nodes?

A1: live answered

A2: I think you may be thinking about this as a decision tree, which would be 2^height(tree). But given N nodes dividied across a binary tree, the height is Log(n), so 2^log(N) = N, magical!


Q: what would be an example of when you would use a pre-order traversal?

A1: live answered


Q: why would we not say print 2 twice? do we only print after coming back from the left child?

A1: live answered


Q: Is there a name for a tree which prints nodes in order when traversed using pre order?

A1: live answered


Q: do we ever go right and then go left?

A1: That is called a reverse in/pre/post order traversal. Not used as much as forward version


Q: What does going left/right from the bottom nodes mean?

A1: live answered


Q: What's arms-length recursion?

A1: live answered


Q: That’s how a binary heap is printed right?

A1: Correct!


Q: Isn’t this how binary heaps are stored in an array?

A1: Correct!


Q: You could use depth first search, with iterative-deepening, right? So we have a parameter for the “maxDepth”

A1: Yep, that works


Q: Ive heard of KD-trees before, is this similar to a NAryTree?

A1: live answered


Q: Can you tell us a bit about our final project coming up?

A1: live answered


Q: The children are not necessarily sorted in order right?

A1: Correct


Q: do we have to create all of our classes or can we use the stanford library?

A1: live answered


Q: Can you go through the number tree with post order traversal one more time?

A1: live answered


Q: Is the main difference between binary heaps and binary trees that binary heaps are implemented with arrays /must satisfy the heap property while binary trees are implemented with nodes and do not have to satisfy the heap property?

A1: live answered


Q: cat!!


Q: oh my god that was supposed to be a text, sorry