-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
71 changed files
with
2,528 additions
and
83 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
Binary file renamed
BIN
+185 KB
.../Debug/Cygwin-Windows/cis17cmidtermp4_1.0 → ....1/dist/Debug/Cygwin-Windows/cis17cmtp1.1
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
//Libraries | ||
#include <iostream> | ||
#include <cstdlib> | ||
#include <ctime> | ||
#include <chrono> | ||
using namespace std; | ||
|
||
|
||
//Function Prototypes | ||
void fillAry(int [],int,int,int); | ||
int binSrch(int [],int, int); | ||
|
||
|
||
int main(int argc, char** argv) | ||
{ | ||
//Set the random number seed | ||
srand(static_cast<unsigned int>(time(0))); | ||
|
||
//Declare all Variables Here | ||
const int SIZE=80000000; | ||
int *array = new int[SIZE]; | ||
int lowRng=0,highRng=SIZE; | ||
int loopCnt = 100000; | ||
int answer = 0; | ||
//double beg = time(0); | ||
//double endd = time(0); | ||
clock_t t; | ||
|
||
//Finish initializing the rest of the array | ||
fillAry(array,SIZE,highRng,lowRng); | ||
|
||
//Start time | ||
t = clock(); | ||
//beg = time(0); | ||
//auto start = high_resolution_clock::now(); | ||
|
||
//Test the binary search by looping randomly chosen values | ||
for(int i = 0; i < loopCnt; ++i) | ||
{ | ||
int value=rand()%(highRng-lowRng+1)+lowRng; | ||
answer += binSrch(array,SIZE,value); | ||
} | ||
|
||
// End time | ||
t = clock() - t; | ||
double time_taken = ((double)t)/CLOCKS_PER_SEC; | ||
//endd = time(0); | ||
//auto stop = high_resolution_clock::now(); | ||
//auto duration = duration_cast<microseconds>(stop - start); | ||
|
||
//Output | ||
cout<<"Array Size: "<<SIZE<<endl; | ||
cout<<"Loop Count: "<<loopCnt<<endl; | ||
cout<<"Operations: "<<answer / loopCnt<<endl; | ||
cout<<"Average Time: "<<time_taken / loopCnt<<" Seconds"<<endl; | ||
// cout<<"Average Time: "<<(endd-beg) / loopCnt<<" Seconds"<<endl; | ||
// cout<<"Average Time: "<<duration.count() / loopCnt<<" Micro Seconds"<<endl; | ||
|
||
//Exit | ||
delete [] array; | ||
return 0; | ||
} | ||
int binSrch(int a[],int n, int val) | ||
{ | ||
//Initialize Vars | ||
int lowEnd=0; | ||
int highEnd=n-1; | ||
int ops = 3; | ||
|
||
//Loop until value found not indexes | ||
do | ||
{ | ||
int middle=(highEnd+lowEnd)/2; | ||
ops += 12; | ||
if(val==a[middle])return ops; | ||
else if(val>a[middle])lowEnd=middle+1; | ||
else highEnd=middle-1; | ||
}while(lowEnd<=highEnd); | ||
|
||
//Not found | ||
return ops; | ||
} | ||
|
||
void fillAry(int a[],int n,int hr,int lr) | ||
{ | ||
for(int indx=0;indx<n;indx++){ | ||
a[indx]=rand()%(hr-lr+1)+lr; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project-private xmlns="http://www.netbeans.org/ns/project-private/1"> | ||
<data xmlns="http://www.netbeans.org/ns/make-project-private/1"> | ||
<activeConfTypeElem>1</activeConfTypeElem> | ||
<activeConfIndexElem>0</activeConfIndexElem> | ||
</data> | ||
</project-private> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
//Libraries | ||
#include <iostream> | ||
#include <cstdlib> | ||
#include <ctime> | ||
#include <chrono> | ||
|
||
using namespace std; | ||
using namespace chrono; | ||
|
||
//Function Prototypes | ||
void fillAry(int [],int,int,int); | ||
int linSrch(int [],int, int); | ||
|
||
|
||
int main(int argc, char** argv) | ||
{ | ||
//Set the random number seed | ||
srand(static_cast<unsigned int>(time(0))); | ||
|
||
//Declare all Variables Here | ||
const int SIZE=1000000; | ||
int *array = new int[SIZE]; | ||
int lowRng=0,highRng=SIZE; | ||
int loopCnt = 10000; | ||
int answer = 0; | ||
double beg = time(0); | ||
double endd = time(0); | ||
|
||
//Finish initializing the rest of the array | ||
fillAry(array,SIZE,highRng,lowRng); | ||
|
||
|
||
// Start time | ||
beg = time(0); | ||
auto start = high_resolution_clock::now(); | ||
|
||
//Test the linear search by looping randomly chosen values | ||
for(int i = 0; i < loopCnt; ++i) | ||
{ | ||
int value=rand()%(highRng-lowRng+1)+lowRng; | ||
answer += linSrch(array,SIZE,value); | ||
} | ||
// End time | ||
endd = time(0); | ||
auto stop = high_resolution_clock::now(); | ||
auto duration = duration_cast<microseconds>(stop - start); | ||
|
||
//Output results | ||
cout<<"Array Size: "<<SIZE<<endl; | ||
cout<<"Loop Count: "<<loopCnt<<endl; | ||
cout<<"Operations: "<<answer / loopCnt<<endl; | ||
cout<<"Average Time: "<<(endd-beg) / loopCnt<<" Seconds"<<endl; | ||
cout<<"Average Time: "<<duration.count() / loopCnt<<" Micro Seconds"<<endl; | ||
|
||
//Exit | ||
delete [] array; | ||
return 0; | ||
} | ||
int linSrch(int a[],int n, int val) | ||
{ | ||
|
||
int ops = 0; | ||
|
||
//Loop until value found | ||
for(int indx=0;indx<n;indx++) | ||
{ | ||
if(val==a[indx])return ops; | ||
ops += 5; | ||
} | ||
//Not found | ||
return ops; | ||
} | ||
|
||
void fillAry(int a[],int n,int hr,int lr) | ||
{ | ||
for(int indx=0;indx<n;indx++) | ||
{ | ||
a[indx]=rand()%(hr-lr+1)+lr; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.