Skip to content

Commit

Permalink
problem 4 finished problem 7 is .5
Browse files Browse the repository at this point in the history
  • Loading branch information
jasojone committed May 15, 2021
1 parent 3fcbbba commit 12055a4
Show file tree
Hide file tree
Showing 92 changed files with 5,669 additions and 38 deletions.
Binary file added Cis17cLabGeneralHashFunctions.zip
Binary file not shown.
26 changes: 11 additions & 15 deletions Cis17cLabGeneralHashFunctions/HashTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,13 @@ int main(int argc, char* argv[])
srand(static_cast<unsigned int>(time(0)));

// The size of the array
const int SIZE = 50000;
const int SIZE = 10000000;
// The search query size
const int QSIZE = 50;
// The size of the loop count for searches
const int TSIZE = 100000;
const int LSIZE = 1000;





string* randWords = fillary(SIZE, 20);
string* randWords2 = arrayCopy(randWords, SIZE);
string* randWords3 = arrayCopy(randWords, SIZE);
Expand All @@ -70,7 +66,7 @@ int main(int argc, char* argv[])
//cout << "Searching for key: " << key << endl;
double beg = time(0);
// for loop for 10,000 then time it
//cout << "Linear search :" << endl;
cout << "Linear search :" << endl;
for (int i = 0; i < LSIZE; i++)
{
for (int j = 0; j < QSIZE; j++)
Expand All @@ -79,13 +75,13 @@ int main(int argc, char* argv[])
}
}
double end = time(0);
//cout<<"For N = " << SIZE <<" Linear Search Takes " << setprecision(9) <<
// ((end-beg)/LSIZE)/QSIZE<<" Seconds " << "for " << LSIZE << " Searches" <<endl;
cout<<"For N = " << SIZE <<" Linear Search Takes " << setprecision(9) <<
((end-beg)/LSIZE)/QSIZE<<" Seconds " << "for " << LSIZE << " Searches" <<endl;
cout << ((end-beg)/LSIZE)/QSIZE << endl;
//selSort(randWords2, SIZE);
sort(randWords2, randWords2 + SIZE );

//cout << "Binary search :" << endl;
cout << "Binary search :" << endl;
beg = time(0);
// 1,000,000 times to search for 50 keys
for (int i = 0; i < TSIZE; i++ )
Expand All @@ -97,12 +93,12 @@ int main(int argc, char* argv[])
}
}
end = time(0);
// cout<<"For N = " << SIZE <<" Binary Search Takes " << setprecision(9) <<
// ((end-beg)/TSIZE)/QSIZE<<" Seconds " << "for " << TSIZE << " Searches" <<endl;
cout<<"For N = " << SIZE <<" Binary Search Takes " << setprecision(9) <<
((end-beg)/TSIZE)/QSIZE<<" Seconds " << "for " << TSIZE << " Searches" <<endl;
cout << ((end-beg)/TSIZE)/QSIZE << endl;
hasher(randWords3, hashList, SIZE);

// cout << "Hash search :" << endl;
cout << "Hash search :" << endl;
beg = time(0);
for (int i = 0; i < TSIZE; i++)
{
Expand All @@ -112,9 +108,9 @@ int main(int argc, char* argv[])
}
}
end = time(0);
//cout<<"For N = " << SIZE <<" Hash Search Takes " << setprecision(9) <<
// ((end-beg)/TSIZE)/QSIZE<<" Seconds " << "for " << TSIZE << " Searches" <<endl;
cout << ((end-beg)/TSIZE)/QSIZE << endl;
cout<<"For N = " << SIZE <<" Hash Search Takes " << setprecision(9) <<
((end-beg)/TSIZE)/QSIZE<<" Seconds " << "for " << TSIZE << " Searches" <<endl;
cout << ((end-beg)/TSIZE)/QSIZE << endl;
// cout << "Key: " <<key<<endl;
// cout << "Key: " << endl;
// cout << " 1. RS-Hash Function Value: " <<setw(15)<< RSHash(key)<<endl;
Expand Down
6 changes: 1 addition & 5 deletions cis17cLab4.4LinkedList/nbproject/private/private.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
</data>
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/C:/Users/Jason/OneDrive/Documents/GitHub/Cis17c2021/cis17cLab4.4LinkedList/main.cpp</file>
<file>file:/C:/Users/Jason/OneDrive/Documents/GitHub/Cis17c2021/cis17cLab4.4LinkedList/List.h</file>
<file>file:/C:/Users/Jason/OneDrive/Documents/GitHub/Cis17c2021/cis17cLab4.4LinkedList/Link.h</file>
</group>
<group/>
</open-files>
</project-private>
5 changes: 5 additions & 0 deletions cis17cLabBloomFilter1.0/.dep.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This code depends on make tool being used
DEPFILES=$(wildcard $(addsuffix .d, ${OBJECTFILES} ${TESTOBJECTFILES}))
ifneq (${DEPFILES},)
include ${DEPFILES}
endif
128 changes: 128 additions & 0 deletions cis17cLabBloomFilter1.0/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#
# There exist several targets which are by default empty and which can be
# used for execution of your targets. These targets are usually executed
# before and after some main targets. They are:
#
# .build-pre: called before 'build' target
# .build-post: called after 'build' target
# .clean-pre: called before 'clean' target
# .clean-post: called after 'clean' target
# .clobber-pre: called before 'clobber' target
# .clobber-post: called after 'clobber' target
# .all-pre: called before 'all' target
# .all-post: called after 'all' target
# .help-pre: called before 'help' target
# .help-post: called after 'help' target
#
# Targets beginning with '.' are not intended to be called on their own.
#
# Main targets can be executed directly, and they are:
#
# build build a specific configuration
# clean remove built files from a configuration
# clobber remove all built files
# all build all configurations
# help print help mesage
#
# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
# .help-impl are implemented in nbproject/makefile-impl.mk.
#
# Available make variables:
#
# CND_BASEDIR base directory for relative paths
# CND_DISTDIR default top distribution directory (build artifacts)
# CND_BUILDDIR default top build directory (object files, ...)
# CONF name of current configuration
# CND_PLATFORM_${CONF} platform name (current configuration)
# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration)
# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration)
# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration)
# CND_PACKAGE_DIR_${CONF} directory of package (current configuration)
# CND_PACKAGE_NAME_${CONF} name of package (current configuration)
# CND_PACKAGE_PATH_${CONF} path to package (current configuration)
#
# NOCDDL


