SlideShare a Scribd company logo
1 of 13
Data Structures & Algorithms
Coursework Assignment for Semester 2, 2016-17
Due Date: Friday 12th May 2017
An examination of the number of comparisons needed for
successful searches of sorted arrays using ten different search
algorithms
SID Number: XXXXXXX
Instructions
1. In this assignment, you will analyse some array search
algorithms using MATLAB. The first search algorithm (linear
search) is analysed for you as an example. There are 10 marks
available for each of the remaining search algorithms to be
analysed. Test your algorithms before analysing them to ensure
that they operate correctly (e.g., using small arrays passed to
your functions from the Command Window).
2. Complete the report in exactly the format given here (i.e., fill
in the sections and do not change the structure of the
document). 10 marks will be awarded for keeping the document
in the correct format as you complete the report. In particular,
note that code should be pasted directly from MATLAB, in
order that a fixed-width font is used, and to ensure that
indentation is maintained.
3. Your printed report must be submitted with a CD or USB
drive containing your source code (functions for each search
algorithm and test harnesses). Work must be submitted to the
iCentre by the published deadline. This assignment is worth
50% of your grade for the module.
4. Some initial references are provided, but further research will
be needed to learn about the search algorithms that have not
been discussed in class. Additional references should be added
to the Harvard style reference list to acknowledge the sources
consulted. Use reliable sources wherever possible.
5. In the mark scheme (shown below) insert 0s for any
algorithms or subsections not completed to determine the
maximum possible mark that you can score and to indicate
which parts were attempted.
Mark Scheme
Algorithm
Subsection 1
Subsection 2
Subsection 3
Subsection 4
Subsection 5
Marks
1. Linear
N/A
N/A
N/A
N/A
N/A
N/A
2. Random
0..2
0..2
0..2
0..2
0..2
0..10
3. Jump
0..2
0..2
0..2
0..2
0..2
0..10
4. K-level Jump
0..2
0..2
0..2
0..2
0..2
0..10
5. Exponential
0..2
0..2
0..2
0..2
0..2
0..10
6. Fibonaccian
0..2
0..2
0..2
0..2
0..2
0..10
7. Binary
0..2
0..2
0..2
0..2
0..2
0..10
8. Ternary
0..2
0..2
0..2
0..2
0..2
0..10
9. Interpolation-Sequential
0..2
0..2
0..2
0..2
0..2
0..10
10. Interpolation
0..2
0..2
0..2
0..2
0..2
0..10
Presentation
0..10
Total Marks
0..100
Table of Contents
1. Linear Search (Sequential Search)
1.1 Basic logic used by the algorithm
1.2 Published and/or theoretically deduced time complexity
1.3 Presentation of algorithm as a function in MATLAB
1.4 Presentation of successful search test results graphs for
increasing array sizes
1.5 Discussion of results
2. Random Search
2.1 Basic logic used by the algorithm
2.2 Published and/or theoretically deduced time complexity
2.3 Presentation of algorithm as a function in MATLAB
2.4 Presentation of successful search test results graphs for
increasing array sizes
2.5 Discussion of results
3. Jump Search (Block Search)
3.1 Basic logic used by the algorithm
3.2 Published and/or theoretically deduced time complexity
3.3 Presentation of algorithm as a function in MATLAB
3.4 Presentation of successful search test results graphs for
increasing array sizes
3.5 Discussion of results
4. K-level Jump Search
4.1 Basic logic used by the algorithm
4.2 Published and/or theoretically deduced time complexity
4.3 Presentation of algorithm as a function in MATLAB
4.4 Presentation of successful search test results graphs for
increasing array sizes
4.5 Discussion of results
5. Exponential Search (Doubling Search, Galloping Search)
5.1 Basic logic used by the algorithm
5.2 Published and/or theoretically deduced time complexity
5.3 Presentation of algorithm as a function in MATLAB
5.4 Presentation of successful search test results graphs for
increasing array sizes
5.5 Discussion of results
6. Fibonaccian Search
6.1 Basic logic used by the algorithm
6.2 Published and/or theoretically deduced time complexity
6.3 Presentation of algorithm as a function in MATLAB
6.4 Presentation of successful search test results graphs for
increasing array sizes
6.5 Discussion of results
7. Binary Search (Half-interval Search, Logarithmic Search)
7.1 Basic logic used by the algorithm
7.2 Published and/or theoretically deduced time complexity
7.3 Presentation of algorithm as a function in MATLAB
7.4 Presentation of successful search test results graphs for
increasing array sizes
7.5 Discussion of results
8. Ternary Search
8.1 Basic logic used by the algorithm
8.2 Published and/or theoretically deduced time complexity
8.3 Presentation of algorithm as a function in MATLAB
8.4 Presentation of successful search test results graphs for
increasing array sizes
8.5 Discussion of results
9. Interpolation-Sequential Search
9.1 Basic logic used by the algorithm
9.2 Published and/or theoretically deduced time complexity
9.3 Presentation of algorithm as a function in MATLAB
9.4 Presentation of successful search test results graphs for
increasing array sizes
9.5 Discussion of results
10. Interpolation Search (Predictive Search)
10.1 Basic logic used by the algorithm
10.2 Published and/or theoretically deduced time complexity
10.3 Presentation of algorithm as a function in MATLAB
10.4 Presentation of successful search test results graphs for
increasing array sizes
10.5 Discussion of results
Appendix A: Test Harness for Deterministic Search Algorithms
Appendix B: Test Harness for Non-deterministic Search
Algorithms
List of Figures
Figure 1: Min, average, and max comparisons for linear search
for array sizes [0..1024].
Figure 2: Min, average, and max comparisons for random search
for array sizes [0..1024].
Figure 3: Min, average, and max comparisons for jump search
for array sizes [0..1024].
Figure 4: Min, average, and max comparisons for k-level jump
search for array sizes [0..1024].
Figure 5: Min, average, and max comparisons for exponential
search for array sizes [0..1024].
Figure 6: Min, average, and max comparisons for Fibonaccian
search for array sizes [0..1024].
Figure 7: Min, average, and max comparisons for binary search
for array sizes [0..1024].
Figure 8: Min, average, and max comparisons for ternary search
for array sizes [0..1024].
Figure 9: Min, average, and max comparisons for interpolation-
sequential search for array sizes [0..1024].
Figure 10: Min, average, and max comparisons for interpolation
search for array sizes [0..1024].
List of Tables
Table 1: Time complexity summary for linear search.
Table 2: Time complexity summary for random search.
Table 3: Time complexity summary for jump search.
Table 4: Time complexity summary for k-level jump search.
Table 5: Time complexity summary for exponential search.
Table 6: Time complexity summary for Fibonaccian search.
Table 7: Time complexity summary for binary search.
Table 8: Time complexity summary for ternary search.
Table 9: Time complexity summary for interpolation-sequential
search.
Table 10: Time complexity summary for interpolation search.
List of Files on Attached Media
linearSearch.m linearSearchTestHarness.m
randomSearch.m
randomSearchTestHarness.m
jumpSearch.m jumpSearchTestHarness.m
kLevelJumpSearch.m
kLevelJumpSearchTestHarness.m
exponentialSearch.m
exponentialSearchTestHarness.m
fibonaccianSearch.m
fibonaccianSearchTestHarness.m
binarySearch.m binarySearchTestHarness.m
ternarySearch.m ternarySearchTestHarness.m
interpolationSequentialSearch.m
interpolationSequentialSearchTestHarness.m
interpolationSearch.m
interpolationSearchTestHarness.m
1. Linear Search (Sequential Search)
1.1 Basic logic used by the algorithm
The linear search algorithm compares a search target to the
value in each element [1..N] of an array sequentially, starting
from the first element (here, element 1). The search terminates
if one of two things happens: 1. the search target is found; 2.
the end of the array is reached. In the event that the target is
found, the array index in which it was found is returned. In the
event that the end of the array is reached and the search target
has not been found, a fail token is returned (here, -1).
1.2 Published and/or theoretically deduced time complexity
For successful searches, the best case occurs when the target is
found in the first index examined (i.e., index 1, requiring one
comparison). The worst case occurs when the search target is
found in the final element (at index N, requiring N
comparisons). The average case is that the search target is found
in the centre of the array, at index 0.5N, taking 0.5N
comparisons. These time complexities are summarised in Table
1.
Best Case
Average Case
Worst Case
Linear Search (Successful)
O(1)
O(n)
O(n)
Table 1: Time complexity summary for linear search.
1.3 Presentation of algorithm as a function in MATLAB
function [numComparisons, currentIndex] = linearSearch(V,
target)
numComparisons = 0;
for currentIndex=1:length(V)
numComparisons = numComparisons + 1;
if(V(currentIndex) == target)
break;
end
end
if(V(currentIndex)~=target)
currentIndex = -1;
end
end
The MATLAB source code for this algorithm is provided on the
attached disk, filename linearSearch.m
1.4 Presentation of successful search test results graphs for
increasing array sizes
Results for a successful linear search of array sizes 1..1024 are
shown in Fig. 1.
Figure 1: Min (green), average (yellow), and max (red)
comparisons for linear search of an array of size [0..1024].
Dotted lines show expected (theoretically deduced) min,
average and max.
1.5 Discussion of results
The observed test results (coloured lines) are in good agreement
with the published (expected) time complexities for a linear
search (dotted lines). The best case (minimum number of
comparisons required) was always one (green line), irrespective
of array length. The worst case (maximum number of
comparisons required) was always equal to the array length (red
line), occurring when the search target was found in the final
element. The average case was 0.5N, representing the average
of all possible outcomes (yellow line), which is that the search
target is found in the centre of the array. The average and worst
cases therefore grew linearly as the size of the array increased
as functions y = x/2 and y = x, respectively (i.e., as arithmetic
progressions). If the array size were doubled, the best case
would remain constant (at 1), and the average and worst cases
would also double.
References
Shneiderman, B. (1978). Jump Searching: A Fast Sequential
Search Technique, Communications of the ACM, 21(10), 831-
834. [Jump Search].
Bentley, J. L. and Yao, A. C. (1976). An almost optimal
algorithm for unbounded searching. Information Processing
Letters, 5(3), 82–87. [Exponential Search].
Ferguson, D. E. (1960). Fibonaccian searching.
Communications of the ACM, 3(12), 648. [Fibonaccian Search].
Perl, Y., Itai, A., & Avni, H. (1978). Interpolation search — a
log log N search. Communications of the ACM, 21(7), 550-553.
[Interpolation Search].
Appendix A: Test Harness for Deterministic Search Algorithms
Array sizes from 1..maxArraySize are tested, where
maxArraySize = 1024. The current array size being tested is
held in variable N. The sequence [1..N] is placed in the current
array. Values [1..N] are used as search targets, one at a time.
Best (minimum), average (arithmetic mean) and worst
(maximum) number of comparisons performed for each array
size are collected. A graph of N against comparisons is
displayed, with three lines (minimum, average and maximum).
Expected performance is also plotted (dotted lines).
clear all;close all;clc;
maxArraySize = 1024;
for N = 1:maxArraySize
array = 1:N;
for searchTarget = 1:N
comparisons(searchTarget) = linearSearch(array,
searchTarget);
end
min_comps(N) = min(comparisons);
avg_comps(N) = mean(comparisons);
max_comps(N) = max(comparisons);
clear comparisons;
end
figure;
% Plot Observed
plot([1:maxArraySize], min_comps,'g','LineWidth',3);hold on;
plot([1:maxArraySize], avg_comps,'y','LineWidth',3);
plot([1:maxArraySize], max_comps,'r','LineWidth',3);
legend('min','mean','max');
% Plot Expected
plot([1:maxArraySize], linspace(1,1,maxArraySize), 'k:');
plot([1:maxArraySize], linspace(1,N/2,maxArraySize), 'k:');
plot([1:maxArraySize], linspace(1,N,maxArraySize), 'k:');
% Annotate Chart
xlabel('Array Size (N)','FontSize',14);
ylabel('Comparisons', 'FontSize', 14);
title('Linear Search (Successful)','FontSize', 14);
xlim([0 maxArraySize]);
ylim([0 max(max_comps)]);
modify as required
print -f1 -r300 -dbmp linearSearchSuccessful.bmp
2

