this is week 7 - cs50cdn.cs50.net/2013/fall/sections/7/section7.pdf · this is week 7 fall 2013...
TRANSCRIPT
![Page 1: this is week 7 - CS50cdn.cs50.net/2013/fall/sections/7/section7.pdf · this is week 7 fall 2013 playlist50 Ya Hey (Vampire Weekend) Mountain Sound (Of Monsters and Men) Monster Mash](https://reader033.vdocuments.net/reader033/viewer/2022041923/5e6cdd1b7e2dde559d762d6d/html5/thumbnails/1.jpg)
this is week 7
fall 2013
playlist50 Ya Hey (Vampire Weekend)
Mountain Sound (Of Monsters and Men) Monster Mash (Bobby Pickett & The Crypt-Kickers)
![Page 2: this is week 7 - CS50cdn.cs50.net/2013/fall/sections/7/section7.pdf · this is week 7 fall 2013 playlist50 Ya Hey (Vampire Weekend) Mountain Sound (Of Monsters and Men) Monster Mash](https://reader033.vdocuments.net/reader033/viewer/2022041923/5e6cdd1b7e2dde559d762d6d/html5/thumbnails/2.jpg)
agenda
resources
linked lists
hash tables
![Page 3: this is week 7 - CS50cdn.cs50.net/2013/fall/sections/7/section7.pdf · this is week 7 fall 2013 playlist50 Ya Hey (Vampire Weekend) Mountain Sound (Of Monsters and Men) Monster Mash](https://reader033.vdocuments.net/reader033/viewer/2022041923/5e6cdd1b7e2dde559d762d6d/html5/thumbnails/3.jpg)
resources
lecture notes & source code
cs50.net/shorts
study.cs50.net
man
cs50.net/discuss
ohs
me!
![Page 4: this is week 7 - CS50cdn.cs50.net/2013/fall/sections/7/section7.pdf · this is week 7 fall 2013 playlist50 Ya Hey (Vampire Weekend) Mountain Sound (Of Monsters and Men) Monster Mash](https://reader033.vdocuments.net/reader033/viewer/2022041923/5e6cdd1b7e2dde559d762d6d/html5/thumbnails/4.jpg)
pset6
gdb
valgrind --leak-check=full
diff -y
![Page 5: this is week 7 - CS50cdn.cs50.net/2013/fall/sections/7/section7.pdf · this is week 7 fall 2013 playlist50 Ya Hey (Vampire Weekend) Mountain Sound (Of Monsters and Men) Monster Mash](https://reader033.vdocuments.net/reader033/viewer/2022041923/5e6cdd1b7e2dde559d762d6d/html5/thumbnails/5.jpg)
http://sayat.me/cs50
![Page 6: this is week 7 - CS50cdn.cs50.net/2013/fall/sections/7/section7.pdf · this is week 7 fall 2013 playlist50 Ya Hey (Vampire Weekend) Mountain Sound (Of Monsters and Men) Monster Mash](https://reader033.vdocuments.net/reader033/viewer/2022041923/5e6cdd1b7e2dde559d762d6d/html5/thumbnails/6.jpg)
linked lists
i.qkme.me/3toh4j.jpg
![Page 7: this is week 7 - CS50cdn.cs50.net/2013/fall/sections/7/section7.pdf · this is week 7 fall 2013 playlist50 Ya Hey (Vampire Weekend) Mountain Sound (Of Monsters and Men) Monster Mash](https://reader033.vdocuments.net/reader033/viewer/2022041923/5e6cdd1b7e2dde559d762d6d/html5/thumbnails/7.jpg)
node
typedef struct node
{
int n;
struct node* next;
}
node;
![Page 8: this is week 7 - CS50cdn.cs50.net/2013/fall/sections/7/section7.pdf · this is week 7 fall 2013 playlist50 Ya Hey (Vampire Weekend) Mountain Sound (Of Monsters and Men) Monster Mash](https://reader033.vdocuments.net/reader033/viewer/2022041923/5e6cdd1b7e2dde559d762d6d/html5/thumbnails/8.jpg)
node
node new_node;
new_node.n = 1;
printf("%i\n", new_node.n);
node* ptr_node = &new_node;
printf("%i\n", (*ptr_node).n);
printf("%i\n", ptr_node->n);
![Page 9: this is week 7 - CS50cdn.cs50.net/2013/fall/sections/7/section7.pdf · this is week 7 fall 2013 playlist50 Ya Hey (Vampire Weekend) Mountain Sound (Of Monsters and Men) Monster Mash](https://reader033.vdocuments.net/reader033/viewer/2022041923/5e6cdd1b7e2dde559d762d6d/html5/thumbnails/9.jpg)
insert
http://www.cs.grinnell.edu/~walker/courses/153.sp09/readings/reading-lists-c.shtml
![Page 10: this is week 7 - CS50cdn.cs50.net/2013/fall/sections/7/section7.pdf · this is week 7 fall 2013 playlist50 Ya Hey (Vampire Weekend) Mountain Sound (Of Monsters and Men) Monster Mash](https://reader033.vdocuments.net/reader033/viewer/2022041923/5e6cdd1b7e2dde559d762d6d/html5/thumbnails/10.jpg)
find
http://www.cs.grinnell.edu/~walker/courses/153.sp09/readings/reading-lists-c.shtml
![Page 11: this is week 7 - CS50cdn.cs50.net/2013/fall/sections/7/section7.pdf · this is week 7 fall 2013 playlist50 Ya Hey (Vampire Weekend) Mountain Sound (Of Monsters and Men) Monster Mash](https://reader033.vdocuments.net/reader033/viewer/2022041923/5e6cdd1b7e2dde559d762d6d/html5/thumbnails/11.jpg)
delete
http://www.cs.grinnell.edu/~walker/courses/153.sp09/readings/reading-lists-c.shtml
![Page 12: this is week 7 - CS50cdn.cs50.net/2013/fall/sections/7/section7.pdf · this is week 7 fall 2013 playlist50 Ya Hey (Vampire Weekend) Mountain Sound (Of Monsters and Men) Monster Mash](https://reader033.vdocuments.net/reader033/viewer/2022041923/5e6cdd1b7e2dde559d762d6d/html5/thumbnails/12.jpg)
your turn: linked.c
Write a function that inserts an int into a
linked list. Keep the list sorted from
smallest to largest. Do not insert
duplicates. Let the user know whether or not
the insert was successful. Don't worry about
freeing nodes at the end of the program.
bool insert_node(int value);
Skeleton code has been provided for you.
![Page 13: this is week 7 - CS50cdn.cs50.net/2013/fall/sections/7/section7.pdf · this is week 7 fall 2013 playlist50 Ya Hey (Vampire Weekend) Mountain Sound (Of Monsters and Men) Monster Mash](https://reader033.vdocuments.net/reader033/viewer/2022041923/5e6cdd1b7e2dde559d762d6d/html5/thumbnails/13.jpg)
strategy
// logic
draw a picture
write some pseudocode
// syntax
map it onto C
code the program
![Page 14: this is week 7 - CS50cdn.cs50.net/2013/fall/sections/7/section7.pdf · this is week 7 fall 2013 playlist50 Ya Hey (Vampire Weekend) Mountain Sound (Of Monsters and Men) Monster Mash](https://reader033.vdocuments.net/reader033/viewer/2022041923/5e6cdd1b7e2dde559d762d6d/html5/thumbnails/14.jpg)
your turn: linked.c
Write a function that prints out all of
the ints in a linked list. Print out the
number of each node (0-indexed) as well.
void print_nodes(node* list);
Skeleton code has been provided for you.
![Page 15: this is week 7 - CS50cdn.cs50.net/2013/fall/sections/7/section7.pdf · this is week 7 fall 2013 playlist50 Ya Hey (Vampire Weekend) Mountain Sound (Of Monsters and Men) Monster Mash](https://reader033.vdocuments.net/reader033/viewer/2022041923/5e6cdd1b7e2dde559d762d6d/html5/thumbnails/15.jpg)
your turn: linked.c
Write a function that frees all of the
nodes in a linked list before the program
exits.
void free_nodes(node* list);
Skeleton code has been provided for you.
![Page 16: this is week 7 - CS50cdn.cs50.net/2013/fall/sections/7/section7.pdf · this is week 7 fall 2013 playlist50 Ya Hey (Vampire Weekend) Mountain Sound (Of Monsters and Men) Monster Mash](https://reader033.vdocuments.net/reader033/viewer/2022041923/5e6cdd1b7e2dde559d762d6d/html5/thumbnails/16.jpg)
hash tables
####### # # # #
![Page 17: this is week 7 - CS50cdn.cs50.net/2013/fall/sections/7/section7.pdf · this is week 7 fall 2013 playlist50 Ya Hey (Vampire Weekend) Mountain Sound (Of Monsters and Men) Monster Mash](https://reader033.vdocuments.net/reader033/viewer/2022041923/5e6cdd1b7e2dde559d762d6d/html5/thumbnails/17.jpg)
hash tables
array + hash function
0) key
1) value = hash_function(key)
2) array[value] = key
![Page 18: this is week 7 - CS50cdn.cs50.net/2013/fall/sections/7/section7.pdf · this is week 7 fall 2013 playlist50 Ya Hey (Vampire Weekend) Mountain Sound (Of Monsters and Men) Monster Mash](https://reader033.vdocuments.net/reader033/viewer/2022041923/5e6cdd1b7e2dde559d762d6d/html5/thumbnails/18.jpg)
http://en.wikipedia.org/wiki/Hash_table
. . . . . .
![Page 19: this is week 7 - CS50cdn.cs50.net/2013/fall/sections/7/section7.pdf · this is week 7 fall 2013 playlist50 Ya Hey (Vampire Weekend) Mountain Sound (Of Monsters and Men) Monster Mash](https://reader033.vdocuments.net/reader033/viewer/2022041923/5e6cdd1b7e2dde559d762d6d/html5/thumbnails/19.jpg)
potential pitfalls
What make a good
hash function?
0) deterministic
1) returns valid indices
![Page 20: this is week 7 - CS50cdn.cs50.net/2013/fall/sections/7/section7.pdf · this is week 7 fall 2013 playlist50 Ya Hey (Vampire Weekend) Mountain Sound (Of Monsters and Men) Monster Mash](https://reader033.vdocuments.net/reader033/viewer/2022041923/5e6cdd1b7e2dde559d762d6d/html5/thumbnails/20.jpg)
potential pitfalls
What if two keys map to the
same value?
0) linear probing
1) separate chaining
![Page 21: this is week 7 - CS50cdn.cs50.net/2013/fall/sections/7/section7.pdf · this is week 7 fall 2013 playlist50 Ya Hey (Vampire Weekend) Mountain Sound (Of Monsters and Men) Monster Mash](https://reader033.vdocuments.net/reader033/viewer/2022041923/5e6cdd1b7e2dde559d762d6d/html5/thumbnails/21.jpg)
http://en.wikipedia.org/wiki/Hash_table
. . . . . .
. . . . . .