# Environment
MKDIR=mkdir
CP=cp
CCADMIN=CCadmin


# build
build: .build-post

.build-pre:
# Add your pre 'build' code here...

.build-post: .build-impl
# Add your post 'build' code here...


# clean
clean: .clean-post

.clean-pre:
# Add your pre 'clean' code here...

.clean-post: .clean-impl
# Add your post 'clean' code here...


# clobber
clobber: .clobber-post

.clobber-pre:
# Add your pre 'clobber' code here...

.clobber-post: .clobber-impl
# Add your post 'clobber' code here...


# all
all: .all-post

.all-pre:
# Add your pre 'all' code here...

.all-post: .all-impl
# Add your post 'all' code here...


# build tests
build-tests: .build-tests-post

.build-tests-pre:
# Add your pre 'build-tests' code here...

.build-tests-post: .build-tests-impl
# Add your post 'build-tests' code here...


# run tests
test: .test-post

.test-pre: build-tests
# Add your pre 'test' code here...

.test-post: .test-impl
# Add your post 'test' code here...


# help
help: .help-post

.help-pre:
# Add your pre 'help' code here...

.help-post: .help-impl
# Add your post 'help' code here...



# include project implementation makefile
include nbproject/Makefile-impl.mk

# include project make variables
include nbproject/Makefile-variables.mk
116 changes: 116 additions & 0 deletions cis17cLabBloomFilter1.0/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// Pulled from G for G
//
//


#include <bits/stdc++.h>
#define ll long long
using namespace std;

// hash 1
int h1(string s, int arrSize)
{
ll int hash = 0;
for (int i = 0; i < s.size(); i++)
{
hash = (hash + ((int)s[i]));
hash = hash % arrSize;
}
return hash;
}

// hash 2
int h2(string s, int arrSize)
{
ll int hash = 1;
for (int i = 0; i < s.size(); i++)
{
hash = hash + pow(19, i) * s[i];
hash = hash % arrSize;
}
return hash % arrSize;
}

// hash 3
int h3(string s, int arrSize)
{
ll int hash = 7;
for (int i = 0; i < s.size(); i++)
{
hash = (hash * 31 + s[i]) % arrSize;
}
return hash % arrSize;
}

// hash 4
int h4(string s, int arrSize)
{
ll int hash = 3;
int p = 7;
for (int i = 0; i < s.size(); i++) {
hash += hash * 7 + s[0] * pow(p, i);
hash = hash % arrSize;
}
return hash;
}


// loookup operation
bool lookup(bool* bitarray, int arrSize, string s)
{
int a = h1(s, arrSize);
int b = h2(s, arrSize);
int c = h3(s, arrSize);
int d = h4(s, arrSize);

if (bitarray[a] && bitarray[b] && bitarray
&& bitarray[d])
return true;
else
return false;
}

// insert operation
void insert(bool* bitarray, int arrSize, string s)
{
// check if the element in already present or not
if (lookup(bitarray, arrSize, s))
cout << s << " is Probably already present" << endl;
else
{
int a = h1(s, arrSize);
int b = h2(s, arrSize);
int c = h3(s, arrSize);
int d = h4(s, arrSize);

bitarray[a] = true;
bitarray[b] = true;
bitarray = true;
bitarray[d] = true;

cout << s << " inserted" << endl;
}
}

// Driver Code
int main()
{
bool bitarray[100] = { false };
int arrSize = 100;
string sarray[33]
= { "abound", "abounds", "abundance",
"abundant", "accessable", "bloom",
"blossom", "bolster", "bonny",
"bonus", "bonuses", "coherent",
"cohesive", "colorful", "comely",
"comfort", "gems", "generosity",
"generous", "generously", "genial",
"bluff", "cheater", "hate",
"war", "humanity", "racism",
"hurt", "nuke", "gloomy",
"facebook", "geeksforgeeks", "twitter" };
for (int i = 0; i < 33; i++) {
insert(bitarray, arrSize, sarray[i]);
}
return 0;
}
Loading

0 comments on commit 12055a4

Please sign in to comment.