日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

txt如何单独单独选择一列_散列| 单独链接以解决冲突

發布時間:2023/12/1 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 txt如何单独单独选择一列_散列| 单独链接以解决冲突 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

txt如何單獨單獨選擇一列

Prerequisite: Hashing data structure

先決條件: 哈希數據結構

單獨鏈接 (Separate chaining)

In separate chaining, we maintain a linked chain for every index in the hash table. So whenever there is a Collison the linked list is extended for that particular location of the hash table.

單獨的鏈接中 ,我們為哈希表中的每個索引維護一個鏈接鏈。 因此,只要有Collison,鏈表都會擴展到哈希表的特定位置。

We can visualize the separate chaining method with the following example,

通過以下示例,我們可以可視化單獨的鏈接方法:

Key set: {123, 456, 763, 656, 908, 238, 231} Hash function: f(x) = x%10

Step 1: Inserting 123 in the hash map. So, location is 3.

步驟1:在哈希圖中插入123。 因此,位置為3。

Index keys 0 NULL 1 NULL 2 NULL 3 123->NULL 4 NULL 5 NULL 6 NULL 7 NULL 8 NULL 9 NULL

Step 2: Inserting 456 in the hash map. So, location is 3.

步驟2:在哈希圖中插入456。 因此,位置為3。

Index keys 0 NULL 1 NULL 2 NULL 3 123->NULL 4 NULL 5 NULL 6 456->NULL 7 NULL 8 NULL 9 NULL

Step 3: Inserting 763 in the hash map. So, location is 3.

步驟3:在哈希圖中插入763。 因此,位置為3。

Index keys 0 NULL 1 NULL 2 NULL 3 123->763->NULL 4 NULL 5 NULL 6 456->NULL 7 NULL 8 NULL 9 NULL

Step 4: Inserting 656 in the hash map. So, location is 6.

步驟4:在哈希圖中插入656。 因此,位置為6。

Index Keys 0 NULL 1 NULL 2 NULL 3 123->763->NULL 4 NULL 5 NULL 6 456->656->NULL 7 NULL 8 NULL 9 NULL

Step 5: Inserting 908 in the hash map. So, location is 8.

步驟5:在哈希圖中插入908。 因此,位置為8。

Index Keys 0 NULL 1 NULL 2 NULL 3 123->763->NULL 4 NULL 5 NULL 6 456->656->NULL 7 NULL 8 908->NULL 9 NULL

Step 6: Inserting 238 in the hash map. So, location is 8.

步驟6:在哈希圖中插入238。 因此,位置為8。

Index Keys 0 NULL 1 NULL 2 NULL 3 123->763->NULL 4 NULL 5 NULL 6 456->656->NULL 7 NULL 8 908->238->NULL 9 NULL

Step 7: Inserting 231 in the hash map. So, location is 8.

步驟7:在哈希圖中插入231。 因此,位置為8。

Index Keys 0 NULL 1 231->NULL 2 NULL 3 123->763->NULL 4 NULL 5 NULL 6 456->656->NULL 7 NULL 8 908->238->NULL 9 NULL

So, the above thing is called as separate chaining as we have chained the collided elements within the hash table.

因此,由于我們在哈希表中鏈接了沖突的元素,因此上述事情稱為單獨鏈接。

Performance analysis:

性能分析:

Load factor = n/m, n = number of keys inserted, m = number of indices in the hash table() size of hash tableSearch complexity = O(load factor) Insertion complexity = O(1) Deletion complexity = O(load factor)

單獨鏈接的優缺點 (Advantage and disadvantages of separate chaining)

Advantages are,

優點是

  • We can add as many keys as we want to add

    我們可以添加任意數量的鍵

  • It's simpler than open addressing to implement

    它比開放地址更容易實現

Disadvantages are,

缺點是

  • It uses extra spaces for links

    它為鏈接使用多余的空間

  • If the collision rate is high, the search complexity increases as load factor increases

    如果沖突率很高,則搜索復雜度會隨著負載因子的增加而增加

單獨鏈接的C ++實現 (C++ implementation of separate chaining)

//separate chaining #include <bits/stdc++.h> using namespace std;class node { public:int data;node* next;node(){data = 0;next = NULL;}node(int x){data = x;next = NULL;} };node* add(node* head, int data) {if (head == NULL) {head = new node(data);return head;}node* temp = head;while (temp->next) {temp = temp->next;}temp->next = new node(data);return head; }void print(node* head) {if (!head) {cout << "NULL\n";return;}node* temp = head;while (temp) {cout << temp->data << "->";temp = temp->next;}cout << "NULL\n"; }int main() {//set of input numbersvector<int> arr{ 123, 456, 763, 656, 908, 238, 231 };//initialize the hash table//each entry of the hash table is a linkedlistvector<node*> hash(10); //size of hashtable is 10//using hash function f(x)=no of digits in xfor (int a : arr) {hash[a % 10] = add(hash[a % 10], a);}cout << "Hash table is:\n";for (int i = 0; i < 10; i++) {cout << i << "---- ";print(hash[i]);}return 0; }

Output:

輸出:

Hash table is: 0---- NULL 1---- 231->NULL 2---- NULL 3---- 123->763->NULL 4---- NULL 5---- NULL 6---- 456->656->NULL 7---- NULL 8---- 908->238->NULL 9---- NULL

翻譯自: https://www.includehelp.com/data-structure-tutorial/hashing-separate-chaining-for-collision-resolution.aspx

txt如何單獨單獨選擇一列

總結

以上是生活随笔為你收集整理的txt如何单独单独选择一列_散列| 单独链接以解决冲突的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。