Langsung ke konten utama

Sorting & Searching

Sorting & Searching



SUB TOPICS :
  • Bubble Sort
  • Selection Sort
  • Insertion Sort
  • Quick Sort
  • Merge Sort
  • Linear Search
  • Binary Search
  • Interpolation Search
Sorting

       Sorting needs to speed up searching operation in a list.
       Sorting type:
      Ascending
      Descending
Sorting algorithm:
1. Internal sorting
    All data to be sorted are loaded to RAM
2. External sorting
    Sorting process using secondary storage

       Simple:
                      Bubble sort
                      Selection sort
                      Insertion sort
       Intermediate:
                      Quick Sort
                      Merge Sort

Bubble Sort

       Compare two neighboring values.
       Compare and swap (if necessary)
       Also known as exchange sort
       Source Code of Bubble Sort:

void Bubble(int *DataArr, int n)
{
                                int i, j;
                                for(i=1; i<n; i++)
                                                for(j=n-1; j>=i; j--)
                                                                if(DataArr[j-1] > DataArr[j])
                                Swap(&DataArr[j-1],&DataArr[j]);
}
Selection Sort

Algorithm:
for(i=0; i<N-1; i++){      /* N=number of data */
                Set idx_smallest equal to i
                for(j=i+1; j<N; j++){
                                                If array[ j ] < array [ idx_smallest ] then idx_smallest = j
    }
                Swap array[ i ] with array[ idx_smallest ]
}

Insertion Sort

Algorithm:
for(i=1; i<n; i++) {
                   x = A[i], insert x to its suitable place between A[0] and A[i-1].
}


Quick Sort

Algorithm:
void QuickSort(int left, int right)
{
      if(left < right){
            //arrange elements  R[left],...,R[right] that
            //producing new sequence:
            R[left],...,R[J-1] < R[J] and R[J+1],...,R[right] > R[J].
            QuickSort(left, J-1);
            QuickSort(J+1, right);
       }
}


Merge Sort

       Merge Sort is a sorting algorithm based on the divide-and-conquer algorithm
       Divide-and-conquer is a general algorithm design paradigm
      Divide: divide the input data in two disjoint subsets
      Recur: solve the sub problems associated with subsets
      Conquer: combine the solutions for each subset into a solution


Searching
       We’ll often work with large amounts of data stored in arrays
       It may be necessary to determine whether an array contains a value that matches a certain key value
       The process of finding a particular element of an array is called searching

       Searching is an action to retrieve information based on particular key from some saved information
       Key is used to do record searching which is desired from a set of data list
       Key must be unique, means there must not be any same key in the data
       Example:
                Student data consists of name, nim, gender, address, place and date of birth
                nim is used as key from the data, as it is unique.

       Several types of searching algorithm:
      Linear Search
      Binary Search
      Interpolation Search

Linear Search
       Linear search compares each element of the array with the search key.
       Since the array is not in any particular order, it’s just as likely that the value will be found in the first element as in the last
       On average, therefore, the program will have to compare the search key with half the elements of the array


Binary Search
       The linear searching method works well for small or unsorted arrays. However, for large arrays linear searching is inefficient
       If the array sorted, the high-speed binary search technique can be used

Interpolation Search
       Interpolation search technique is performed on the sorted data
       This searching process is almost similar with binary search technique
       Searching technique is done with the approximate location of the data
       Example:
       If we want to find a name in the phone book, for example the one beginning with the letter T, then we would not look for from the beginning of the book, but we opened it at 2/3 or ¾ of the book.

   Summary

       Sorting type:
       Ascending
       Descending
       Simple sorting algorithms:
                       Bubble sort
                       Selection sort
                       Insertion sort
       Intermediate sorting algorithms:
                       Quick Sort
                       Merge Sort
       The process of finding a particular element of an array is called searching
       Searching is an action to retrieve information based on particular key from some saved information
       Several types of searching algorithm:
       Linear Search
       Binary Search
       Interpolation Search 

2201760945
Skyconnectiva
Kevin Orlando Sutanto

Komentar

Postingan populer dari blog ini

Cloud Computing Services

Cloud Computing Services What is Cloud? Cloud refers to a network or internet, which is present at certain place which is accessible from any location over public network or private network Cloud Computing refers to manage, configuring, and accessing the applications online. It offer online data storage, compute, network infrastructure and application which delivered as a network services. Cloud computing tends to separate infrastructure with business, whereas terms "infrastructure" refer to hardware, networking, and software which managed as one entity. And terms "Business" refers to procedural workflow, strategic enforcement, etc Deployment Examples Social networking : Facebook, Instagram, LinkedIn, etc. Data sharing / collaboration : Email, Dropbox, etc. Education : Quipper, Smart Campus, E-Learning, E-Library, etc. Business : Office application : Online shop portal, Google doc, Personal / Corporate                  ...

File Processing

FILE PROCESSING SUB TOPICS : Files and Streams File Definition Open File Close File Input File Output File Files and Streams Streams Definition •       To keep key in data from keyboard need to be saved at secondary storage device as a data file. •       Stream is a sequence of character. All input and output data is a stream. C sees file as a stream. •        When a C program run, there are three (3) standard streams activated: 1. Standard Input Stream     Controlling input stream from keyboard 2. Standard Output Stream     Controlling output stream to the monitor 3. Standard Error Stream     Controlling the error messaging •        Each stream associated with a file. File Definition •        File is a collection of record •    ...