You are on page 1of 11

UNIT IV:

SPECIAL DATA STRUCTURES


OPERATIONS
WEEK 7-8
TOPIC:

 Sorting
 Merging
 Updating
 Creation
SORTING

• Arranging data elements of a data structure in a specified order is called sorting.


• Sorting refers to arranging data in a particular format. Sorting algorithm specifies
the way to arrange data in a particular order. Most common orders are in numerical
or lexicographical order.
• The importance of sorting lies in the fact that data searching can be optimized to a
very high level, if data is stored in a sorted manner. Sorting is also used to represent
data in more readable formats.
Following are some of the examples of sorting in real-life scenarios
• Telephone Directory − The telephone directory stores the telephone numbers of people sorted
by their names, so that the names can be searched easily.
• Dictionary − The dictionary stores words in an alphabetical order so that searching of any
word becomes easy.
CATEGORIES OF SORTING
• The techniques of sorting can be divided into two categories. These are:
• Internal Sorting
• External Sorting

• Internal Sorting: If all the data that is to be sorted can be adjusted at a time
in the main memory, the internal sorting method is being performed.
• External Sorting: When the data that is to be sorted cannot be
accommodated in the memory at the same time and some has to be kept in
auxiliary memory such as hard disk, floppy disk, magnetic tapes etc, then
external sorting methods are performed.
IN-PLACE SORTING AND NOT-IN-PLACE SORTING

• Sorting algorithms may require some extra space for comparison and
temporary storage of few data elements. These algorithms do not require any
extra space and sorting is said to happen in-place, or for example, within the
array itself. This is called in-place sorting. Bubble sort is an example of in-
place sorting.
• However, in some sorting algorithms, the program requires space which is
more than or equal to the elements being sorted. Sorting which uses equal or
more space is called not-in-place sorting. Merge-sort is an example of not-
in-place sorting.
THE COMPLEXITY OF SORTING ALGORITHM
• The complexity of sorting algorithm calculates the running time of
a function in which 'n' number of items are to be sorted. The choice
for which sorting method is suitable for a problem depends on
several dependency configurations for different problems. The
most noteworthy of these considerations are:
• The length of time spent by the programmer in programming a specific
sorting program
• Amount of machine time necessary for running the program
• The amount of memory necessary for running the program
TYPE OF SORTING TECHNIUES
• There are many algorithms that can be used to perform sorting,
for example,
• Bubble Sort
• Selection Sort
• Merge Sort
• Insertion Sort
• Quick Sort
• Heap Sort
MERGING

• Combining elements of two similar data structures to form a new data


structure of the same type, is called merging.
• When two lists List A and List B of size M and N respectively, of similar type
of elements, clubbed or joined to produce the third list, List C of size (M+N),
then this process is called merging.
UPDATING

• Updates or modifies the data in the dt structure


• can be performed on array
CREATION

• Creating Data structure from scratch

int Sales[7];

You might also like