Data Structure - CS3301 - Important Questions With Answer - Unit 5 - Searching Sorting and Hashing Techniques
Data Structure - CS3301 - Important Questions With Answer - Unit 5 - Searching Sorting and Hashing Techniques
Environmental Sciences
Professional English and Sustainability -
Professional English - - II - HS3252 Discrete Mathematics GE3451
I - HS3152 - MA3354
Statistics and Theory of Computation
Matrices and Calculus Numerical Methods - Digital Principles and - CS3452
3rd Semester
4th Semester
- MA3151 MA3251 Computer Organization
1st Semester
2nd Semester
8th Semester
6th Semester
E
Anna University Regulation: 2021
II Year/III Semester
RA
TECHNIQUES)
Prepared By,
CS3301_DS
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com Page 2 of 8
TWO MARKS
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.
2. What do you mean by internal and external sorting?
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. External sorting is a term
for a class of sorting algorithms that can handle massive amounts of data.
E
External sorting is required when the data being sorted do not fit into the
CO
main memory of a computing device (usually RAM) and instead they must
reside in the slower external memory (usually a hard drive)
3. Define bubble sort
Bubble sort is a simple sorting algorithm that works by repeatedly stepping
through the list to be sorted, comparing each pair of adjacent items and
swapping them if they are in the wrong order. The pass through the list is
CE
repeated until no swaps are needed, which indicates that the list is sorted. The
algorithm gets its name from the way smaller elements "bubble" to the top of
the list
4. How the insertion sort is done with the array?
RA
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 are the steps for selection sort?
The algorithm divides the input list into two parts: the sublist of items
already sorted, which is built up from left to right at the front (left) of the list,
and the sublist of items remaining to be sorted that occupy the rest of the list.
Initially, the sorted sublist is empty and the unsorted sublist is the entire
input list. The algorithm proceeds by finding the smallest (or largest,
depending on sorting order) element in the unsorted sublist, exchanging it
with the leftmost unsorted element (putting it in sorted order), and moving
CS3301_DS
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com Page 3 of 8
E
Radix Sort is a clever and intuitive little sorting algorithm. Radix sort is a
noncomparative integer sorting algorithm that sorts data with integer keys by
CO
grouping keys by the individual digits which share the same significant position
and value. Radix Sort puts the elements in order by comparing the digits of the
numbers.
9. Define searching
G
CS3301_DS
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com Page 4 of 8
For binary search, the array should be arranged in ascending or descending order.
In each step, the algorithm compares the search key value with the middle element
of the array. If the key match, then a matching element has been found and its
index, or position, is returned. Otherwise, if the search key is less than the middle
element, then the algorithm repeats its action on the sub-array to the left of the
middle element or, if the search key is greater, on the sub-array to the right.
E
13. Define hashing function
CO
A hashing function is a key-to-transformation, which acts upon a given key to
compute the relative position of the key in an array. A simple hash function
HASH(KEY_Value)= (KEY_Value)mod(Table-size)
There are three strategies in open addressing: Linear probing Quadratic probing
Double hashing
G
The following are the collision resolution methods Separate chaining Open
addressing Multiple hashing
CS3301_DS
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com Page 5 of 8
17 . Define Hashing.
The hash table data structure is merely an array of some fixed size, containing the
keys. A key is a string with an associated value. Each key is mapped into some
number in the range 0 to tablesize-1 and placed in the appropriate cell.
E
19.What do you mean by hash function?
CO
A hash function is a key to address transformation which acts upon a given key to
compute the relative position of the key in an array. The choice of hash function
should be simple and it must distribute the data evenly. A simple hash function is
hash_key=key mod tablesize.
CE
20 Write the importance of hashing.
• Maps key with the corresponding value using hash function. • Hash tables
support the efficient addition of new entries and the time spent on searching for the
RA
Separate chaining is a collision resolution technique to keep the list of all elements
that hash to the same value. This is called separate chaining because each hash
table element is a separate chain (linked list). Each linked list contains all the
elements whose keys hash to the same index.
CS3301_DS
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com Page 6 of 8
• The elements are evenly distributed. Some elements may have more elements and
some may not have anything.
• It requires pointers. This leads to slow the algorithm down a bit because of the
time required to allocate new cells, and also essentially requires the
implementation of a second data structures
E
26. What are the types of collision resolution strategies in open addressing?
empty cell. If the table is big enough, a free cell can always be found, but the time
to do so can get quite large.
If the table gets too full, the running time for the operations will start taking too
long and inserts might fail for open addressing with quadratic resolution. A
solution to this is to build another table that is about twice as big with the
associated new hash function and scan down the entire original hash table,
CS3301_DS
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com Page 7 of 8
computing the new hash value for each element and inserting it in the new table.
This entire operation is called rehashing.
If either open addressing hashing or separate chaining hashing is used, the major
problem is that collisions could cause several blocks to be examined during a Find,
even for a welldistributed hash table. Extendible hashing allows a find to be
performed in two disk accesses. Insertions also require few disk accesses.
• Time taken for finding the next available cell is large. • In linear probing, we
E
come across a problem known as clustering.
CO
33. Mention one advantage and disadvantage of using quadratic probing.
Advantage: The problem of primary clustering is eliminated. Disadvantage: There
is no guarantee of finding an unoccupied cell once the table is nearly half full.
CE
34. Mention the types of sorting
PART B
1.Outline the algorithm to perform linear search on an array of ‘N’ numbers .
Illustrate each step of the algorithm with an example(Nov/Dec 2022)
2.Outline the algorithm to sort an array of ‘N’ numbers using bubble sort. Illustrate
G
6.The keys 12,18,13,2,3,23,5 and 15 are inserted into an initially empty hash table
of length 10 using linear probing with hash function h(k)= k mod 10. What is the
CS3301_DS
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com Page 8 of 8
E
CO
CE
RA
G
CS3301_DS
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
Click on Subject/Paper under Semester to enter.
Professional English Discrete Mathematics Environmental Sciences
Professional English - - II - HS3252 - MA3354 and Sustainability -
I - HS3152 GE3451
Digital Principles and
Statistics and Probability and
Computer Organization
Matrices and Calculus Numerical Methods - Statistics - MA3391
- CS3351
- MA3151 MA3251
3rd Semester
1st Semester
4th Semester
2nd Semester
Deep Learning -
AD3501
Embedded Systems
Data and Information Human Values and
and IoT - CS3691
5th Semester
7th Semester
8th Semester
Open Elective-1
Distributed Computing Open Elective 2
- CS3551 Project Work /
Elective-3
Open Elective 3 Intership
Big Data Analytics - Elective-4
CCS334 Open Elective 4
Elective-5
Elective 1 Management Elective
Elective-6
Elective 2
All Computer Engg Subjects - [ B.E., M.E., ] (Click on Subjects to enter)
Programming in C Computer Networks Operating Systems
Programming and Data Programming and Data Problem Solving and Python
Structures I Structure II Programming
Database Management Systems Computer Architecture Analog and Digital
Communication
Design and Analysis of Microprocessors and Object Oriented Analysis
Algorithms Microcontrollers and Design
Software Engineering Discrete Mathematics Internet Programming
Theory of Computation Computer Graphics Distributed Systems
Mobile Computing Compiler Design Digital Signal Processing
Artificial Intelligence Software Testing Grid and Cloud Computing
Data Ware Housing and Data Cryptography and Resource Management
Mining Network Security Techniques
Service Oriented Architecture Embedded and Real Time Multi - Core Architectures
Systems and Programming
Probability and Queueing Theory Physics for Information Transforms and Partial
Science Differential Equations
Technical English Engineering Physics Engineering Chemistry
Engineering Graphics Total Quality Professional Ethics in
Management Engineering
Basic Electrical and Electronics Problem Solving and Environmental Science and
and Measurement Engineering Python Programming Engineering
Click on Subject/Paper under Semester to enter.
Environmental Sciences
Professional English and Sustainability -
Professional English - - II - HS3252 Discrete Mathematics GE3451
I - HS3152 - MA3354
Statistics and Theory of Computation
Matrices and Calculus Numerical Methods - Digital Principles and - CS3452
3rd Semester
4th Semester
- MA3151 MA3251 Computer Organization
1st Semester
2nd Semester
8th Semester
6th Semester
4th Semester
- MA3151 MA3251 Computer Organization
1st Semester
2nd Semester
Computer Networks -
CS3591
Object Oriented
Full Stack Web Software Engineering - Human Values and
5th Semester
8th Semester
6th Semester
Elective 1 Elective-5
Management Elective
Elective-6
Elective 2
All Computer Engg Subjects - [ B.E., M.E., ] (Click on Subjects to enter)
Programming in C Computer Networks Operating Systems
Programming and Data Programming and Data Problem Solving and Python
Structures I Structure II Programming
Database Management Systems Computer Architecture Analog and Digital
Communication
Design and Analysis of Microprocessors and Object Oriented Analysis
Algorithms Microcontrollers and Design
Software Engineering Discrete Mathematics Internet Programming
Theory of Computation Computer Graphics Distributed Systems
Mobile Computing Compiler Design Digital Signal Processing
Artificial Intelligence Software Testing Grid and Cloud Computing
Data Ware Housing and Data Cryptography and Resource Management
Mining Network Security Techniques
Service Oriented Architecture Embedded and Real Time Multi - Core Architectures
Systems and Programming
Probability and Queueing Theory Physics for Information Transforms and Partial
Science Differential Equations
Technical English Engineering Physics Engineering Chemistry
Engineering Graphics Total Quality Professional Ethics in
Management Engineering
Basic Electrical and Electronics Problem Solving and Environmental Science and
and Measurement Engineering Python Programming Engineering