11/08/2017

BCS1223 Data Structure And Algorithms : Assignment 2

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.

No comments:

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.  ...