More Related Content

Similar to Data Structures & Algorithms Coursework Assignment for Sem.docx

Ch24 efficient algorithms
Ch24 efficient algorithmsCh24 efficient algorithms
Ch24 efficient algorithmsrajatmay1992
 
Chapter 16-spreadsheet1 questions and answer
Chapter 16-spreadsheet1  questions and answerChapter 16-spreadsheet1  questions and answer
Chapter 16-spreadsheet1 questions and answerRaajTech
 
VCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxVCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxskilljiolms
 
ADSA orientation.pptx
ADSA orientation.pptxADSA orientation.pptx
ADSA orientation.pptxKiran Babar
 
01 Notes Introduction Analysis of Algorithms Notes
01 Notes Introduction Analysis of Algorithms Notes01 Notes Introduction Analysis of Algorithms Notes
01 Notes Introduction Analysis of Algorithms NotesAndres Mendez-Vazquez
 
Prelim Project OOP
Prelim Project OOPPrelim Project OOP
Prelim Project OOPDwight Sabio
 
IRJET- A Survey on Different Searching Algorithms
IRJET- A Survey on Different Searching AlgorithmsIRJET- A Survey on Different Searching Algorithms
IRJET- A Survey on Different Searching AlgorithmsIRJET Journal
 
Data Analysis – Technical learnings
Data Analysis – Technical learningsData Analysis – Technical learnings
Data Analysis – Technical learningsInvenkLearn
 
