INPUT: Two lists L1 and L2
QUESTION: Do L1 and L2 represent the same list?
(That is, do L1 and L2 contain the same numbers, each appearing exactly the same number of times?).
My Solution:
temp = head->L1
while search_L2(temp) == true
temp = temp->next
if search_L2(temp) == false
OUTPUT: L1 does not represent L2
Is this a correct algorithm?
Could this algorithm be a randomized algorithm (possibly using hash functions?). If so, how is it possible?
I'm using C++.
How could I Be able to:
You would probably be better off using two hash tables. Populate these by traversing each list. Then, compare the keys in the hash tables to determine if they contain the same numbers. The key of the hash table can be the numbers in the list and the values can be the count of occurrences.
2006-11-27
06:19:33
·
2 answers
·
asked by
ff3101
1