Professional Documents
Culture Documents
Implementation of Sequential Search
Implementation of Sequential Search
AIM
To develop a Java application to implement sequential search.
ALGORITHM
Step 1: First, read the array of n elements and the search element (Target element) in the
array.
Step 2: In the second step compare the search element with the first element in the array.
Step 3: If both are matched, return the index value of an element and display the message
“Target element is found".
Step 4: If both are not matched, compare the search element with the next element in the
array.
Step 5: In this step, repeat steps 3 and 4 until the search (Target) element is compared with
the last element of the array.
Step 6 - If the last element in the list does not match, the Linear Search Function will return
-1 and the message "Element is not found" will be displayed.
Program
Thus the java application to implement sequential search was executed and verified
successfully.
ALGORITHM
Step 1: First, read the array of n elements and the search element (Target element) in the
array.
Step 4: If key = middle element, then we return the mid index position for the key found.
Step 5: Else If key > mid element, then the key lies in the right half of the collection. Thus repeat
steps 1 to 3 on the lower (right) half of the collection.
Step 6: Else key < mid element, then the key is in the upper half of the collection. Hence you
need to repeat the binary search in the upper half.
Step 7: Repeat steps 2 to 6 until the value is found or not found in entire array.
Program
RESULT
Thus the java application to implement binary search was executed and verified
successfully.
EX NO 1 c) Implementation of Selection sort
AIM
To develop a Java application to implement selection sort.
ALGORITHM
Step 1. First, read the array of n elements
Step 2. Set MIN to location 0
Step 3. Search the minimum element in the list
Step 4. Swap with value at location MIN
Step 5. Increment MIN to point to next element
Step 6. Repeat until the array is sorted
Program
RESULT
Thus the java application to implement selection sort was executed and verified
successfully.
AIM
To develop a Java application to implement insertion sort.
ALGORITHM
Step 1. First, read the array of n elements
Step 2. If the element is the first element, assume that it is already sorted. Return 1.
Step 3. Pick the next element, and store it separately in a key.
Step 4. Now, compare the key with all elements in the sorted array
Step 5. If the element in the sorted array is smaller than the current element, then move to
the next element. Else, shift greater elements in the array towards the right.
Step 6. Insert the value
Step 7 - Repeat until the array is sorted
Program
RESULT
Thus the java application to implement insertion sort was executed and verified
successfully