Sort and Search Evaluation - C++ You are to compare two sorting algorithms and c
ID: 3681090 • Letter: S
Question
Sort and Search Evaluation - C++
You are to compare two sorting algorithms and compare two searching algorithms by running the algorithms and collecting data on each. Your data for sorting and searching will be strings of 15 characters in length. You are to have your program run, compute, and print all the results in one run, not multiples runs. (You are to run your program once for all data sets).
First part:
The two sorts to compare are the Bubble Sort and the Selection Sort. You are to test your sorts against different sets of strings. Each sort will sort six sets of data, 1000 strings, 3000 strings, 5000, 7000, 9000, and 11000 strings. You will compare how well each sort did with the different data sizes and show results. I would like to see a plot of the results. A table format showing results will do. Use the 'time' function and the 'difftime' function to gather sorts times. Show your answers with at least 4 places to the right of the decimal point.
Second part:
The two searches to use for comparisons are the Linear Search and the Binary Search. You will search for 3000 random strings in the array of 11000 strings array only and compute the average number of probes (not time!) needed to find a match. The target string will be a randomly selected string from the 11000 string's data set. You will randomly select 3000 strings for testing each search algorithm. Output the average number of probes needed for each search algorithm.
Third part:
How does your two search algorithms compare with the theoretical values?
Explanation / Answer
Bubble sort Solution :
Sub BubbleSort(MyArray() As String)
Local x,y As Long
For x = 1 To UBound(MyArray)-1
For y = x To UBound(MyArray)
If MyArray(x) > MyArray(y) Then Swap MyArray(x), MyArray(y)
Next y
Next y
End Sub
--------------------------------------------------------------------
#Compiler PBWin 9, PBWin 10
#Compile Exe
#Dim All
%Unicode=1
#Include "Win32API.inc"
%IDC_Button = 500
Global hDlg As Dword
Global qFreq, qStart, qStop As Quad
Type AdvancedPlan
desc As StringZ * 100
age As StringZ * 15
int As StringZ * 15
inf As StringZ * 15
altinf As StringZ * 15
lumpinc As StringZ * 15
socsec As StringZ * 15
workinc As StringZ * 15
otherinc As StringZ * 15
lumpexp As StringZ * 15
exp As StringZ * 15
altexp As StringZ * 15
End Type
Global Plan() As AdvancedPlan
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Button,"Test"
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_InitDialog
QueryPerformanceFrequency qFreq
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_Button
Local i,j As Long
For j = 100 To 1000 Step 100
ReDim Plan(j)
For i = 0 To UBound(tempPlan) : Plan(i).age = Str$(Rnd(1,10000)) : Next i
QueryPerformanceCounter qStart
Array Sort Plan(), Call CustomSort
QueryPerformanceCounter qStop
? "UBound:" + Str$(j) + " " + Format$((qStop-qStart)/qFreq,"###.000") & " seconds"
Next j
End Select
End Select
End Function
Function CustomSort(A As AdvancedPlan, B As AdvancedPlan) As Long
If Trim$(A.age) = "" Then Function = +1 : Exit Function
If Trim$(B.age) = "" Then Function = -1 : Exit Function
If Val(A.age) < Val(B.age) Then Function = -1 : Exit Function
If Val(A.age) > Val(B.age) Then Function = +1 : Exit Function
End Function
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.