Page 91 - CTS - CSA TP - Volume 2
P. 91
COMPUTER SOFTWARE APPLICATION - CITS
Explanation:
• This program sorts n elements in descending order using the bubble sort algorithm.
• It first prompts the user to enter the number of elements and reads the input.
• Then, it creates an array of the specified size.
• The user is prompted to enter each element of the array.
• The program then performs the bubble sort algorithm to sort the array in descending order.
• In the bubble sort algorithm, we iterate through the array multiple times, comparing adjacent elements
and swapping them if they are in the wrong order.
• After sorting, it displays the sorted array elements in descending order.
• Finally, it closes the Scanner object to release system resources.
Bubble sort is easy to understand and implement. It repeatedly steps through the list, compares adjacent
elements, and swaps them if they are in the wrong order. This process continues until the list is sorted.
TASK 5 : Binary Search
Binary search is one of the searching techniques applied when the input is sorted here we are focusing on
finding the middle element that acts as a reference frame whether to go left or right to it as the elements are
already sorted. This searching helps in optimizing the search technique with every iteration is referred to as
binary search and readers do stress over it as it is indirectly applied in solving questions.
Binary Search Algorithm in Java
Below is the Algorithm designed for Binary Search:
1 Start
2 Take input array and Target
3 Sort the array if it is not in sorted order .
4 Initialise start = 0 and end = (array size -1)
5 Initialise mid variable
76
CITS : IT & ITES - Computer Software Application - Exercise 93