0% found this document useful (0 votes)
39 views

Unit 5

Uploaded by

mugil63692
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Unit 5

Uploaded by

mugil63692
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Click on Subject/Paper under Semester to enter.

Probability and Environmental Sciences


Professional English complex function - and Sustainability -
Professional English - - II - HS3252 MA3303 GE3451
I - HS3152
Statistics and Electromagnetic Transmission and
Matrices and Calculus Numerical Methods - Theory - EE3301 Distribution - EE3401

4th Semester
3rd Semester

- MA3151 MA3251
1st Semester

2nd Semester

Digital Logic Circuits - Linear Integrated


Engineering Physics - Engineering Graphics EE3302 Circuits - EE3402
PH3151 - GE3251
Measurements and
Electron Devices and Instrumentation -
Engineering Chemistry Physics for Electrical Circuits - EC3301 EE3403
- CY3151 Engg - PH3202
Microprocessor and
Electrical Machines I - Microcontroller -
Basic Civil and
EE3303 EE3404
Problem Solving and Mechanical Engg -
Python Programming - BE3255
C Programming and Electrical Machines II
GE3151
Electric Circuit Data Structures - - EE3405
Analysis - EE3251 CS3353

Power System Analysis


High Voltage
- EE3501
Engineering - EE3701
Protection and
Switchgear - EE3601
Power Electronics - Human Values and
5th Semester

EE3591 Ethics - GE3791


8th Semester
7th Semester
6th Semester

Power System
Operation and Control
Control Systems - - EE3602 Open Elective 2
EE3503 Project Work /
Open Elective-1
Open Elective 3 Intership
Elective 1 Elective-4
Open Elective 4
Elective 2 Elective-5
Elective 7
Elective 3 Elective-6
Management Elective
All EEE Engg Subjects - [ B.E., M.E., ] (Click on Subjects to enter)
Circuit Theory Digital Logic Circuits Electromagnetic Theory
Environmental Science and Linear Integrated Circuits Discrete Time Systems and
Engineering and Applications Signal Processing
Electronic Devices and Electrical Machines I Electrical Machines II
Circuits
Power Plant Engineering Special Electrical Machines Transmission and Distribution
Power System Analysis Control Systems Power Electronics
Power System Operation Measurements and Design of Electrical Machines
and Control Instrumentation
Communication Engineering Solid State Drives Embedded Systems
Power Quality High Voltage Engineering Protection and Switchgear
Flexible AC Transmission Microprocessors and Electric Energy Generation,
Systems Microcontrollers Utilization and Conservation
Professional Ethics in Physics for Electronics Basic Civil and Mechanical
Engineering Engineering Engineering
Transforms and Partial Environmental Science and Problem Solving and Python
Differential Equations Engineering Programming
Engineering Physics Engineering Chemistry Numerical Methods
Engineering Graphics Technical English Object Oriented Programming
Principles of Management Total Quality Management
www.BrainKart.com
4931_Grace College of Engineering, Thoothukudi

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

BE- Electrical and Electronics Engineering


&
BE- Electronics and Communication Engineering

Anna University Regulation: 2021

CS3353 - C Programming and Data Structures

II Year/III Semester

Question Bank

Unit- V SORTING AND SEARCHING TECHNIQUES

Prepared By,

Ms. S. Abarna, AP/CSE

CS3353_CPDS

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering, Thoothukudi

CS3353- C Programming and Data Structures


UNIT V SORTING AND SEARCHING TECHNIQUES
Insertion Sort – Quick Sort – Heap Sort – Merge Sort –Linear Search – Binary Search.

UNIT-V / PART-A
1 Define best case of an algorithm.
It is the shortest time that an algorithm will use over all instances of size n for a given
problem to produce the result.
2 What is binary search?
Binary search is also a method used to locate a specified item in a sorted list. This method
starts by comparing the searched element to the elements in the middle of the list. If the
comparison determines that the two elements are equal the method stops and returns the
position of the element. If the searched element is greater than the middle element, it
starts the method again using only the bottom half of the sorted list. If the searched
element is less than the middle element, it starts the method again using only the top half
of the sorted list.
3 What is the best case and Average case analysis of shell sort?
 Best case Analysis – O(N log N)
 Average case Analysis – O(N1 . 5)
