Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6929005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:15:45+00:00 2026-05-27T11:15:45+00:00

My insert function already handles collisions correctly but i want to be able to

  • 0

My insert function already handles collisions correctly but i want to be able to count the number of collisions in each different hashing way(chaining,linear probing, and quadratic probing). How would i go about doing this?

This my code so far:

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <iterator>
#include <ctime>
#include "Chaining.h"
#include "QuadraticProbing.h"
#include "LinearProbing.h"

using namespace std;

int main()
{
    int collision_count = 0;
    float diff = 0.0;
    clock_t tStart, tStop;
    string ITEM_NOT_FOUND = "ITEM_NOT_FOUND";
    std::vector<std::string> DataArray;
    std::copy(std::istream_iterator<std::string>(std::ifstream("OHenry.txt")),istream_iterator<string>(),back_inserter(DataArray));
    std::vector<std::string> QueryArray;
    std::copy(std::istream_iterator<std::string>(std::ifstream("queries.txt")),istream_iterator<string>(),back_inserter(QueryArray));

    cout << "Testing chaining probing...\n";
    HashTable_chaining ChainingHT( ITEM_NOT_FOUND, 101 );
    int i = 0;
    double average_c = 0.0;
    double total_c = 0.0;
    double temp_c = 0.0;
    while(i != DataArray.size())
    {
        tStart = clock();
        ChainingHT.insert(DataArray[i]);
        tStop = clock();
        total_c = tStop - tStart;
        temp_c = total_c + temp_c;
        average_c = total_c / DataArray.size(); 
        if(DataArray[i] != DataArray[NULL])
        {
            collision_count++;
        }
        i++;
    }   

    cout<<"The number of collisions using Chaining is: "<<collision_count<<endl;
    cout<<"The average time per insertion using Chaining is: "<<average_c<<endl;
    system("pause");
    // Quadratic Probing 
    cout << "Testing quadratic probing...\n";
    HashTable_chaining QuadraticProbingHT( ITEM_NOT_FOUND, 101 );   
    int j = 0;
    int collision_count_quadratic = 0;
    double average_qp = 0;
    while(j != DataArray.size())
    {
        clock_t tStartq = clock();
        QuadraticProbingHT.insert(DataArray[j]);
        if(DataArray[j] != DataArray[NULL])
        {
            collision_count_quadratic++;
        }
        j++;
        average_qp = (((double)(clock() - tStartq)/CLOCKS_PER_SEC) + average_qp) / DataArray.size();

    }   
    cout<<"The number of collisions using Quadratic is: "<<collision_count<<endl;
    cout<<"The average time per insertion using Quadratic is: "<<average_qp<<endl;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:15:45+00:00Added an answer on May 27, 2026 at 11:15 am

    It is possible to have the hashtable itself report the number of colissions it has seen without exposing its internal implementation at all.

    For hashtables that use probing (of any kind), the number of colissions is equal to the number of elements positioned at an index not consistent with their hash code (that is because the position they would normally have been stored in was already occupied).

    For hashtables that use chaining, the number of colissions is equal to the number of items in the hashtable, minus the number of occupied buckets (in other words, count all inserted items except the first in each bucket). This is also quite intuitive.

    So what I would do in your shoes is give each hashtable a count_colissions() method that calculates the number of colissions in O(n) time using the corresponding method and returns it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the insertWithOnConflict function in Android/SQLite to insert values that potentially already exist
I want to insert files into mysql from php function. The files that need
I am wondering if wordpress' insert function also adds slashes to data. If it
iam using a simple insert script function to pass the values from registration html
I am Looking for a Function that insert Any form values to mysql ,
I'm using folding-mode in emacs and was trying to make a function to insert
I have function: char *zap(char *ar) { char pie[100] = INSERT INTO test (nazwa,
I'm using the .load() function in jquery to insert the results of a php
Should I use textbox.text.Trim() function every time when I insert any data from web
I have a controller insert action: <AcceptVerbs(HttpVerbs.Post)> _ Function InsertObject(<Bind(Exclude:=Id)> <ModelBinder(GetType(CustomModelBinder))> ByVal object As

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.