SYBCS DS Assignment 3

Set A 

a) Create a random array of n integers. Accept a value x from user and use linear search algorithm to check whether the number is present in the array or not and output the position if the number is present.

b) Create a random array of n integers. Sort the array using bubble sort. Accept a value x from user and use binary search algorithm to check whether the number is present in array or not and output the position if the number is present.  

Set B 

a) Read the data from file 'cities.txt' containing names of 100 cities and their STD codes. Accept a name of the city from user and use linear search algorithm to check whether the name is present in the file and output the STD code, otherwise output “city not in the list”. 

b) Read the data from file ‘sortedcities.txt’ containing names of 100 cities and their STD codes. Accept a name of the city from user and use binary search algorithm to check whether the name is present in the file and output the STD code, otherwise output “city not in the list”.

Post a Comment

1 Comments

  1. What modifications are required to linear search and binary search algorithm to count the number of comparisons

    ReplyDelete