4 Differentiate linear search and binary search.
Linear search Binary search
Linear search is easy but takes more time Binary search it start searching from
to search an element as it compare all middle, if the searching element is not
element sequentially found in middle then it goes to left or right
and vice versa and hence take less time than
linear search
Iterative in nature Divide and conquer in nature
Linear search requires O(n)times Binary search is very best in time and
efficiency. It requires O(log n)times
5 What is meant by sorting and what are its classifications?
Ordering the data in an increasing or decreasing order according to some relationship
among the data item is called sorting.
a) Internal sorting
b) External sorting
6 What is meant by external sorting? (Dec 19)
External sorting takes place in the secondary memory of a computer, since the number of
objects to be sorted is too large to fit in main memory.
Example:
 Merge sort
 Multiday Merge
 Polyphone Merge

30

CS3353_CPDS

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering, Thoothukudi

CS3353- C Programming and Data Structures


7 What is meant by internal sorting? (Dec 19)
An internal sort is any data sorting process that takes place entirely within the main
memory of a computer. This is possible whenever the data to be sorted is small enough
to all be held in the main memory.
Example:
Bubble sort, Insertion Sort, Heap sort, shell sort, quick sort.
8 What are the various factors to be considered in deciding a sorting algorithm?
 Programming time
 Execution time of the program
 Memory needed for program environment
