[Home]

# CS 223 - Spring 2017. 2/8

## Welcome to CS 223!

### Logical problem of the day

lp0208.c
```  // create a recursive data structure
typedef struct person {
char * first;
char * last;
Date birthday;
struct person friend;
} Person;
```
What happens above?

## Lecture 8: Introduction to C: hw3 + linked lists, hash tables

• Office hours:
The office hours are Sun/Tue/Thu 8-11 PM at Hillhouse 17 Rm 111.
• My office hours this week are Wednesday 4-5pm.

### Assignment 3

Problem set 3
• Convert PICK to number: 7425.
• Convert 456 to words. [ghi][jkl][mno]
```  gjm
gjn
gjo
gkm
gkn
gko
glm
gln
glo ***
hjm
...
```
• Also, there was a question about the debug output:
```% Callme 7245677 -debug
Growing to size: 2048. n: 1024. Used buckets: 812. Occupancy rate: 0.79
Growing to size: 4096. n: 2048. Used buckets: 1611. Occupancy rate: 0.79
Growing to size: 8192. n: 4096. Used buckets: 3219. Occupancy rate: 0.79
Growing to size: 16384. n: 8192. Used buckets: 6438. Occupancy rate: 0.79
Growing to size: 32768. n: 16384. Used buckets: 12921. Occupancy rate: 0.79
Growing to size: 65536. n: 32768. Used buckets: 25899. Occupancy rate: 0.79

Here n is the size of the array. However, in the next section

The hash table keeps track of how many elements it contains, say
n. Once n * MAX_LOAD_FACTOR == SIZE n is the track of how many
elements it contains.
```
n is used to count the number of items in the table. Once n reaches the size of the table, the table expands. At that point n == size, but normally n is less than size.

### Lecture Starts Here

#### structs

Aspnes: structs

• struct.c Basic date struct, and recursive person struct, with and without pointers and malloc.
• struct3.c Shows the danger of allocating the wrong size. See diffence with int's vs long's.
• You can use structs to make new data types. Here is a string data type that includes the length of the string.
• myString.h
• myString.c

Structs are just fine for creating single data type instances, like strings. It is usually more interesting to create data structures that actually produce structures. The simplest structure is a linked list. We will later see more complex structures, like trees and graphs, which are variations on linked lists.

• lists.c

#### Hash Tables

Aspnes: Hash Tables

• hw3/hash.h from hw3
• hw3/hashtest.c uses hash.h, string keys, linked lists
• hw3/bighashtest.c uses hash.h, string keys, linked lists

• Hash Functions:
• Determinism - consider a random number generator as a hash function random.c
• Uniformity - Maintain constant load factor
• exhash.c integer keys, linear probing
• exhash2.c string keys, linear probing
• examplehash.c integer keys, linear probing, dummy item for deletes
• examplehash2.c string keys, linear probing, dummy item for deletes
[Home]