Page 58 - DCAP407_DATA_STRUCTURE
P. 58
Unit 3: Arrays
4. The values in the array are printed using a for loop.
5. Next, the Bubble function is called. The sorting operation is carried out and
values present in the array are printed.
6. getch() prompts the user to press a key. Then the program terminates.
7. In The BUBBLE function the variables K, PTR and TEMP are declared as
integers.
8. PTR is set to 0.
9. Within the while loop the adjacent array elements are compared. If the
element at a lower position is greater than the element at the next position,
both the elements are interchanged.
10. The array index is then incremented.
Did you know? There is no algorithm that can sort n items in time of order less than O(n log n).
Consider the array NUM[10] = {11,55,71,37,55,29,8,13, 32,6}
Write an algorithm to sort the array in descending order.
3.3.3 Searching Operation
Searching is an operation used for finding an item with specified properties among a collection of items.
In a database, the items are stored individually as records, or as elements of a search space addressed by
a mathematical formula or procedure. The mathematical formula or procedure may be the root of an
equation containing integer variables.
Search operation is closely related to the concept of dictionaries. Dictionaries are a type of data structure
that support operations such as, search, insert, and delete.
Computer systems are used to store large amounts of data. From these large amount of data, individual
records are retrieved based on some search criterion. The efficient storage of data is an important issue
to facilitate fast searching.
There are many different searching techniques or algorithms. The selection of algorithm depends on the
way the information is organized in memory. Now, we will discuss linear searching technique.
Suppose A is a linear array with n elements. If no information on A is
specified, then the most spontaneous way to search for a given ITEM in
A is to compare ITEM with each element of A, one by one. First, we test
whether A[1] = ITEM, and then we test whether A[2] = ITEM, and so
on. This method of sequentially traversing array A is called linear
search.
LOVELY PROFESSIONAL UNIVERSITY 51