9 What is the main idea in Bubble sort?
The basic idea underlying the bubble sort is to pass through the file sequentially several
times. Each pass consists of comparing each element in the file with its successor (x[i] and
x [i+1] and interchanging the two elements if they are not in proper order.
10 What is meant by selection sort? Or What are the steps involved in performing
selection sort?(Dec 20)
It will first find the smallest element in the array and swap it with the element in
the first position, then it will find the second smallest element and swap it with the
element in the second position, and it will keep on doing this until the entire array is
sorted. It is called selection sort because it repeatedly selects the next-smallest element
and swaps it into the right place.
11 What is complexity analysis?
It is the analysis of the amount of memory and time an algorithm requires to completion.
There are two types of Complexity
 Space Complexity: Space complexity of an algorithm is the amount of memory it
needs to run to completion.
 Time Complexity: Time complexity is the amount of computer time an algorithm
requires to run to completion.
12 What is insertion sort?
Insertion sort iterates, consuming one input element each repetition, and growing a
sorted output list. Each iteration, insertion sort removes one element from the input data,
finds the location it belongs within the sorted list, and inserts it there. It repeats until no
input elements remain.
13 What are the advantages of Insertion Sort?
 It is easy to implement and efficient to use on small sets of data
 It performs better than algorithms like selection sort and bubble sort. It is over twice
as fast as the bubble sort and almost 40 percent faster than the selection sort.
 It requires less memory space.
 It can be efficiently implemented on data sets that are already substantially sorted.
14 What are the advantages of selection sort?
 It is simple and easy to implement.
 It can be used for small data sets.
 It is 60 percent more efficient than bubble sort.

31

CS3353_CPDS

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering, Thoothukudi

CS3353- C Programming and Data Structures


15 What is linear search?
Linear search is the simplest searching method, which checks each element in a list
sequentially until it finds a specified element. The input to the linear search method is a
sequence and the item that needs to be searched. The output is true if the specified item is
within the provided sequence or false if it is not in the sequence. The complexity of linear
search is O (n).
16 What is meant by Shell sort?
The shell sort, sometimes called the “diminishing increment sort,” improves on the
insertion sort by breaking the original list into a number of smaller sublists, each of
which is sorted using an insertion sort. The unique way that these sub lists are chosen is
the key to the shell sort. Instead of breaking the list into sub lists of contiguous items, the
shell sort uses an increment i, sometimes called the gap, to create a sub list by choosing
all items that are i items apart.
17 What is meant by Radix Sort? Or Define Radix Sort.(Nov/Dec 19)
A multiple pass distribution sort algorithm that distributes each item to
a bucket according to part of the item's key beginning with the least significant part of
the key. After each pass, items are collected from the buckets, keeping the items in order,
then redistributed according to the next most significant part of the key.
18 What is Hashing?
Hashing is a technique used to identify the location of an identifier ‘x’ in the memory by
some arithmetic functions like f(x), which gives address of ‘x’ in the table.
19 List some popular sorting methods.
 Bubble sort
 Bucket sort
 Insertion sort
 Merge sort
 Quick sort
 Selection sort
 Shell sort
20 Explain Hash Function.
Hash Function takes an identifier and computes the address of that identifier in the
hash table.
A simple Hash function :
HASH (KEYVALUE) = KEYVALUE MOD TABLESIZE
21 Mention Different types of popular hash function.
 Division method
 Square method
 Folding method
22 Define Collision.
When two different keys compute in the same location or address in the hash table
through any one of the hashing function then it is termed as collision.

32

CS3353_CPDS

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering, Thoothukudi

CS3353- C Programming and Data Structures


23 Mention Different types of collision resolving techniques.
The collision resolving techniques are:
 Separate chaining.
 Open Addressing
 Linear Probing
 Quadratic Probing
 Double Hashing.
24 Define Separate Chaining
Separate Chaining is a technique used to avoid collision, where a linked list is used to
store the keys which fall into the same address in the hash table.
25 Define Open Addressing.
Open addressing is an alternative to resolving collisions with linked lists. In an open
addressing hashing system, if a collision occurs; alternative cells are tried until an empty
cell is found.
26 What are the uses of hash table?
 Compilers can use hash table to keep track of declared variable in source code.
 A hash table is useful for any graph theory problem where nodes have real names
instead of numbers.
 A third use of hash table is in program that plays games.
 On line spell checkers.
27 What is meant by Rehashing?
The rehashing method builds new table that is about twice as big and scan down the
entire original hash table, computing the new hash value for each element and inserting
it in the new table
28 When should we rehash?
 When table is half full
 When an insertion fails
 When load reaches a certain level
29 What is the need of Extendible Hashing method?
Brief about Extendible Hashing. (May 19)
When open addressing hashing or separate chaining hashing is used, Collisions could
cause several blocks to be examined during a Find, even for a well distributed hash table.
Furthermore, when the table gets too full, an extremely expensive rehashing step must be
performed, which requires O (N) disk accesses. This problem can be overcomes by using
extendible hashing.
30 State the complexity of binary search. (Dec 18)
Time Complexity of Binary Search O (log n)
31 What is double Hashing?
 Double hashing is a collision resolving technique in Open Addressed Hash tables.
 Double hashing uses the idea of applying a second hash function to key when a
collision occurs. Double hashing can be done using :
(hash1(key) + i * hash2(key)) % TABLE_SIZE
Here hash1() and hash2() are hash functions and TABLE_SIZE is size of hash table.(We
repeat by increasing i when collision occurs)

33

CS3353_CPDS

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering, Thoothukudi

CS3353- C Programming and Data Structures


32 What are the advantage and disadvantage of separate chaining and linear
probing?(Dec 18,20)
Advantages of separate chaining
 Simple to Implement
 Hash Table Capacity Not Limited
 Robust technique
Disadvantages of separate chaining
 Cost of maintaining linked list is high.
Advantages of Linear Probing
 Requires less memory than Separate Chaining because no pointers are used.
 Simpler to implement than Quadratic or Double Hashing.
Disadvantages of Linear Probing
 Elements begin to cluster together in groups of adjacent array locations
 Causes "primary clustering" in which there are large blocks of occupied cells
within the hash table. There are "holes" when an element is removed and it is
difficult to determine when to stop looking through the hash table.
33 Compare linear search and binary search. (May 19)
Basis for comparison Linear search Binary search
Time Complexity O(N) O(log 2 N)
Best case time First Element O(1) Center Element O(1)
Prerequisite for an array No required Array must be in sorted
order
Worst case for N number of N comparisons are required Can conclude after only
elements log2N comparisons
Can be implemented on Array and Linked list Cannot be directly
implemented on linked list
Insert operation Easily inserted at the end of Require processing to insert
list at its proper place to
maintain a sorted list.
Algorithm type Iterative in nature Divide and conquer in
nature
Usefulness Easy to use and no need for Anyhow tricky algorithm
any ordered elements. and elements should be
organized in order.
UNIT-V / PART-B
1 With example explain the binary search technique.
2 Explain the insertion sort with its time complexity.
3 State and explain the shell sort. State and explain the algorithm for shell sort. Sort the
elements using shell sort. (Dec 18)
4 Explain separate chaining and extendible hashing.
5 i) Explain the common collision resolution strategies in open address hashing. (Dec 18)
ii) Describe the different hashing functions with an example.
6 Explain the algorithm to perform Radix Sort with Example.