Lecture#1(Algorithmic Notations).ppt
Lecture#1(Algorithmic Notations).pptLecture#1(Algorithmic Notations).ppt
Lecture#1(Algorithmic Notations).pptMuhammadTalhaAwan1
 
The International Journal of Engineering and Science (The IJES)
The International Journal of Engineering and Science (The IJES)The International Journal of Engineering and Science (The IJES)
The International Journal of Engineering and Science (The IJES)theijes
 
Basics in algorithms and data structure
Basics in algorithms and data structure Basics in algorithms and data structure
Basics in algorithms and data structure Eman magdy
 
User_42751212015Module1and2pagestocompetework.pdf.docx
User_42751212015Module1and2pagestocompetework.pdf.docxUser_42751212015Module1and2pagestocompetework.pdf.docx
User_42751212015Module1and2pagestocompetework.pdf.docxdickonsondorris
 
Matrix algebra in_r
Matrix algebra in_rMatrix algebra in_r
Matrix algebra in_rRazzaqe
 
29 19 sep17 17may 6637 10140-1-ed(edit)
29 19 sep17 17may 6637 10140-1-ed(edit)29 19 sep17 17may 6637 10140-1-ed(edit)
29 19 sep17 17may 6637 10140-1-ed(edit)IAESIJEECS
 
29 19 sep17 17may 6637 10140-1-ed(edit)
29 19 sep17 17may 6637 10140-1-ed(edit)29 19 sep17 17may 6637 10140-1-ed(edit)
29 19 sep17 17may 6637 10140-1-ed(edit)IAESIJEECS
 

Similar to Data Structures & Algorithms Coursework Assignment for Sem.docx (20)

Ch24 efficient algorithms
Ch24 efficient algorithmsCh24 efficient algorithms
Ch24 efficient algorithms
 
Chapter 16-spreadsheet1 questions and answer
Chapter 16-spreadsheet1  questions and answerChapter 16-spreadsheet1  questions and answer
Chapter 16-spreadsheet1 questions and answer
 
Lect11
Lect11Lect11
Lect11
 
VCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxVCE Unit 01 (2).pptx
VCE Unit 01 (2).pptx
 
ADSA orientation.pptx
ADSA orientation.pptxADSA orientation.pptx
ADSA orientation.pptx
 
Sortsearch
SortsearchSortsearch
Sortsearch
 
01 Notes Introduction Analysis of Algorithms Notes
01 Notes Introduction Analysis of Algorithms Notes01 Notes Introduction Analysis of Algorithms Notes
01 Notes Introduction Analysis of Algorithms Notes
 
Ds
DsDs
Ds
 
Prelim Project OOP
Prelim Project OOPPrelim Project OOP
Prelim Project OOP
 
IRJET- A Survey on Different Searching Algorithms
IRJET- A Survey on Different Searching AlgorithmsIRJET- A Survey on Different Searching Algorithms
IRJET- A Survey on Different Searching Algorithms
 
Data Analysis – Technical learnings
Data Analysis – Technical learningsData Analysis – Technical learnings
Data Analysis – Technical learnings
 
Lecture#1(Algorithmic Notations).ppt
Lecture#1(Algorithmic Notations).pptLecture#1(Algorithmic Notations).ppt
Lecture#1(Algorithmic Notations).ppt
 
The International Journal of Engineering and Science (The IJES)
The International Journal of Engineering and Science (The IJES)The International Journal of Engineering and Science (The IJES)
The International Journal of Engineering and Science (The IJES)
 
Basics in algorithms and data structure
Basics in algorithms and data structure Basics in algorithms and data structure
Basics in algorithms and data structure
 
User_42751212015Module1and2pagestocompetework.pdf.docx
User_42751212015Module1and2pagestocompetework.pdf.docxUser_42751212015Module1and2pagestocompetework.pdf.docx
User_42751212015Module1and2pagestocompetework.pdf.docx
 
Blinkdb
BlinkdbBlinkdb
Blinkdb
 
chapter 1
chapter 1chapter 1
chapter 1
 
Matrix algebra in_r
Matrix algebra in_rMatrix algebra in_r
Matrix algebra in_r
 
29 19 sep17 17may 6637 10140-1-ed(edit)
29 19 sep17 17may 6637 10140-1-ed(edit)29 19 sep17 17may 6637 10140-1-ed(edit)
29 19 sep17 17may 6637 10140-1-ed(edit)
 
29 19 sep17 17may 6637 10140-1-ed(edit)
29 19 sep17 17may 6637 10140-1-ed(edit)29 19 sep17 17may 6637 10140-1-ed(edit)
29 19 sep17 17may 6637 10140-1-ed(edit)
 

More from simonithomas47935

Hours, A. (2014). Reading Fairy Tales and Playing A Way of Treati.docx
Hours, A. (2014). Reading Fairy Tales and Playing A Way of Treati.docxHours, A. (2014). Reading Fairy Tales and Playing A Way of Treati.docx
Hours, A. (2014). Reading Fairy Tales and Playing A Way of Treati.docxsimonithomas47935
 
How are authentication and authorization alike and how are the.docx
How are authentication and authorization alike and how are the.docxHow are authentication and authorization alike and how are the.docx
How are authentication and authorization alike and how are the.docxsimonithomas47935
 
How are self-esteem and self-concept different What is the or.docx
How are self-esteem and self-concept different What is the or.docxHow are self-esteem and self-concept different What is the or.docx
How are self-esteem and self-concept different What is the or.docxsimonithomas47935
 
How are morality and religion similar and how are they different.docx
How are morality and religion similar and how are they different.docxHow are morality and religion similar and how are they different.docx
How are morality and religion similar and how are they different.docxsimonithomas47935
 
How are financial statements used to evaluate business activities.docx
How are financial statements used to evaluate business activities.docxHow are financial statements used to evaluate business activities.docx
How are financial statements used to evaluate business activities.docxsimonithomas47935
 
How are Japanese and Chinese Americans similar How are they differe.docx
How are Japanese and Chinese Americans similar How are they differe.docxHow are Japanese and Chinese Americans similar How are they differe.docx
How are Japanese and Chinese Americans similar How are they differe.docxsimonithomas47935
 
Hot Spot PolicingPlace can be an important aspect of crime and.docx
Hot Spot PolicingPlace can be an important aspect of crime and.docxHot Spot PolicingPlace can be an important aspect of crime and.docx
Hot Spot PolicingPlace can be an important aspect of crime and.docxsimonithomas47935
 
HOSP3075 Brand Analysis Paper 1This is the first of three assignme.docx
HOSP3075 Brand Analysis Paper 1This is the first of three assignme.docxHOSP3075 Brand Analysis Paper 1This is the first of three assignme.docx
HOSP3075 Brand Analysis Paper 1This is the first of three assignme.docxsimonithomas47935
 
Hou, J., Li, Y., Yu, J. & Shi, W. (2020). A Survey on Digital Fo.docx
Hou, J., Li, Y., Yu, J. & Shi, W. (2020). A Survey on Digital Fo.docxHou, J., Li, Y., Yu, J. & Shi, W. (2020). A Survey on Digital Fo.docx
Hou, J., Li, Y., Yu, J. & Shi, W. (2020). A Survey on Digital Fo.docxsimonithomas47935
 
