cs3353 Cdsunit V
cs3353 Cdsunit V
&
Question bank
Prepared By,
cs3353_cds
lOMoARcPSD|47265940
UNIT V
SORTING AND SEARCHING TECHNIQUES
1 Define sorting
Sorting arranges the numerical and alphabetical data present in a list in a
specific order or sequence. There are a number of sorting techniques
available. The algorithms can be chosen based on the following factors
● Size of the data structure
● Algorithm efficiency
Programmer’s knowledge of the technique
51
CS3353_CDS
a. Pass 1: A[2] is compared with A[1] and placed them in sorted order.
b. Pass 2: A[3] is compared with both A[1] and A[2] and inserted at an appropriate
place. This makes A[1], A[2],A[3] as a sorted sub array.
c. Pass n-1: A[n] is compared with each element in the sub array
A [1], A [2] …A [n-1] and inserted at an appropriate position.
5 what is insertion sort? How many passes are required for theelements to be sorted ?
one of the simplest sorting algorithms is the insertion sort. Insertionsort consist of N-1 passes .
For pass P=1 through N-1 , insertion sort ensures that the elements in positions 0 through P-1
are in sorted order .It makes use of the fact that elements in position 0
through P-1 are already known to be in sorted order .
7 Differentiate between merge sort and quick sort? Merge sort quick
sort
1. Divide and conquer strategy Divide and conquer strategy
2. Partition by position Partition by value
8 Mention some methods for choosing the pivot element in quick sort?
1. Choosing first element
2. Generate random number
3. Median of three
52
CS3353_CDS
9 What are the three cases that arise during the left to right scanin quick sort?
1. I and j cross each other
2. I and j do not cross each other
3. I and j points the same position
11 What is sorting?
Sorting is the process of arranging the given items in a logical order. Sorting is an example
where the analysis can be preciselyperformed.
53
CS3353_CDS
17 Define searching
Searching refers to determining whether an element is present in a given list of
elements
or not. If the element is present, the search is considered as successful, otherwise it is
considered as an unsuccessful search. The choice of a searching technique is based on the
followingfactors
a. Order of elements in the list i.e., random or sorted
b. Size of the list
54
CS3353_CDS
PART B
1
Explain the sorting algorithms[insertion sort,quick sort,merge sort, heapsort]
4 Write a C program to perform searching operations using linear and binary search.
55
CS3353_CDS