CSE 1321L: Programming and Problem Solving I Lab Lab 14 Search and Sort Algorithms

$30.00

Category: Tags: , , , , , , , You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (4 votes)

Exercise #1: Design and implement a program (name it LinearBinarySearch) to implement and test the linear and binary search algorithm discussed in the lecture slides.

 

Define method LinearSearch() to implement linear search of an array of integers. Modify the algorithm implementation to count number of comparisons it takes to find a target value (if exist) in the array.

 

Define method BinarySearch() to implement binary search of an array of integers. Modify the algorithm implementation to count number of comparisons it takes to find a target value (if exist) in the array.

 

Now, develop a test method to read integer values from the user in to an array and then call methods LinearSearch() and BinarySearch() and printout the number of comparison took to find the target values using each search method. Document your code and organized your outputs as follows:

 

Arrays Values:

Target value:

 

Linear Search Comparisons:

Binary Search Comparisons:

 

 

Exercise #2: Design and implement a program (name it SimpleSort) to implement and test the three sort algorithms (Bubble, Insertion, Selection) discussed in the lecture slides.

 

Define method BubbleSort() to implement Bubble sort of an array of integers. Modify the algorithm implementation to count number of swaps it takes to sort the array.

 

Define method InsertionSort() to implement insertion sort of an array of integers. Modify the algorithm implementation to count number of swaps it takes to sort the array.

 

Define method SelectionSort() to implement selection sort of an array of integers. Modify the algorithm implementation to count number of swaps it takes to sort the array.

 

Now, develop a test method that generates 50 integer values between 0 and 100, store them in an array, and then pass the array to those three sort methods. Document your code and organized your outputs as follows:

 

Arrays Values:

 

Bubble Sorted values:

Bubble Sort Swaps:

 

Insertion Sorted values:

Insertion Sort Swaps:

 

Selection Sorted values:

Selection Sort Swaps:

 

 

Instructions:

 

  1. Programs must be working correctly.
  2. Programs must be completed and checked before working the assignment.
  3. Programs must be checked by the end of the designated lab session.