diff --git a/lab07/l7 b/lab07/l7 index 89f483d7c78343a9e1ec7782d38b31afab4308ee..945d464d64e33c57da551a80bbf1fbd1602fcef6 100644 --- a/lab07/l7 +++ b/lab07/l7 @@ -4,10 +4,30 @@ The difference is that the two functions take different argument type to travers Meanwhile, "addSuffix" has the prefix as the input. It looks up in the statetab if there is that prefix in there, then add the suffix to the state that has that prefix. if not, it creates 1. Then it add the suffix in to the suffix component of the newly created state with the new prefix. + Q2: +Lookup does what its name says, to look up if there exists a prefix (that is the same as the input prefix) in the states in the statetab. If the prefix is found in a particular state, the pointer to the state is returned. If not, the function will look into the boolean argument "create" given to it and decide whether to create a new state with the input prefix or not. Function add() and generate() call this function. Q3: include a picture of the table later + +The following table is created with random hash value assigned to the states and assuming the prefix pairs (NULL; it's) and (a; new) have the same hash values; (NULL;NULL) and (it's; a) have the same hash value. + +statetab[hashValue 1] --> | next | -----------> | next | ---> NULL + | pref[0] | ---> NULL | pref[0] | ---> It's + | pref[1] | ---> NULL | pref[1] | ---> a + | suffix | ---> It's | suffix | ---> new + +statetab[hashValue 2] --> | next | -----------> | next | ---> NULL + | pref[0] | ---> NULL | pref[0] | ---> a + | pref[1] | ---> It's | pref[1] | ---> new + | suffix | ---> a | suffix | ---> dawn + +statetab[hashValue 3] --> | next | ---> NULL + | pref[0] | ---> new + | pref[1] | ---> dawn + | suffix | ---> NULL + Number of pointers: It's : 3 a: 3 @@ -67,4 +87,17 @@ Q13: Disadvantage: In contrast to the advantage of the C implementation, this one consume more memory as it stores multiple duplications of the same word in different suffix vectors and also as prefixes in many places. Q14: +The prefix are store in tuples of 2 elements that are keys to a python dictionary + +Q15: +the Python built in dictionary replaces the hash table + +Q16: The list of suffices is store in a list, which is the value to the table dictionary + +Q17: +Advantages: +Take less lines of code to write the program that does the same objectives. The dictionary built in Python used a close hash function so there should not be collisions that happen as in the C implemetation. +Q18: +Disadvantages: +Takes more time to compile. Has to be interpreted first , then compiled. So the performance in terms of time elpapsed is worse than C and C++, which are directly compiled.