How (Not) to be Secular by James K.A. SmithSecular (1)—the ea.docx
How (Not) to be Secular by James K.A. SmithSecular (1)—the ea.docxHow (Not) to be Secular by James K.A. SmithSecular (1)—the ea.docx
How (Not) to be Secular by James K.A. SmithSecular (1)—the ea.docxsimonithomas47935
 
Hopefully, you enjoyed this class on Digital Media and Society.Q.docx
Hopefully, you enjoyed this class on Digital Media and Society.Q.docxHopefully, you enjoyed this class on Digital Media and Society.Q.docx
Hopefully, you enjoyed this class on Digital Media and Society.Q.docxsimonithomas47935
 
hoose (1) one childhood experience from the list provided below..docx
hoose (1) one childhood experience from the list provided below..docxhoose (1) one childhood experience from the list provided below..docx
hoose (1) one childhood experience from the list provided below..docxsimonithomas47935
 
honesty, hard work, caring, excellence HIS 1110 Dr. .docx
honesty, hard work, caring, excellence  HIS 1110      Dr. .docxhonesty, hard work, caring, excellence  HIS 1110      Dr. .docx
honesty, hard work, caring, excellence HIS 1110 Dr. .docxsimonithomas47935
 
hoose one of the four following visualsImage courtesy o.docx
hoose one of the four following visualsImage courtesy o.docxhoose one of the four following visualsImage courtesy o.docx
hoose one of the four following visualsImage courtesy o.docxsimonithomas47935
 
HomeworkChoose a site used by the public such as a supermark.docx
HomeworkChoose a site used by the public such as a supermark.docxHomeworkChoose a site used by the public such as a supermark.docx
HomeworkChoose a site used by the public such as a supermark.docxsimonithomas47935
 
Homework 2 Please answer the following questions in small paragraph.docx
Homework 2 Please answer the following questions in small paragraph.docxHomework 2 Please answer the following questions in small paragraph.docx
Homework 2 Please answer the following questions in small paragraph.docxsimonithomas47935
 
HomeNotificationsMy CommunityBBA 2010-16J-5A21-S1, Introductio.docx
HomeNotificationsMy CommunityBBA 2010-16J-5A21-S1, Introductio.docxHomeNotificationsMy CommunityBBA 2010-16J-5A21-S1, Introductio.docx
HomeNotificationsMy CommunityBBA 2010-16J-5A21-S1, Introductio.docxsimonithomas47935
 
HomeAnnouncementsSyllabusDiscussionsQuizzesGra.docx
HomeAnnouncementsSyllabusDiscussionsQuizzesGra.docxHomeAnnouncementsSyllabusDiscussionsQuizzesGra.docx
HomeAnnouncementsSyllabusDiscussionsQuizzesGra.docxsimonithomas47935
 
Homeless The Motel Kids of Orange CountyWrite a 1-2 page pa.docx
Homeless The Motel Kids of Orange CountyWrite a 1-2 page pa.docxHomeless The Motel Kids of Orange CountyWrite a 1-2 page pa.docx
Homeless The Motel Kids of Orange CountyWrite a 1-2 page pa.docxsimonithomas47935
 
Home work 8 Date 042220201. what are the different between.docx
Home work  8 Date 042220201. what are the  different between.docxHome work  8 Date 042220201. what are the  different between.docx
Home work 8 Date 042220201. what are the different between.docxsimonithomas47935
 

More from simonithomas47935 (20)

Hours, A. (2014). Reading Fairy Tales and Playing A Way of Treati.docx
Hours, A. (2014). Reading Fairy Tales and Playing A Way of Treati.docxHours, A. (2014). Reading Fairy Tales and Playing A Way of Treati.docx
Hours, A. (2014). Reading Fairy Tales and Playing A Way of Treati.docx
 
How are authentication and authorization alike and how are the.docx
How are authentication and authorization alike and how are the.docxHow are authentication and authorization alike and how are the.docx
How are authentication and authorization alike and how are the.docx
 
How are self-esteem and self-concept different What is the or.docx
How are self-esteem and self-concept different What is the or.docxHow are self-esteem and self-concept different What is the or.docx
How are self-esteem and self-concept different What is the or.docx
 
How are morality and religion similar and how are they different.docx
How are morality and religion similar and how are they different.docxHow are morality and religion similar and how are they different.docx
How are morality and religion similar and how are they different.docx
 
How are financial statements used to evaluate business activities.docx
How are financial statements used to evaluate business activities.docxHow are financial statements used to evaluate business activities.docx
How are financial statements used to evaluate business activities.docx
 
How are Japanese and Chinese Americans similar How are they differe.docx
How are Japanese and Chinese Americans similar How are they differe.docxHow are Japanese and Chinese Americans similar How are they differe.docx
How are Japanese and Chinese Americans similar How are they differe.docx
 
Hot Spot PolicingPlace can be an important aspect of crime and.docx
Hot Spot PolicingPlace can be an important aspect of crime and.docxHot Spot PolicingPlace can be an important aspect of crime and.docx
Hot Spot PolicingPlace can be an important aspect of crime and.docx
 
HOSP3075 Brand Analysis Paper 1This is the first of three assignme.docx
HOSP3075 Brand Analysis Paper 1This is the first of three assignme.docxHOSP3075 Brand Analysis Paper 1This is the first of three assignme.docx
HOSP3075 Brand Analysis Paper 1This is the first of three assignme.docx
 
