hashtable

Hash table runtime complexity (insert, search and delete)

不羁岁月 提交于 2019-11-26 03:08:40
问题 Why do I keep seeing different runtime complexities for these functions on a hash table? On wiki, search and delete are O(n) (I thought the point of hash tables was to have constant lookup so what\'s the point if search is O(n)). In some course notes from a while ago, I see a wide range of complexities depending on certain details including one with all O(1). Why would any other implementation be used if I can get all O(1)? If I\'m using standard hash tables in a language like C++ or Java,

Hash tables in MATLAB

断了今生、忘了曾经 提交于 2019-11-26 03:05:10
问题 Does MATLAB have any support for hash tables? Some background I am working on a problem in Matlab that requires a scale-space representation of an image. To do this I create a 2-D Gaussian filter with variance sigma*s^k for k in some range., and then I use each one in turn to filter the image. Now, I want some sort of mapping from k to the filtered image. If k were always an integer, I\'d simply create a 3D array such that: arr[k] = <image filtered with k-th guassian> However, k is not

.NET HashTable Vs Dictionary - Can the Dictionary be as fast?

纵然是瞬间 提交于 2019-11-26 02:39:50
问题 I am trying to figure out when and why to use a Dictionary or a HashTable. I have done a bit of a search on here and have found people talking about the generic advantages of the Dictionary which I totally agree with, which leads the boxing and unboxing advantage for a slight performance gain. But I have also read the Dictionary will not always return the objects in the order they are inserted, thing it is sorted. Where as a HashTable will. As I understand it this leads to the HashTable being

How do HashTables deal with collisions?

本秂侑毒 提交于 2019-11-26 02:27:41
问题 I\'ve heard in my degree classes that a HashTable will place a new entry into the \'next available\' bucket if the new Key entry collides with another. How would the HashTable still return the correct Value if this collision occurs when calling for one back with the collision key? I\'m assuming that the Keys are String type and the hashCode() returns the default generated by say Java. If I implement my own hashing function and use it as part of a look-up table (i.e. a HashMap or Dictionary ),

Can hash tables really be O(1)?

╄→尐↘猪︶ㄣ 提交于 2019-11-26 01:33:26
问题 It seems to be common knowledge that hash tables can achieve O(1), but that has never made sense to me. Can someone please explain it? Here are two situations that come to mind: A. The value is an int smaller than the size of the hash table. Therefore, the value is its own hash, so there is no hash table. But if there was, it would be O(1) and still be inefficient. B. You have to calculate a hash of the value. In this situation, the order is O(n) for the size of the data being looked up. The

How to define hash tables in Bash?

筅森魡賤 提交于 2019-11-26 01:29:16
问题 What is the equivalent of Python dictionaries but in Bash (should work across OS X and Linux). 回答1: Bash 4 Bash 4 natively supports this feature. Make sure your script's hashbang is #!/usr/bin/env bash or #!/bin/bash so you don't end up using sh . Make sure you're either executing your script directly, or execute script with bash script . (Not actually executing a Bash script with Bash does happen, and will be really confusing!) You declare an associative array by doing: declare -A animals

How does a hash table work?

故事扮演 提交于 2019-11-26 01:25:38
问题 I\'m looking for an explanation of how a hash table works - in plain English for a simpleton like me! For example, I know it takes the key, calculates the hash (I am looking for an explanation how) and then performs some kind of modulo to work out where it lies in the array where the value is stored, but that\'s where my knowledge stops. Could anyone clarify the process? Edit: I\'m not asking specifically about how hash codes are calculated, but a general overview of how a hash table works.

How to implement an efficient bidirectional hash table?

牧云@^-^@ 提交于 2019-11-26 01:14:57
问题 Python dict is a very useful data-structure: d = {\'a\': 1, \'b\': 2} d[\'a\'] # get 1 Sometimes you\'d also like to index by values. d[1] # get \'a\' Which is the most efficient way to implement this data-structure? Any official recommend way to do it? 回答1: Here is a class for a bidirectional dict , inspired by Finding key from value in Python dictionary and modified to allow the following 2) and 3). Note that : 1) The inverse directory bd.inverse auto-updates itself when the standard dict

hash function for string

廉价感情. 提交于 2019-11-26 00:27:03
问题 I\'m working on hash table in C language and I\'m testing hash function for string. The first function I\'ve tried is to add ascii code and use modulo (%100) but i\'ve got poor results with the first test of data: 40 collisions for 130 words. The final input data will contain 8 000 words (it\'s a dictionnary stores in a file). The hash table is declared as int table[10000] and contains the position of the word in a txt file. The first question is which is the best algorithm for hashing string

Good Hash Function for Strings

自闭症网瘾萝莉.ら 提交于 2019-11-25 23:50:23
I'm trying to think up a good hash function for strings. And I was thinking it might be a good idea to sum up the unicode values for the first five characters in the string (assuming it has five, otherwise stop where it ends). Would that be a good idea, or is it a bad one? I am doing this in Java, but I wouldn't imagine that would make much of a difference. jonathanasdf Usually hashes wouldn't do sums, otherwise stop and pots will have the same hash. and you wouldn't limit it to the first n characters because otherwise house and houses would have the same hash. Generally hashs take values and