hash table sort

Mar 7, 2020 at 8:26pm
Hello I have question about hash table and sort function. I have to make hash table which i have done. And now i must do a sort function. But i do not understand why. If i do this sort function, does this move all the buckets? What i mean is if i have 3 people in 3 buckets.

bucket 1 - Jón
bucket 2 - Ana
bucket 3 - Bób

When sort happens does the names move to different buckets and become in alphebtical? So would be

bucket 1 - Ana
bucket 2 - Bób
bucket 3 - Jón

Mar 7, 2020 at 9:32pm
Say my hash table is like this
array of 5 buckets
[0] -> list
[1] -> list
[2] -> list
[3] -> list
[4] -> list

Now, this is gonna split up the nodes according to key among the arrays, but it’s not necessarily going to order every individual list
So it could be
[0] -> 5 -> 20 -> 15 -> 35
[1] -> 21 -> 76
[2] ...
[3] ...
[4] ...
Or it could be
[0] -> 35 -> 20 -> 15 -> 5
[1] -> 76 -> 21
[2] ...
[3] ...
[4] ...
Last edited on Mar 7, 2020 at 9:33pm
Mar 7, 2020 at 9:39pm
ok so the sort function sorts each bucket into order, it does not move elements in the buckets? I think that make more sense to me why you would do this now. Before I did not understand why you would do this. Thank you
Mar 7, 2020 at 9:49pm
Yes it does not move elements to different buckets.
Last edited on Mar 7, 2020 at 9:50pm
Topic archived. No new replies allowed.