34

CS3353_CPDS

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering, Thoothukudi

CS3353- C Programming and Data Structures


7 Write the selection sort algorithm and explain with suitable example. Give its worst case,
Average Case and Best case time complexities. Or Write an algorithm to implement
selection sort with suitable example. (Dec 19,20)
8 Explain about collision resolution techniques.
9 Given input {4371,1323,6173,4199,4344,9679,1989} and a hash function h(X) = X (mod 10).
Show the resulting (Dec 18)
1. Separate chaining table
2. Open addressing hash table using linear probing
3.Open addressing hash table using Quadratic probing
4.Open addressing hash table with second hash function h2(X)=7-(X mod 7)
10 Explain in detail about Rehashing method and extendible hashing. (Dec 18)
When do you perform rehashing? Illustrate with example. (May 19)
11 Distinguish between linear search and binary search. State and explain the algorithms for
both the search with example. (Dec 18,20)
12 Write an algorithm for binary search with suitable example.(Dec 19)
13 Explain Open Addressing in detail. (Dec 18)
14 Consider a hash table with 9 slots. The hash function is h(k) = k mod 9. The following
keys are inserted in the order 5, 28, 19, 15, 20, 33, 12, 7, 10. Draw the contents of the hash
table when the collisions are resolved by
i) Chaining
ii) Linear Probing
iii) Double Hashing. The second hash function h2(x) = 7 – (x mod 7) (May 19)
15 i) Write a function to perform merge sort. Give example.
ii) Write a routine for insertion sort. Sort the following sequence using insertion sort.
3, 10, 4, 2, 8, 6, 5, 1 (Dec 20)
16 Indicate whether you use an Array, Linked List or Hash Table to store data in each of the
following cases. Justify your answer. (May 19)
i) A list of employee records need to be stored in a manner that is easy to find max
or min in the list
ii) A library needs to maintain books by their ISBN number. Only thing important is
finding them as soon as possible.
iii) A data set needs to be maintained in order to find the median of the set quickly
17 Consider a hash table with 9 slots. The hash function is h(k) = k mod 9. The following
keys are inserted in the order 15, 38, 8, 5, 20, 33, 14, 30. Draw the contents of the hash
table when the collisions are resolved by
i) Chaining
ii) Linear Probing
iii) Double hashing.
The second hash function h2(x) = 7 – (x mod 7). (Dec 20)

35

CS3353_CPDS

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
Click on Subject/Paper under Semester to enter.
Random Process and Electromagnetic
Professional English Linear Algebra -
Professional English - - II - HS3252 Fields - EC3452
MA3355
I - HS3152
C Programming and Networks and
Statistics and
Data Structures - Security - EC3401
Matrices and Calculus Numerical Methods -
CS3353
- MA3151 MA3251
1st Semester

3rd Semester

Linear Integrated

4th Semester
2nd Semester

Signals and Systems - Circuits - EC3451


Engineering Physics - Engineering Graphics
- GE3251 EC3354
PH3151 Digital Signal
Processing - EC3492
Physics for Electronic Devices and
Engineering Chemistry Electronics Engg - Circuits - EC3353
- CY3151 PH3254 Communication
Systems - EC3491
Control Systems -
Basic Electrical & EC3351
Problem Solving and Instru Engg - BE3254 Environmental
Python Programming - Sciences and
GE3151 Digital Systems Design Sustainability -
Circuit Analysis - - EC3352 GE3451
EC3251

Wireless
Communication -
EC3501 Embedded Systems
and IOT Design -
ET3491
VLSI and Chip Design
5th Semester

- EC3552 Human Values and


7th Semester

8th Semester
6th Semester

