Q1. Add() is used to add a string prefix and a suffix to the table. addSuffix is used to add a new suffix to the hash table
Q2. Lookup takes a boolean and a string prefix and determines if a new state should be created. It loops through the linked list in the states table until the match is found and returns the pointer to the location in memory.
Q3.
Prefix | Suffix
____________________________
(null) (null) | It's
(null) It's | a
It's a | new
a new | dawn
new dawn | (null)
__________________________
"It's" - 3 references
"a" - 3 references
"new" - 3 references
"dawn" - 2 references
Q4. It uses a minimum amount of memory storage. Each string is allocated only the memory it needs
Q5. Having to free memory after the program after it executes, so it can be used elsewhere (for other pointers)
Q6.
void cleanup(State *statetab)
{
while(statetab != null){
free(statetab);
statetab = statetab -> next;
}
}
Q7. I think this function works properly. I was confused on whether to allocate the memory or to delete them. Could've used delete function in C++ (which would have given the same results), but freeing makes more sense if I am just cleaning the list up.
Q8. You could track a pointer and the value attacked to it and check if the pointer is equal to that value prior and after freeing the value. This way, one could tell if a memory location is freed only once or the value tied to that pointer still exists.
Q9. prefixes are stored in a deque which allow individual elements to be accessed directly through random access iterators with storage handled automatically by expanding and contracting the container as needed. Deques are better at inserting and deleting elements at the beginning and end of a sequence. Also, Deque elements can be scattered in different areas of storage while keeping track of each position and pointer.
Q10. A map
Q11. Satellite data are stored as vectors of suffices
Q12. ADvantages are: less repetition in code by using the standard library (Less pointers to create and clener code).
Q13. Drawbacks are: more memory allocation usually causing C++ to be slower than C
Q14. Stored as tuples
Q15. As hash table
Q16. Stored in a list object
Q17. I believe python is a lot easier to follow than C++ or C. There are no pointer in python, which makes the code cleaner with objects and references.
Q18. Drawbacks are: not being able to use pointers. Everything is stored in object. No real memory and data management line C++ with freeing and allocating memory.