You are on page 1of 4

Paul Ovidiu Cioanca

Group 912
Find all the anagrams of a given word
An anagram of a word is the result of rearranging the letters of a word to produce a new word,
using all the original letters, and having the same letter frequencies.
12. Define ADT Multimap; representation: dynamic linked list.
13. Define ADT Multimap; representation: hashtable, collision resolution through chaining.
ADT Multimap - dynamic linked list
multimap.h - contains the template for the multimap with class definition, parameters, and
implementation of the class methods
main.cpp - contains the main file of the project, declaring the multimap and loading the file into
it

Problem solving method


- The program reads the wordlist and loads it into memory using a linked list, the key being the
word sorted in ascending alphabetical order. If any other words while being sorted in an
ascending order are identical to the key, it means they are anagrams, and such, links them
together.
- The user is prompted for a word. The word is sorted and checked against all existing keys. If
an identical key is found, all the words having that key will be printed. Otherwise, if the word
doesn't exist, an error message will be shown.
- The user can input '0' to end program execution.

Operations
TElem = record:
Key: Key
Value: Value
next: ^TElem
nextKey: ^TElem

end record
MultiMap = record:
_size: int
_first: ^TElem
_last: ^TElem
end record
subalg insert(key, value)
if _size = 0 do
s.value <- value
s.key <- sortKey(key)
s.next <- NUL
s.nextKEY <- NUL
else
s <- findKey(sortKey(key))
if s.value = "-1" do
s.value <- value
s.key <- sortKey(key)
s.next <- NUL
s.nextKEY <- NUL
_last.nextKey <- s
_last <- s
else
while s.next != NUL do
s<-s.next
endwhile
s.next <- d
d.nextKey <- NUL
d.next <- NUL
d.value <- value
d.key <- sortKey(key)
endif
endif
_size <- _size + 1
end insert
funct findKey(key)
s <- _first
while s!=NUL do
if s.key = key do
return s
end if
s <- s.nextKey

end while
d.value <- "-1"
return d;
end findKey

ADT Multimap - hashtable, collision resolution through chaining


multimap.h - contains the template for the multimap with class definition, parameters, and
implementation of the class methods
main.cpp - contains the main file of the project, declaring the multimap and loading the file into
it

Problem solving method


- The program reads the wordlist and loads it into memory using a TElem array, the key being
the word ran through a hash function. If any other words while being hashed to the key, it
means they are anagrams, and such, links them together.
- The user is prompted for a word. The word is sorted and checked against all existing keys. If
an identical key is found, all the words having that key will be printed. Otherwise, if the word
doesn't exist, an error message will be shown.
- The user can input '0' to end program execution.
Operations
TElem = record:
Key: Key
Value: Value
next: ^TElem
nextKey: ^TElem
end record
MultiMap = record:
_size: int
_array: ^^TElem
end record
subalg insert(key, value)

hashValue <- HashFunction(key)


s = _array[hashValue]
prev = NUL
while s != NUL do
prev <- s
s <- s.next
end while
if s = NUL do
s.value <- value
s.key <- hashValue
s.next <- NUL
if prev = NUL do
_array[hashValue] <- s
else
prev.next <- s
end if
end if
_size <- size + 1
end insert