0% found this document useful (0 votes)
7 views5 pages

Unit 6

M3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views5 pages

Unit 6

M3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

UNIT-VI

Introduction

Searching refers to an operation of finding the location of an item in a table or a file. Depending
on the location of the records to be searched, searching techniques are classified into two types.

External searching:

When the records are stored in files, disk, tape any secondary storage, then the searching is
known as external searching.

Internal searching

When the records to be searched are stored entirely within computer memory, then it is known as
internal searching.

Some internal searching methods are :

Linear or sequential search


Binary search

Sorting is a method of arranging keys in a file in ascending or descending order. Sorting makes
handling of records in a file easier.

Sorting can be classified into two types:

Internal sorting :Sorting of records in a file which is stored in main memory.


External sorting : sorting of records in a file which is stored in secondary memory.

Prepared by : M V B REDDY 69
Some sorting techniques are

Bubble sort
Insertion sort
Selection sort
Quick sort
Tree sort

Linear search :

This is a simplest search technique. In this method, the array is searched for the required element
from the first element onwards either the list is exhausted or the required element is found.

Binary search :
To implement binary search method, the elements must be in sorted order. This method is
implemented as given below:
 The key is compared with item in the middle position of array.
 If the key matches with item, return it and stop.
 If the key is less than mid positioned item, then the item to be found must be in first half of
array, otherwise it must be in second half of array.
 Repeat the procedure for lower half (or upper half) of array until the elements is found.

Prepared by : M V B REDDY 70
QUIZ QUESTIONS

1. The worst case complexity of linear search is


a) O(n) b) O(n2) c) O(nlogn) d) 0(n3)
2. The worst case complexity of binary search is
a) O(n) b) CKlogn) c) O(n:) d) O(nlogn)
3. The average case complexity of binary search is
a) O(n2) b) CKlog n) c) O(n2) d) O(n log n)
4. The average case complexity of bubble sort is
a) O(n2) b) CKnlogn) c) O(n) d) O(logn)
5. The worst case complexity of bubble sort is
a) O(n log n) b) O(n2) c) O(log n) d) 0(n)
6. The average case complexity of quick sort is
a) O(n log n) b) O(n2) c) O(log n) d) 0(n)
7. The worst case complexity of quick sort is
a) O(n2) b) O(n log n) c) O(n) d) O(logn)
8. The average case complexity of binary search tree sort is
a) O(n log n) b) O(log n) c) O(n2) d) O(n)
9. The worst case complexity of binary search tree sort is
a) O(n log n) b) O(log n) c) O(n2) d) O(n)
10. For the list of only few elements which search technique is efficient
a) binary search b) Linear search
c) fibonacci search d) none
11. For the list of large number of elements which search technique is efficient
a) linear search b) binary search c) none
12. Which of the sorting techniques is more efficient?
a) heap sort b) bubble sort
c) insertion sort d) quick sort
13. Quick sort is same as selection sort when
a) elements are already in sorted order b) elements are in reverse order
c) elements are randomly ordered d) none
14. Heap sort is implemented efficiently using :
a) arrays b) linked list c) queues d) none

Prepared by : M V B REDDY 71
15. Insertion sort is implemented efficiently using
a) arrays b) linked list c) none
16. Data movement is minimized in
a) insertion sort b) selection sort c) both a & b d) none

17. For randomly ordered elements, which algorithm works better :


a) heap sort b) quick sort c) insertion sort d) bubble sort
18. Each node is greater than its children in case of
a) complete binary tree b) heap tree
c) binary search tree d) extended binary tree
19. If the elements are stored using linked lists, which sorting is more efficient
a) selection sort b) insertion sort c) bubble sort d) none
20. The binary search tree sort is less efficient when
a) data is completely in sorted order b) data is in completely reverse sorted order
c) in randomly sorted tree d) both a & b
21. The growing phase in heap sort constitutes
a) sorting element of heap tree c) botha&b b) constructing a heap tree d) none

22. Shrinking phase in heap sort constitutes


a) sorting elements of heap tree b) constructing a heap tree d) none
c) botha&b
23. The elements must be in sorted order in case of
a) binary search b) linear search
c) cannot be determined d) none
24. A very small dummy elements is introduced in the beginning of list in
a) quicksort b) insertion sort c) selection sort d) bubble sort
25. In each pass of bubble sort, for ascending order
a) the largest element is placed in position in list
b) the smallest elements is placed in proper position in list
c) cannot be determined
d) none

Prepared by : M V B REDDY 72
PREVIOUS QUESTIONS

1. Write and explain linear search procedure with a suitable example.


2. Formulate recursive algorithm for binary search with its timing analysis.
3. Write and explain non-recursive algorithm for binary search with suitable example and discuss the
various time complexities of binary search.
4. Suppose that the list contains the integers 1,2, ...8 in this order. Trace through the steps of binary search to
determine what comparisons of keys are done in searching.
(i) to locate 3 (ii) to locate 4.5
5. Explain the algorithm for selection sort and give a suitable example.
6. Explain the algorithm for exchange sort with a suitable example.
7. Compare sort and exchange sort.
8.Design an algorithm that will delete the entry with the largest key from the top of the heap and restore
the heap properties of the resulting smaller list.
9. By hand, trace through the steps of selection sort for the following lists. The following seven numbers
to be sorted into increasing order: 12 20 34 27 30 36 23
10. By hand, trace through the steps of selection sort for the following lists.
The following list of 14 names to be sorted into alphabetical order. Tim Dom Eva Roy Tom Kim Guy
Amy Jon Ann Jim Kay Ron Jan
11. Trace through the steps by hand to sort the following list in Quick sort
28 7 39 3 63 13 61 17 50 21

12.Explain heap sort with example. Write necessary algorithms.


13. Explain Quick sort with algorithm.
14. Analyze the worst case performance of quick sort and compare with selection sort.

Prepared by : M V B REDDY 73

You might also like