Hou, J., Li, Y., Yu, J. & Shi, W. (2020). A Survey on Digital Fo.docx
Hou, J., Li, Y., Yu, J. & Shi, W. (2020). A Survey on Digital Fo.docxHou, J., Li, Y., Yu, J. & Shi, W. (2020). A Survey on Digital Fo.docx
Hou, J., Li, Y., Yu, J. & Shi, W. (2020). A Survey on Digital Fo.docx
 
How (Not) to be Secular by James K.A. SmithSecular (1)—the ea.docx
How (Not) to be Secular by James K.A. SmithSecular (1)—the ea.docxHow (Not) to be Secular by James K.A. SmithSecular (1)—the ea.docx
How (Not) to be Secular by James K.A. SmithSecular (1)—the ea.docx
 
Hopefully, you enjoyed this class on Digital Media and Society.Q.docx
Hopefully, you enjoyed this class on Digital Media and Society.Q.docxHopefully, you enjoyed this class on Digital Media and Society.Q.docx
Hopefully, you enjoyed this class on Digital Media and Society.Q.docx
 
hoose (1) one childhood experience from the list provided below..docx
hoose (1) one childhood experience from the list provided below..docxhoose (1) one childhood experience from the list provided below..docx
hoose (1) one childhood experience from the list provided below..docx
 
honesty, hard work, caring, excellence HIS 1110 Dr. .docx
honesty, hard work, caring, excellence  HIS 1110      Dr. .docxhonesty, hard work, caring, excellence  HIS 1110      Dr. .docx
honesty, hard work, caring, excellence HIS 1110 Dr. .docx
 
hoose one of the four following visualsImage courtesy o.docx
hoose one of the four following visualsImage courtesy o.docxhoose one of the four following visualsImage courtesy o.docx
hoose one of the four following visualsImage courtesy o.docx
 
HomeworkChoose a site used by the public such as a supermark.docx
HomeworkChoose a site used by the public such as a supermark.docxHomeworkChoose a site used by the public such as a supermark.docx
HomeworkChoose a site used by the public such as a supermark.docx
 
Homework 2 Please answer the following questions in small paragraph.docx
Homework 2 Please answer the following questions in small paragraph.docxHomework 2 Please answer the following questions in small paragraph.docx
Homework 2 Please answer the following questions in small paragraph.docx
 
HomeNotificationsMy CommunityBBA 2010-16J-5A21-S1, Introductio.docx
HomeNotificationsMy CommunityBBA 2010-16J-5A21-S1, Introductio.docxHomeNotificationsMy CommunityBBA 2010-16J-5A21-S1, Introductio.docx
HomeNotificationsMy CommunityBBA 2010-16J-5A21-S1, Introductio.docx
 
HomeAnnouncementsSyllabusDiscussionsQuizzesGra.docx
HomeAnnouncementsSyllabusDiscussionsQuizzesGra.docxHomeAnnouncementsSyllabusDiscussionsQuizzesGra.docx
HomeAnnouncementsSyllabusDiscussionsQuizzesGra.docx
 
Homeless The Motel Kids of Orange CountyWrite a 1-2 page pa.docx
Homeless The Motel Kids of Orange CountyWrite a 1-2 page pa.docxHomeless The Motel Kids of Orange CountyWrite a 1-2 page pa.docx
Homeless The Motel Kids of Orange CountyWrite a 1-2 page pa.docx
 
Home work 8 Date 042220201. what are the different between.docx
Home work  8 Date 042220201. what are the  different between.docxHome work  8 Date 042220201. what are the  different between.docx
Home work 8 Date 042220201. what are the different between.docx
 

Recently uploaded

Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 

Recently uploaded (20)

Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 