Artificial Intelligence Ethics - GE3791


and Machine Learning
Transmission Lines and - CS3491
RF Systems - EC3551 Open Elective 2 Project Work /
Intership
Open Elective-1 Open Elective 3
Elective 1
Elective-4
Open Elective 4
Elective 2
Elective-5
Elective 3
Elective-6
All ECE Engg Subjects - [ B.E., M.E., ] (Click on Subjects to enter)
Circuit Analysis Digital Electronics Communication Theory
Basic Electrical and Electrical Engineering and Principles of Digital
Instrumentation Engineering Instrumentation Signal Processing
Electronic Devices Linear Integrated Circuits Signals and Systems
Electronic Circuits I Electronic Circuits II Digital Communication
Transmission Lines and Wave Control System Engineering Microprocessors and
Guides Microcontrollers
Computer Architecture Computer Networks Operating Systems
RF and Microwave Engineering Medical Electronics VLSI Design
Optical Communication and Embedded and Real Time Cryptography and
Networks Systems Network Security
Probability and Random Transforms and Partial Physics for Electronics
Processes Differential Equations Engineering
Engineering Physics Engineering Chemistry Engineering Graphics
Problem Solving and Python Object Oriented Programming Environmental Science
Programming and Data Structures and Engineering
Principles of Management Technical English Total Quality
Management
Professional Ethics in Engineering Mathematics I Engineering Mathematics
Engineering II
Click on Subject/Paper under Semester to enter.
Probability and Environmental Sciences
Professional English complex function - and Sustainability -
Professional English - - II - HS3252 MA3303 GE3451
I - HS3152
Statistics and Electromagnetic Transmission and
Matrices and Calculus Numerical Methods - Theory - EE3301 Distribution - EE3401

4th Semester
3rd Semester

- MA3151 MA3251
1st Semester

2nd Semester

Digital Logic Circuits - Linear Integrated


Engineering Physics - Engineering Graphics EE3302 Circuits - EE3402
PH3151 - GE3251
Measurements and
Electron Devices and Instrumentation -
Engineering Chemistry Physics for Electrical Circuits - EC3301 EE3403
- CY3151 Engg - PH3202
Microprocessor and
Electrical Machines I - Microcontroller -
Basic Civil and
EE3303 EE3404
Problem Solving and Mechanical Engg -
Python Programming - BE3255
C Programming and Electrical Machines II
GE3151
Electric Circuit Data Structures - - EE3405
Analysis - EE3251 CS3353

Power System Analysis


High Voltage
- EE3501
Engineering - EE3701
Protection and
Switchgear - EE3601
Power Electronics - Human Values and
5th Semester

EE3591 Ethics - GE3791


8th Semester
7th Semester
6th Semester

Power System
Operation and Control
Control Systems - - EE3602 Open Elective 2
EE3503 Project Work /
Open Elective-1
Open Elective 3 Intership
Elective 1 Elective-4
Open Elective 4
Elective 2 Elective-5
Elective 7
Elective 3 Elective-6
Management Elective
All EEE Engg Subjects - [ B.E., M.E., ] (Click on Subjects to enter)
Circuit Theory Digital Logic Circuits Electromagnetic Theory
Environmental Science and Linear Integrated Circuits Discrete Time Systems and
Engineering and Applications Signal Processing
Electronic Devices and Electrical Machines I Electrical Machines II
Circuits
Power Plant Engineering Special Electrical Machines Transmission and Distribution
Power System Analysis Control Systems Power Electronics
Power System Operation Measurements and Design of Electrical Machines
and Control Instrumentation
Communication Engineering Solid State Drives Embedded Systems
Power Quality High Voltage Engineering Protection and Switchgear
Flexible AC Transmission Microprocessors and Electric Energy Generation,
Systems Microcontrollers Utilization and Conservation
Professional Ethics in Physics for Electronics Basic Civil and Mechanical
Engineering Engineering Engineering
Transforms and Partial Environmental Science and Problem Solving and Python
Differential Equations Engineering Programming
Engineering Physics Engineering Chemistry Numerical Methods
Engineering Graphics Technical English Object Oriented Programming
Principles of Management Total Quality Management

You might also like