Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) Write C++ implement a dictionary program using a table. The user inputs a wor

ID: 3767791 • Letter: 1

Question

1) Write C++ implement a dictionary program using a table. The user inputs a word and the word definition is displayed. Using a string as the search key and use a hash function implmentation.

2) C++ quicksort partition function so that the pivot is chosen by selecting median of 3 random values from the array. Next, write a version using five random values. This may reduce the running time. Test Both of these versions with sorted arrays, random arrays, and reverse order arrays and display your results.

Explanation / Answer

1)

#include <cstdlib>
#include <iostream>
#include <map>
using namespace std;

int main(int argc, char *argv[]){
map<char*,int> hashmap;
//input words
for (int i=0;i<5;i++){
char word[3];
cin>>word;
word[2] = '';
hashmap[word]=1; //key adding
}

//checking for word exists or not.
cout<<"Enter word to check:"<<endl;
char word[3];
cin>>word;
word[2]='';
//checking for value
bool notExists = hashmap.find(word)==hashmap.end();
cout<<((notExists)?"Yes!":"No.")<<endl;
return 0;
}

2)


int QuicksortPartition(int* arr, int start, int end)
{
//getting random pivot value
int pivot_element_index = start + rand() % (end - start + 1);
int pivotValue = arr[pivot_element_index ];

swap(&arr[pivot_element_index ], &arr[end]); // swap random pivot.
pivot_element_index = end;
int i = start -1;
//checking for value les than pivot
for(int j = start; j <= end - 1; j++)
{
//if value less than pivot ..swapping
if(arr[j] <= pivotValue)
{
i++;
swap(&arr[i], &arr[j]);
}
}
//correctly placing the position of pivot
swap(&arr[i + 1], &arr[pivot_element_index]);

return i + 1;
}