Data Structures & Algorithms Coursework Assignment for Sem.docx

  • 1. Data Structures & Algorithms Coursework Assignment for Semester 2, 2016-17 Due Date: Friday 12th May 2017 An examination of the number of comparisons needed for successful searches of sorted arrays using ten different search algorithms SID Number: XXXXXXX Instructions 1. In this assignment, you will analyse some array search algorithms using MATLAB. The first search algorithm (linear search) is analysed for you as an example. There are 10 marks available for each of the remaining search algorithms to be
  • 2. analysed. Test your algorithms before analysing them to ensure that they operate correctly (e.g., using small arrays passed to your functions from the Command Window). 2. Complete the report in exactly the format given here (i.e., fill in the sections and do not change the structure of the document). 10 marks will be awarded for keeping the document in the correct format as you complete the report. In particular, note that code should be pasted directly from MATLAB, in order that a fixed-width font is used, and to ensure that indentation is maintained. 3. Your printed report must be submitted with a CD or USB drive containing your source code (functions for each search algorithm and test harnesses). Work must be submitted to the iCentre by the published deadline. This assignment is worth 50% of your grade for the module. 4. Some initial references are provided, but further research will be needed to learn about the search algorithms that have not been discussed in class. Additional references should be added to the Harvard style reference list to acknowledge the sources consulted. Use reliable sources wherever possible. 5. In the mark scheme (shown below) insert 0s for any algorithms or subsections not completed to determine the maximum possible mark that you can score and to indicate which parts were attempted. Mark Scheme Algorithm Subsection 1 Subsection 2 Subsection 3 Subsection 4 Subsection 5
  • 3. Marks 1. Linear N/A N/A N/A N/A N/A N/A 2. Random 0..2 0..2 0..2 0..2 0..2 0..10 3. Jump 0..2 0..2 0..2 0..2 0..2 0..10 4. K-level Jump 0..2 0..2 0..2 0..2 0..2 0..10 5. Exponential 0..2 0..2 0..2 0..2 0..2 0..10
  • 4. 6. Fibonaccian 0..2 0..2 0..2 0..2 0..2 0..10 7. Binary 0..2 0..2 0..2 0..2 0..2 0..10 8. Ternary 0..2 0..2 0..2 0..2 0..2 0..10 9. Interpolation-Sequential 0..2 0..2 0..2 0..2 0..2 0..10 10. Interpolation 0..2 0..2 0..2 0..2 0..2 0..10 Presentation
  • 5. 0..10 Total Marks 0..100 Table of Contents 1. Linear Search (Sequential Search) 1.1 Basic logic used by the algorithm 1.2 Published and/or theoretically deduced time complexity 1.3 Presentation of algorithm as a function in MATLAB 1.4 Presentation of successful search test results graphs for increasing array sizes 1.5 Discussion of results 2. Random Search 2.1 Basic logic used by the algorithm 2.2 Published and/or theoretically deduced time complexity 2.3 Presentation of algorithm as a function in MATLAB 2.4 Presentation of successful search test results graphs for increasing array sizes 2.5 Discussion of results 3. Jump Search (Block Search) 3.1 Basic logic used by the algorithm 3.2 Published and/or theoretically deduced time complexity 3.3 Presentation of algorithm as a function in MATLAB 3.4 Presentation of successful search test results graphs for increasing array sizes 3.5 Discussion of results 4. K-level Jump Search 4.1 Basic logic used by the algorithm 4.2 Published and/or theoretically deduced time complexity 4.3 Presentation of algorithm as a function in MATLAB 4.4 Presentation of successful search test results graphs for increasing array sizes 4.5 Discussion of results
  • 6. 5. Exponential Search (Doubling Search, Galloping Search) 5.1 Basic logic used by the algorithm 5.2 Published and/or theoretically deduced time complexity 5.3 Presentation of algorithm as a function in MATLAB 5.4 Presentation of successful search test results graphs for increasing array sizes 5.5 Discussion of results 6. Fibonaccian Search 6.1 Basic logic used by the algorithm 6.2 Published and/or theoretically deduced time complexity 6.3 Presentation of algorithm as a function in MATLAB 6.4 Presentation of successful search test results graphs for increasing array sizes 6.5 Discussion of results 7. Binary Search (Half-interval Search, Logarithmic Search) 7.1 Basic logic used by the algorithm 7.2 Published and/or theoretically deduced time complexity 7.3 Presentation of algorithm as a function in MATLAB 7.4 Presentation of successful search test results graphs for increasing array sizes 7.5 Discussion of results 8. Ternary Search 8.1 Basic logic used by the algorithm 8.2 Published and/or theoretically deduced time complexity 8.3 Presentation of algorithm as a function in MATLAB 8.4 Presentation of successful search test results graphs for increasing array sizes 8.5 Discussion of results 9. Interpolation-Sequential Search 9.1 Basic logic used by the algorithm 9.2 Published and/or theoretically deduced time complexity
  • 7. 9.3 Presentation of algorithm as a function in MATLAB 9.4 Presentation of successful search test results graphs for increasing array sizes 9.5 Discussion of results 10. Interpolation Search (Predictive Search) 10.1 Basic logic used by the algorithm 10.2 Published and/or theoretically deduced time complexity 10.3 Presentation of algorithm as a function in MATLAB 10.4 Presentation of successful search test results graphs for increasing array sizes 10.5 Discussion of results Appendix A: Test Harness for Deterministic Search Algorithms Appendix B: Test Harness for Non-deterministic Search Algorithms List of Figures Figure 1: Min, average, and max comparisons for linear search for array sizes [0..1024]. Figure 2: Min, average, and max comparisons for random search for array sizes [0..1024]. Figure 3: Min, average, and max comparisons for jump search for array sizes [0..1024]. Figure 4: Min, average, and max comparisons for k-level jump search for array sizes [0..1024]. Figure 5: Min, average, and max comparisons for exponential search for array sizes [0..1024]. Figure 6: Min, average, and max comparisons for Fibonaccian search for array sizes [0..1024]. Figure 7: Min, average, and max comparisons for binary search for array sizes [0..1024]. Figure 8: Min, average, and max comparisons for ternary search for array sizes [0..1024]. Figure 9: Min, average, and max comparisons for interpolation- sequential search for array sizes [0..1024].
  • 8. Figure 10: Min, average, and max comparisons for interpolation search for array sizes [0..1024]. List of Tables Table 1: Time complexity summary for linear search. Table 2: Time complexity summary for random search. Table 3: Time complexity summary for jump search. Table 4: Time complexity summary for k-level jump search. Table 5: Time complexity summary for exponential search. Table 6: Time complexity summary for Fibonaccian search. Table 7: Time complexity summary for binary search. Table 8: Time complexity summary for ternary search. Table 9: Time complexity summary for interpolation-sequential search. Table 10: Time complexity summary for interpolation search. List of Files on Attached Media linearSearch.m linearSearchTestHarness.m randomSearch.m randomSearchTestHarness.m jumpSearch.m jumpSearchTestHarness.m kLevelJumpSearch.m kLevelJumpSearchTestHarness.m exponentialSearch.m exponentialSearchTestHarness.m fibonaccianSearch.m fibonaccianSearchTestHarness.m binarySearch.m binarySearchTestHarness.m ternarySearch.m ternarySearchTestHarness.m interpolationSequentialSearch.m interpolationSequentialSearchTestHarness.m interpolationSearch.m interpolationSearchTestHarness.m 1. Linear Search (Sequential Search)
  • 9. 1.1 Basic logic used by the algorithm The linear search algorithm compares a search target to the value in each element [1..N] of an array sequentially, starting from the first element (here, element 1). The search terminates if one of two things happens: 1. the search target is found; 2. the end of the array is reached. In the event that the target is found, the array index in which it was found is returned. In the event that the end of the array is reached and the search target has not been found, a fail token is returned (here, -1). 1.2 Published and/or theoretically deduced time complexity For successful searches, the best case occurs when the target is found in the first index examined (i.e., index 1, requiring one comparison). The worst case occurs when the search target is found in the final element (at index N, requiring N comparisons). The average case is that the search target is found in the centre of the array, at index 0.5N, taking 0.5N comparisons. These time complexities are summarised in Table 1. Best Case Average Case Worst Case Linear Search (Successful) O(1) O(n) O(n) Table 1: Time complexity summary for linear search. 1.3 Presentation of algorithm as a function in MATLAB
  • 10. function [numComparisons, currentIndex] = linearSearch(V, target) numComparisons = 0; for currentIndex=1:length(V) numComparisons = numComparisons + 1; if(V(currentIndex) == target) break; end end if(V(currentIndex)~=target) currentIndex = -1; end end The MATLAB source code for this algorithm is provided on the attached disk, filename linearSearch.m 1.4 Presentation of successful search test results graphs for increasing array sizes Results for a successful linear search of array sizes 1..1024 are shown in Fig. 1. Figure 1: Min (green), average (yellow), and max (red) comparisons for linear search of an array of size [0..1024]. Dotted lines show expected (theoretically deduced) min, average and max. 1.5 Discussion of results The observed test results (coloured lines) are in good agreement with the published (expected) time complexities for a linear search (dotted lines). The best case (minimum number of
  • 11. comparisons required) was always one (green line), irrespective of array length. The worst case (maximum number of comparisons required) was always equal to the array length (red line), occurring when the search target was found in the final element. The average case was 0.5N, representing the average of all possible outcomes (yellow line), which is that the search target is found in the centre of the array. The average and worst cases therefore grew linearly as the size of the array increased as functions y = x/2 and y = x, respectively (i.e., as arithmetic progressions). If the array size were doubled, the best case would remain constant (at 1), and the average and worst cases would also double. References Shneiderman, B. (1978). Jump Searching: A Fast Sequential Search Technique, Communications of the ACM, 21(10), 831- 834. [Jump Search]. Bentley, J. L. and Yao, A. C. (1976). An almost optimal algorithm for unbounded searching. Information Processing Letters, 5(3), 82–87. [Exponential Search]. Ferguson, D. E. (1960). Fibonaccian searching. Communications of the ACM, 3(12), 648. [Fibonaccian Search]. Perl, Y., Itai, A., & Avni, H. (1978). Interpolation search — a log log N search. Communications of the ACM, 21(7), 550-553. [Interpolation Search]. Appendix A: Test Harness for Deterministic Search Algorithms Array sizes from 1..maxArraySize are tested, where maxArraySize = 1024. The current array size being tested is held in variable N. The sequence [1..N] is placed in the current array. Values [1..N] are used as search targets, one at a time. Best (minimum), average (arithmetic mean) and worst (maximum) number of comparisons performed for each array size are collected. A graph of N against comparisons is
  • 12. displayed, with three lines (minimum, average and maximum). Expected performance is also plotted (dotted lines). clear all;close all;clc; maxArraySize = 1024; for N = 1:maxArraySize array = 1:N; for searchTarget = 1:N comparisons(searchTarget) = linearSearch(array, searchTarget); end min_comps(N) = min(comparisons); avg_comps(N) = mean(comparisons); max_comps(N) = max(comparisons); clear comparisons; end figure; % Plot Observed plot([1:maxArraySize], min_comps,'g','LineWidth',3);hold on; plot([1:maxArraySize], avg_comps,'y','LineWidth',3); plot([1:maxArraySize], max_comps,'r','LineWidth',3); legend('min','mean','max'); % Plot Expected
  • 13. plot([1:maxArraySize], linspace(1,1,maxArraySize), 'k:'); plot([1:maxArraySize], linspace(1,N/2,maxArraySize), 'k:'); plot([1:maxArraySize], linspace(1,N,maxArraySize), 'k:'); % Annotate Chart xlabel('Array Size (N)','FontSize',14); ylabel('Comparisons', 'FontSize', 14); title('Linear Search (Successful)','FontSize', 14); xlim([0 maxArraySize]); ylim([0 max(max_comps)]); modify as required print -f1 -r300 -dbmp linearSearchSuccessful.bmp 2