Write a program to find the number of comparisons using the binary search and sequential search algorithms as follows:
Suppose list is an array of 1000 elements.
a. Use a random number generator to fill list. (You may refer to http://www.cplusplus.com/reference/cstdlib/rand/)
b. Use any sorting algorithm to sort list. (You may refer to http://www.geeksforgeeks.org/sort-c-stl/)
c. Search the list for some items, as follows:
i. Use the sequential search algorithm to search the list. (You might need to modify the seqSearch function given in http://mohdnazri.blogspot.my/2017/11/bcs1223-data-structure-and-algorithms.html to count the number of
comparisons.)
ii. Use the binary search algorithm to search the list. (You might need
to modify the binSearch function given in http://mohdnazri.blogspot.my/2017/11/bcs1223-data-structure-and-algorithms.html to count the number of
comparisons.)
iii. Use the binary search algorithm to search the list, switching to a sequential search when the size of the search list reduces to less than 15.(Use the sequential search algorithm for a sorted list.)
d. Print the number of comparisons for Steps c.i c.ii and c.iii. If the item is found in the list, then print its position.
due date: 23 November 2017
Students may refer to the following C++ program to get the idea.
Subscribe to:
Post Comments (Atom)
Cara download Installer windows 10 dalam format ISO
1. Jika anda bercadang untuk download windows 10 melalui website rasmi windows - pilihan untuk download dalam format ISO tidak di berikan. ...
-
ANSWERS TO CHAPTER EXERCISES (CHAPTER 8) Review Questions 1. List and describe various types of output, including technolog...
-
Based on real life scenario on any local company/ organization which you are very familiar, define the problem that could be addressed thr...
-
A. Response to the following statements by circling either T (TRUE) or F (FALSE). [10M] I. 1. Java enables users...
No comments:
Post a Comment