How do you hash a string to SHA512 in Swift?

What is the time complexity of checking if an element is present in a hash table?

  • For example, consider this sample Python program to find the frequency of the letters: string = "aaabbbabababcccddcdcdcaacbbbcbbdddeffeeaa" def freq(string): hashmap = {} for x in string: if x in hashmap: hashmap[x] += 1 else: hashmap[x] = 1 return hashmap print freq(string) You just have to traverse the string once, but does the fact that you have to check if every element is in the hashmap add to the time complexity? So is the complexity [math] O(n) [/math] or more?

  • Answer:

    This thread contains some nice explanations: http://cs.stackexchange.com/q/249/906

Franck Dernoncourt at Quora Visit the source

Was this solution helpful to you?

Other answers

For chaining : Expected: O(1) or to be more precise  O(1+a) for both successful search and unsuccessful search; Worst Case: Can be O(n) For Probing: Expected: O(1/(1-a)) for  successful  search                 O( (1/a) ln( 1/(1-a) ) ) for  unsuccessful  search where  a is load factor of table. There also exists some other hashing techniques with different complexities. These two are most common.

Himanshu Bhardwaj

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.