List is a group of elements consist of its data and a pointer to the next element (each element can be consider an object with 2 attributes: data and the next-object-pointer). List has the benefit of not taking away a huge junk of contigous memory but just take a bit here and there then connect them together via pointers. Head of a list is a pointer to the first item while end of it is a pointer poiting to NULL.
Stack: group of elements linked together just like list but follow a in-out protocol called Last In First Out. This mean whatever entered the stack last via the push function call will be dumped out of the stack first via pop function call.
Queue: similar to Stack but the protocol this time is First In First Out
Dictionary: group of key-value pairs. The key is an input to a hash function that returns something like a unique token (only appears once for each key) that will point to the address where the "value" resides
Q2: log2(n) The logarithm base 2 of n
Q3: n times.
Q4: when values cannot be in an order or the order is not meaningful (cannot be sorted) (i.e categorical data).
Example: string of names of people, list of names of occupations, etc. Or when the list is small.
Q6: The list that is built is a linked list of sNodes. Each sNodes contains a data and a next (which is a pointer to the
next sNode). The list goes as the following order: 3 -> 24 -> 6
Q7: Another linked list in Python's form: [13, [28, [24, [3, None]]]]
Q8: In the first attempt, the s is the pointer to the array buffer. Therefore, modifying s is actually modifying what s is pointing to, in this case is buffer.
Hence, when concatenating "who's ..." to s, that phrase is actually concatenated to buffer
In the second attempt, s is the pointer to a junk of memory in heap (via malloc), and then buffer is COPIED into that junk of memory. After that, the "who's..." char array got concatenate to the end of what s points to, which is that junk of heap memory, , NOT the buffer itself. Therefore, only the junk of heap mempry changed, while the buffer is untouched
Q9:
Hash Nodes:
3 [Bob,38][Cos,86]
4 [Vera,99][Nash,11][Kate,28][Jaga,24]
5 [Jesse,78]
Q10:
int find( char *key, int *p_ans);
{
int h=hash(key);
entry *node;
for (node = table[h]; node != NULL; node=node->next)