Logo

CS106B Lecture - Shared screen with speaker view
Ryan Bernstein
09:54
math function
Jordan Lin
09:59
sets
Kenneth W.K. Wang
10:05
unordered data: my memory
shreyasravi
10:09
deck of cards after shuffled
Elan Smolar Eisenberg
10:09
Lists
Arul Saxena
10:12
trees
Kenneth W.K. Wang
10:15
unordered data: my room
Junhao Wang
10:15
sets
yukun yang
10:16
GIS data rasters
Thomas Tao Hale
10:17
College lists
Zachary Alon
10:17
Lists without numebrs
Samuel Lynn Ledden
10:18
team
Elena Williams
10:18
Shopping list, bullet points
Rohan N Chowla
10:20
cards
Ryan J Gabel
10:26
membership lists
alz1022@stanford.edu
10:34
unordered data: my backpack
nicole koch
10:39
my room
Kenneth W.K. Wang
10:53
unordered data: my life
Faith Aing Okamoto
10:57
students in a class
Aadi M Rane
11:09
coin collections
Lukas Fullner
11:47
can structs be used in other structs?
nicole koch
11:57
structceptiom
Nick Bowman
12:01
Yes, structs can contain any data, including other structs.
Elan Smolar Eisenberg
18:08
This is just a quick comment: I always feel in breakout rooms that we don’t have enough time to even address the problems. Ik we have limited time but I just wanted to mention that
Nick Bowman
18:25
Thanks for the heads up, we’ll try to give as much time as possible in the future.
Matt Presson
18:44
And the number of moves was 2^n - 1, right?
edouard des
19:00
Yeah! It’s a Mersenne prime!
Thomas Tao Hale
19:06
Wait you can skip over?
ian rundle
19:06
Whoa that’s epic
Ryan Gabel
19:12
Mersenne number, not a Mersenne prime
Kenny Wang
19:50
do we need an algorithm?
Kenny Wang
19:53
or just a bunch of commands?
Nick Bowman
20:08
A bunch of commands is fine.
Catherine Deng
25:06
If you say a.push(b.pop()), would that also pop from b?
Catherine Deng
25:40
Oh nvm
Jihe He
25:54
Do we need to finish our code
Aadi M Rane
25:55
yes
Jihe He
26:12
Like do we need to finish our breakout section room's challenge
Nick Bowman
26:29
Correct, that one line of code will both remove from b and add to a
Kenneth Fischer
26:44
Would there still be three pegs?
Nick Bowman
26:49
Not required, just an interesting challenege if you wanst more practice with stacks
Ryan Gabel
26:50
Yes, still 3 pegs
Jihe He
26:54
ty
Nick Bowman
27:02
Yes, the game always has 3 pegs, but variable number of disks.
Remy Shearer Kartzman
27:04
for the generalized solution does it have to be a multiple of 3 ?
Nick Bowman
27:15
No, it can be any number of disks
Ryan Gabel
27:17
It works with any number of disks
Remy Shearer Kartzman
27:30
cool thanks
karan parikh
29:54
so sets are like array lists?
Aadi M Rane
30:01
not really
Nick Bowman
30:11
No, Vectors are similar to Java ArrayLists
karan parikh
30:37
is there any reflection of a set in java?
Nick Bowman
31:00
Yes, there is a Java Set class
edouard des
31:07
Is the order they are outputted in the console completely random?
Nick Bowman
31:19
Not exactly, but it will take until the end of the quarter to see why!
dyson ye
31:22
Can you iterate over a set?
Oz Gitelson
31:25
im getting flashbacks to 103
Nick Bowman
31:35
Yes, you can iterate over a set with a foreach loop, that’s coming soon in the slides
Elan Smolar Eisenberg
31:35
same
Ryan Gabel
31:47
it's all coming together
Pablo Manjon Gamez
32:43
Are these sort of liked dunder/magic methods from Python?
Sedef Emekli
32:46
How could sets be implemented in a lower level language, what is the back end of this abstract data type?
Siddharth Balaji
32:59
Since there is no numerical order in a set when you parse through the set in a loop how does the program know which elements are accessed first?
Rohan N Chowla
33:00
Is there any way to access elements of a set without using a for each loop?
Jordan Lin
33:12
You can use an iterator
Nick Bowman
33:12
@Sedef we will learn about the backend data organization of sets later this quarter
Nick Bowman
33:46
@Siddharth similar answer to above, sets do internally maintains structure of the data, and we will learn what structure that is later in the quarter
Nick Bowman
34:05
@Pablo I’m not exactly sure, that might be a question best discussed after class
Nick Bowman
34:52
@Rohan you can use the .contains() method to see if things exists in a set or not. If for some reason you want to get a single random element out of the set you can use the .first() method, but that is not a super common usage pattern
Aadi M Rane
35:29
why declare as a const? why can't you just not change it?
Kenny Wang
35:55
I believe they said it was a style thing
Nick Bowman
35:55
Declaring things as const is extra protection against accidentally changing it, and is a good semantic sign to other programmers that might be reading or modifying your code
Jordan Lin
36:02
Changing a Vector while iterating over it is not that good of an idea
Kenny Wang
37:04
can you pass a non-constant vector to be "lines"
Kenny Wang
37:07
*?
Nick Bowman
37:27
Yes, you can. The const here is mostly used for stylistic messaging that the structure should not be changed.
Marcela Simone De los Rios
37:59
Could you explain again why it won’t add duplicates?
Nick Bowman
38:24
The set internally guarantees that there are no duplicates. So if you try to add two exact same things to a set, only the first add will result in a change to the structure.
kathleen bryan
38:48
I don’t really understand adding sets together
Siddharth Balaji
38:59
I cut out of the feed for a second, why is the vector “lines
Siddharth Balaji
39:05
“ Passed into the function as a const
kathleen bryan
39:06
Like how would a set that had strings add to another set of strings?
Ali Mahdi
39:24
why pass something as a reference if it is not modified?
Jordan Lin
39:27
Are there any 'caveats' to sets than Vectors? For instance, if the purpose of your data structure is just to iterate over it, and order does not matter, then is a set always better than a vector?
Nate Hedgecock
39:31
How does that program handle punctuation? Is a word with punctuation considered different than a word without?
Nick Bowman
39:41
I you have two sets a = {“hello”} and b = {“world”} then a + b would yield the set {“hello”, “world”}
Nick Bowman
39:59
@Nate good catch, it doesn’t! you will learn how to better punctuation on the assignment!
kathleen bryan
39:59
but what about a set with many strings added with another set of many strings
kathleen bryan
40:06
They are not ordered so how is the addition determined
Nick Bowman
40:17
@Kathleen it will just take the full union of the two sets (union operation described on the slides)
Chloe Su
40:29
What happens to the empty lines in between each worded line?
Nick Bowman
40:34
the resulting set from the addition will just contain all the values from the two sets that are being added together
kathleen bryan
40:36
ok I will look back at that
Nick Bowman
40:41
The empty lines get stripped away
Nick Bowman
41:07
@Ali you would pass something by reference that isn’t going to be changes because it is very large, and copying it would be very expensive
Ali Mahdi
41:20
thanks
Dominic Yong Yi Lo
41:43
where are YEAH sessions posted?
Nick Bowman
41:44
@Jordan if you don’t care about the order in which things are maintained and you don’t care about being able to store duplicates, then a set is probably the way to go
Chloe Su
41:49
Does the empty lines get stripped away by the for line function or the .strip(“ “) ?
Liza George
41:50
(not about the content but) when assign two due?
Chloe Su
41:52
Just to clarify!
Nick Bowman
41:57
@Dominic under the course videos section of the Canvas page
Nick Bowman
42:08
@Chloe it gets stripped away by the stringSplit function
Nick Bowman
42:17
@Liza Assignment 2 will be due next wednesday
Nick Bowman
42:30
(a week from tomorrow)
Nick Bowman
43:23
@Siddharth we passed in lines to the function by const reference because we wanted to pass it by reference (since it is large and we don’t want to copy it) and with const to indicate that we won’t be modifying it (important since passing by reference gives us the ability to modify it)
Samuel Lynn Ledden
44:35
is there a way to set a map equal to something?
Samuel Lynn Ledden
44:44
instead of having to use .put of indices
Nick Bowman
45:02
Yes, you can do it but the syntax is a little tricky. If you stick around after class I can type up an example in Ed/
Nick Bowman
45:25
(its just got a lot of curly braces and I don’t want to mess it up here without the benefit of a compiler)
hunter ruebsamen
45:37
Can you have a map within a map?
Nick Bowman
45:50
Yes! You can nest any data structures within one another that you want
Nick Bowman
46:26
Although for clarity (and other purposes) it is good to keep the key type to be something straighforward (string/int/stc)
Nick Bowman
46:31
*etc
Matt Presson
46:55
So a vector is basically a map with integer keys
Nick Bowman
47:08
Yeah, that is an interesting way to think about a vector!
Nick Bowman
47:31
There are some difference, but at a a baseline level, vectors do associate numerical indexes with values
david huang
48:50
will .get() do auto insert as well?
Nick Bowman
49:14
Tricky tricky question! I don’t believe it will, which is why i always stick with using the [] accessing syntax
david huang
49:34
Ok thanks
Emily Sturman
50:38
On the documentation online it says the .get won’t auto insert
Nick Bowman
51:00
Yeah our documentation is sometimes out of date – let me try this out and I’ll report back
Jordan Lin
51:01
Maybe m.constainsKey(key) works better for the purpose of checking if a key is in a map
Kenneth Fischer
51:06
What headers do we include for strings and maps?
Nick Bowman
51:26
Strings is #include <string> and maps is #include “map.h”
Liza George
52:35
When auto-insert creates a new key-value pair and leaves the value empty, what is actually stored for value? like in that cout statement from earlier, what would print out if the key that was searched for didn't exist before?
Elan Smolar Eisenberg
52:39
Does sets have an include?
Nick Bowman
52:54
yes, to use sets you to #include “set.h”
kevin yang
53:17
Can you use wordCounts[word]++
Nick Bowman
53:21
@Liza what is stored is the default value for the type. So if the value type is int, the value stored will be 0, if the value type is string the value stored will be “”
Kyle Booker
53:21
^
Nick Bowman
53:35
Yes, ++ and += 1 are equivalent
Liza George
54:43
is either algorithm more efficient than the other? (using a set vs. using a map)
Nick Bowman
55:09
We’ll talk about this more on Thursday, but the access times for set and map are equivalent
Liza George
55:26
ok, thanks!
Jaelyn N Kelly
56:36
Are maps a useful tool for histograms?
Nick Bowman
57:22
Yes, absolutely!
Jordan Lin
57:36
You can replace all double spaces by single spaces at the beginning of the code
Aadi M Rane
57:36
how do you add a key by itself again?
Nick Bowman
57:54
@Aadi can you clairfy what you mean by adding a key by itself?
Kyle Booker
58:05
What are the default values for vectors?
Aadi M Rane
58:13
Add a key but not attach it to anything
Aadi M Rane
58:30
or will that be a bug?
Nick Bowman
59:20
@Kyle emtpy vector i would guess
max chou
59:24
Is the YEAH zoom on the course page or a separate email
Nick Bowman
59:31
@Aadi you can’t do that, all keys must have associated values
Nick Bowman
59:42
the YEAH zoom info is on the Zoom details page
harry yu
01:00:52
thank you
kevin yang
01:00:54
thank you!
nicole koch
01:00:55
Thank you!
alz1022@stanford.edu
01:00:58
thank you!
Kevin H Fan
01:00:58
Thank you
Aadi M Rane
01:01:00
thank you
Weiqi Yu
01:01:01
thank you
Rohan N Chowla
01:01:03
thanks guys!
paul gialis
01:01:04
Thank you
Kaelyn O
01:01:05
Thank you!
Lawrence Li
01:01:07
thank you
Guozhen Miao
01:01:12
thank you
Shifeng Hong
01:01:12
Thank you
Gautham Rajesh
01:01:13
thank you!
hriday chhabria
01:01:42
Gracias
Aadi M Rane
01:01:55
In a map, does a key have only one value attached to it?
Liza George
01:02:15
I think when you were going over iterating over maps with a foreach loop, you had mentioned a way to still iterate through a map while editing it, but I had missed it. Could you go over that again?
Nick Bowman
01:03:24
Yes there is exactly one value associated with each key
Nick Bowman
01:03:48
If you want to edit a map while iterating over it, the for loop should make use of the keys() function like this
Nick Bowman
01:03:57
for(string key: map.keys() { }
Nick Bowman
01:04:13
This way, you are iterating over a copy of the keys of the map, so that any changes you make don’t cause issues
Emily Sturman
01:04:58
I think you mentioned earlier that it’s possible to declare the contents of a map when declaring the map… how would you do that?
Liza George
01:05:00
oh ok, thanks! and I can still edit the values in either foreach loop right?
christopher cooper
01:05:17
When we submit Assignment 1, should we comment out the slow running tests for findPerfects?
Aadi M Rane
01:05:34
What's the difference between using a Map and using two Vectors with the keys and the values at the same indices?
Nick Bowman
01:05:34
@christopher, sure that might be a good idea. Now worries if not though
christopher cooper
01:06:34
Cool, any suggestions for the program comments at the top of the file for perfect.cpp and soundex.cpp?
Nick Bowman
01:07:20
@Aadi a map is better fo that purpose because then you don’t have to manually keep track of the indices and make sur ethey match up
Nick Bowman
01:07:37
Just desxcribing what you did in the files and giving a general overview is good
christopher cooper
01:07:51
OK, Thanks
karan parikh
01:08:01
I don’t have a mic right now so I’ll type my question here: where can I find associated reading with keys and maps? I remember there being a textbook we can use to catch up on lecture topics
Junhao Wang
01:08:16
would it be printing an empty string?
Liza George
01:08:17
wouldn't it give "", the default value for strings?
Nick Bowman
01:08:29
@Liza is correct, it is giving you the default value
Nick Bowman
01:08:29
which is ""
Chloe Su
01:08:54
Did Nick say also that .get() will return the value also?
Liza George
01:09:24
yes, .get() will return the default value, but will not change the map itself
Nick Bowman
01:09:33
@Karan the textbook is lonked on the sidebar of the course website and the schedule has associated readings for each lecture
Chloe Su
01:09:38
Oh so since get(“Nick”) is not in the map, in here it is returning nothing as default?
Nick Bowman
01:09:39
*linked
Liza George
01:10:09
@chloe yeah, I think so
Chloe Su
01:10:22
Thanks!
Nick Bowman
01:10:25
To be clear it is returning something, it is returning the empty string “”
Liza George
01:10:46
oh woops yeah, mb
Liza George
01:11:43
bye, thanks!
scott nelson
01:11:44
Can map values be data structures? Like maps or vectors or sets?
Michael M Hu
01:11:48
Thanks!
scott nelson
01:14:28
Thanks Nick!
karan parikh
01:14:37
how does grace period for assignments work?
Nick Bowman
01:15:58
@Karan if you need it, you have an extra penalty-free 24 hours to submit the assignment
Nick Bowman
01:18:26
Map<string, string> friends = {{"Nick", "Hello"}, {"Kylie", "World"}};
Demi Lei
01:21:44
Thank you!
Jennifer Anna Bonello
01:22:06
Thanks!
Junhao Wang
01:22:21
thank you