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

DSA - Question Bank

Uploaded by

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

DSA - Question Bank

Uploaded by

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

MUTHAYAMMAL ENGINEERING COLLEGE

(An Autonomous Institution)


(Approved by AICTE, New Delhi, Accredited by NAAC & Affiliated to Anna University)
Rasipuram - 637 408, Namakkal Dist., Tamil Nadu
QB
QUESTION BANK

CSE II/III-B

Course Name : 21CSF01 - Data Structures and Algorithms

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

UNIT I - INTRODUCTION
1. Define data structures.
An arrangement of data in a computer's memory or Way of organizing data in a computer so that it
can be used effectively

2. Define static data structures.


A data structure formed when the number of data items are known in advance is referred as static data
structure or fixed size data structure.EX: Array, pointers, structures, etc.,

3. Define dynamic data structures.


A data structure formed when the number of data items are not known in advance is known as dynamic data
structure or variable size data structure. Ex: linked lists, stacks, queues, trees.

4. What are the different types of data structure?


 Linear data structure.
 Non-linear data structure

5. Define linear data structures.


Linear data structures, where the data are arranged in sequential order or the data having a linear relationship
between its adjacent elements. Linked lists are examples of linear data structures.eg linked list, array

Anu Abirami Arun Babu Balaji Gowtham

6. Define non-linear data structures.


Non-linear data structures are data structures that don’t have a linear relationship between its adjacent
elements but have a hierarchical relationship between the elements. Trees and graphs are examples of non-
linear data structures. Eg: Tree , Graph
7. Define Abstract Data Type(ADT).
An abstract data type is a set of operations for which the implementation of the data structure is not specified
anywhere in the program.

8. Define data and data item.


Data are simply values or sets of values Data items refers to a single unit of values it classified into
i.Group items : Data item divided into sub-items
Ex: Name divided into three - first name, middle
name and last name
ii. Elementary items : Data items that are not able to divide into sub-items
Ex: PAN Number , Bank account number etc

9. What is variable and entity?


Variable is a symbolic name given to the value/ data a=2 ……… a - is a variable name for a data
Entity : Something that has certain attributes ( additional information about entity ) or properties which may
be assigned values

10. List the Primitive Data Types and define it.


Each variable has a specific data typeIt tells - size, range and the type of a value that can be stored in a
variable.
There are 4 basic primitive data types
 integer data types, such as short, int, long
 floating-point data types, such as float, double
 character data type, such as char
 Pointer

11. What is the use of Pointer ?


Special type of variables that are used to store address of another variable rather than values
This variable can be of type int, char or any other pointer

12. Give the Basic Operations on Data Structures


 Creation –Creating a new DS
 Insertion − Add a new data in the existing DS
 Deletion − Delete an existing data item from the DS
 Traversal − Access each data item exactly once so that it can be processed
 Searching − Find out the location of the data item if it exists in the DS
 Sorting − Arranging the data items in some order

13. How we can measure efficiency


Efficiency of DS is always measured in terms of TIME and SPACE.Efficient Algorithm that takes least
possible running time and consumes least memory space

14. Define asymptotic analysis


asymptotic analysis Measures the performance of the algorithm with the change in the order of the input size

15. Define Best, Worst, and Average Case Complexity


 Worst Case Complexity: Function defined by the maximum number of steps/ operations taken to
execute on any instance of size n
 Best Case Complexity: Function defined by the minimum number of steps/ operations taken to
execute on any instance of size n
 Average Case Complexity: The function defined by the average number of steps taken on any
instance of size n
16. What is Asymptotic complexity
Efficiency is measured with the help of asymptotic notations. Approximate measure of time complexity is
called Asymptotic complexity

17. What is meant by Time complexity


Time complexity of an algorithm quantifies the amount of time taken by an algorithm to run as a function of
the size of the input to the problem.

18. List the Asymptotic Notations


Mathematical notations used to describe the running time of an algorithm when the input tends towards a
particular value or a limiting value
There are mainly three asymptotic notations:
 Theta notation,
 Omega notation and
 Big-O notation

19. Give the Analysis and Design of Algorithms


 Big O Notation: is an Asymptotic Notation for the worst case
 Ω Notation (omega notation): is an Asymptotic Notation for the best case
 Θ Notation (theta notation) : is an Asymptotic Notation for the worst case and the best case.

20.Define Theta Notation (Θ-notation)


It represents both the upper and the lower bound of the running time of an algorithm. It analyzes the
average case complexity of an algorithm
If f(n) and g(n) are two functions,Then Θ (g(n)) = f(n) If there exist positive constants c and n0 such
that c1g(n) ≤ f(n) ≤ c2g(n) for all n ≥ n0
24. Define Big-O Notation (O-notation)
Measure the performance of any algorithm by providing the order of growth of the function.It gives upper
bound [maximum unit of time taken to run the program ] .Thus, it gives the worst case complexity of an
algorithm
If f(n) and g(n) are two functions, then O(g(n)) = { f(n) If there exist positive constants c and n0 such
that f(n) ≤ c.g(n), for all n ≥ n0

25. Define Omega Notation (Ω-notation)


Represents the lower bound of the running time of an algorithm. Thus, it provides best case complexity of an
algorithm . If f(n) and g(n) are two functions, then Ω(g(n)) = f(n) If there exist positive constants c and n0
such that f(n) ≥ c.g(n), for all n ≥ n0

26. List the type of Running Time Functions


 1 (constant running time): – Instructions are executed once or a few times
 logN (logarithmic) – A big problem is solved by cutting the original problem in smaller sizes,
by a constant fraction at each step
 N (linear) – A small amount of processing is done on each input element
 N logN – A problem is solved by dividing it into smaller problems
 N2(quadratic)- Typical for algorithms that process all pairs of data items (double nested loops)
 N3 (cubic) –Processing of triples of data (triple nested loops)
 NK (polynomial)
 2 n(exponential)

27.Define searching and List out the types of searching method


Finding an element position in a given array called searching
Type: linear search
binary search

28. Define linear search


Linear search is a very simple search algorithm. In this type of search, a sequential search is made
over all items one by one. Every item is checked and if a match is found then that particular item is returned,
otherwise the search continues till the end of the data collection.

29. Binary Search


It is fastest searching algorithms. It works on the principle of divide and conquers technique. Binary Search
Algorithm can be applied only on Sorted arrays.

30. Write about Time Complexity Analysis of linear search and binary search
Linear search : The element being searched may be present at the last position or not present in the
array at all.In this case, the search terminates in success with n comparisons. Worst case, takes O(n)
operations.
Binary search: The element being searched by iteration or recursive call, where in each search gets
reduced to half of the array. There are log2n iterations or recursive calls.Worst case, takes O(log2n) operations
PART-B

1. Discuss in detail about Basic Terminologies and Elementary Data Organizations


2. Explain the Data Structure Operations in detail.
3. How we can Analyze the algorithm. Explain briefly about Analysis of an Algorithm, Asymptotic Notations
and Time-Space trade off.
4. Write short notes on Linear Search and Binary Search Techniques and their complexity analysis.
5. Write Binary search algorithm and explain with example with its time complexity.

UNIT II - STACKS AND QUEUES

PART-A

1. Array- kind of data structure that can store a fixed-size sequential collection of elements of the same type

There are 2 types of C arrays. They are,


1. One dimensional array
2. Multi dimensional array

2. Define recursion function


Recursion is an approach in which a function calls itself with an argument. Upon reaching a
termination condition, the control returns to the calling function. Ex: Fatorial

3. Define a stack.
Stack is an ordered collection of elements in which insertions and deletions are restricted to one end called
top

4. List out the basic operations that can be performed on a stack and a queue.
The basic operations that can be performed on a stack and queue are,
 Push operation
 Pop operation
 Peek operation
 Empty check
 Full occupied check

5. State the different ways of representing expressions.


The different ways of representing expressions are,
 Infix Notation A+B
 Prefix Notation +AB
 Postfix Notation AB+
6. State the rules to be followed during infix to postfix conversions.
1. Start with empty stack
2. If left parenthesis encountered push into the stack
3. If right parenthesis encountered, pop all element of the stack until left parenthesis found
4. Place all operand on the output
5. If operator is lower priority pop all operator from stack
6. Push the operator on to stack
7. At end of input , pop all symbol from stack

7. Define a queue.
Queue is an ordered collection of elements in which insertions and deletions take place in 2 ends. The end
from which elements are added referred to rear end, and the end from which deletions are made is referred
to as the front end.

8. Define a priority queue.


Priority queue is a collection of elements, each containing a key referred as the priority for that element.
Elements can be inserted in any order (ie. of alternating priority), but are arranged in order of their priority
value in the queue.

9.Define a dequeue.
Dequeue(Double-ended queue) is another form of a queue in which insertions and deletions are made at both
the front and rear ends of the queue.

10. What are the applications of Queue?


 Jobs submitted to printer
 Real life line
 Calls to large companies
 Access to limited resources in Universities
 Accessing files from file server

11.What are the applications of priority queue?


 Operating system
 External sorting
 Greedy algorithms
 Event simulation
12. What are the types of queues?
 Linear Queues – The queue has two ends, the front end and the rear end. The rear end is where we
insert elements and front end is where we delete elements.

 Circular Queues – Another form of linear queue in which the last position is connected to the first
position of the list

 Double-Ended-Queue – Another form of queue in which insertions and deletions are made at both
the front and rear ends of the queue.

13. List the applications of stacks


 Towers of Hanoi
 Reversing a string
 Balanced parenthesis
 Recursion using stack
 Evaluation of arithmetic expressions

14. Write the algorithm to check balancing symbol


1. Make an empty stack
2. Read input string until its end
3. If character have open bracket push on to the stack
4. If character have close bracket pop symbol of the top stack
5. If symbol not matched or at the end stack is not empty report error else success

15. Write algorithm to evaluate postfix expression


1. If operand found push on to the stack
2. If operator, pop 2 symbols from the stack
3. Perform operation , push the result to the stack
4. Repeat steps 1-3 until end of file

16. Mention the overflow condition in array implementation of Queue? (CO2,K2)


Overflow : checking queue is full (contain all elements in array) called overflow
Isfull( )
{ if(front==0 && rear==size-1)
{ printf(“queue is full”); }
}

17. Mention the underflow condition in array implementation of Queue? (CO2,K2)


Underflow : checking queue is empty (contain no elements in array) called underflow
Isempty( )
{ if(front==-1 && rear==-1)
{ printf(“queue is empty”); }
}

18.Distinguish between Stack and Queue? (May 2013) (CO2,K2)


Differentiate LIFO and FIFO? (Nov/Dec 2013) (CO2,K1)

STACK QUEUE
Objects are inserted and removed from different
Objects are inserted and removed at the same end.
ends.
In stacks only one pointer is used. It points to the top
In queues, two different pointers are used for front
of the stack.
and rear ends.
In stacks, the last inserted object is first to come out. In queues, the object inserted first is first deleted.
Stacks follow Last In First Out (LIFO) order. Queues following First In First Out (FIFO) order.
Stack operations are called push and pop. Queue operations are called enqueue and dequeue.
Stacks are visualized as vertical collections. Queues are visualized as horizontal collections.
Collection of dinner plates at a wedding reception is People standing in a file to board a bus is an example
an example of stack. of queue.

19. Give the properties of Priority Queue

1. It should be Binary tree


2. It should be a complete Binary tree
3. A Binary Heap is either Min Heap or Max Heap

20. Define Max Heap

In a Max Binary Heap, the key at root must be maximum among all keys present in Binary Heap. The
same property must be recursively true for all nodes in Binary Tree
21.Define Max Heap

In a Min Binary Heap, the key at root must be minimum among all keys present in Binary Heap. The
same property must be recursively true for all nodes in Binary Tree

PART- B
1. Write down and explain the operations performed in Stack ADT using array with its Algorithms and
their complexity analysis
2. Enumerate the Applications of Stacks with example
3. Explain briefly about the operations for enqueue and dequeue on queue ADT using array with its
Algorithms and their analysis
4. Explain the basic concept of Circular Queue Operations with example
5. With suitable examples explain the Priority Queue Operations with example
6. List and Explain various operation of Circular Queue with example
7. Explain infix to postfix expression and evaluating postfix expression with example. A*B+(C-D/E)

UNIT III - LINKED LIST


PART-A

1. Define structure
Structure is a collection of variables belongings to the different data type. You can store group of
data of different data type in an array.
Eg : struct student
{
char name;
int roll no;
float m1,m2,m3;
};

2. Define pointer
A pointer is a variable whose value is the address of another variable, i.e., direct address of the
memory location. Like any variable or constant, you must declare a pointer before using it to store any
variable address. Eg :type *var-name;
3. Define dynamic memory allocation
The process of allocating memory at runtime is known as dynamic memory allocation. Library routines
known as "memory management functions" are used for allocating and freeing memory during execution
of a program. These functions are defined in stdlib.h.
Function Description

malloc() allocates requested size of bytes and returns a void pointer pointing to the first byte of the
allocated space

calloc() allocates space for an array of elements, initialize them to zero and then returns a void
pointer to the memory

free releases previously allocated memory


realloc modify the size of previously allocated space
4. Define singly linked list
Linked list elements are not stored at contiguous location; the elements are linked using pointers.

5. Define doubly linked list


A Doubly Linked List (DLL) contains an extra pointer, typically called previous pointer, together with
next pointer and data which are there in singly linked list.

6. Define circularly linked list


Circular linked list is a linked list where all nodes are connected to form a circle. There is no NULL at
the end. A circular linked list can be a singly circular linked list or doubly circular linked list.

7. State the different types of linked lists & different types of circular linked lists.
The different types of linked list include single linked list, double linked list and circular linked list.
The different types of circular linked list include circular singly linked list and circular doubly linked list.

8. List the basic operations carried out in a linked list.


The basic operations carried out in a linked list includes, Creation, Insertion(In First, middle and last),
Deletion(In First, middle and last),Searching, Traversing.

9. List the advantages in using a linked list.


 The advantages in using a linked list are,
 It is not necessary to specify the number of elements in a linked list during its declaration.
 Linked list can grow and shrink in size depending upon the insertion and deletion that occurs in the list.
 Insertions and deletions at any place can be handled easily and efficiently.
 A linked list does not waste any memory space.

10. List out the disadvantages in using a linked list.


The disadvantages in using a linked list are,
 Searching a particular element in a list is difficult and time consuming.
 A linked list will use more storage space than an array to store the same number of elements
(therefore each element in a list needs additional memory space for storing the address of the next
node).
11. List out the difference between Array and Linked list

Arrays linked list


1. Size of any array is fixed. Size of a list is variable.
2. It is necessary to specify the number It is not necessary to specify the in an
array number of, elements during declaration. Number of elements in during declaration.
3. Insertion and deletions are somewhat Insertions and deletions are carried in an
difficult out easily. Array.
4. It occupies less memory than a linked list It occupies more memory. for
the same number of elements.

12. Mention some of the application of linked list.


Some of the applications of linked lists are,
 Polynomial Manipulation
 Stacks
 Queues

13. Define LIST


Linear data structure, Where each node connected together via links –pointer ,but data are not stored
at contiguous memory locations

14. State the difference between stacks and linked lists.


The difference between stacks and linked lists is that insertions and deletions may occur anywhere in a linked
list, but only at the top of the stack.

15. Mention the advantages of representing stacks using linked lists than arrays.
 It is not necessary to specify the number of elements to be sorted in a stack during its declaration
 allocated dynamically at run time when an element is added to the stack).
 Insertions and deletions can be handled easily and efficiently.
 Linked list representation of stacks can grow and shrink in size

16. State the difference between queues and linked lists.


The difference between queues and linked lists is that insertions and deletions may occur anywhere in linked
list, but in queues insertions can be made only in the front end.

17. What are the steps to be involved while deleting a node in a singly linked list.
 Find the position P before which the node has to be deleted i.e., find previous(X,L).
 Change the link of the previous node to the link of the node to be deleted.
P->Next=P->Next->Next
18. What are the disadvantages of linear Queue? (CO2,K1)

C D E rear

front
In the above queue we have space but rear pointer points at end of the queue there fore we cannot
insert new element,which occurs memory wastage

19. What are the two operations available in Queue? (CO2,K1)


The basic operations associated with queues −
 enqueue() − add (store) an item to the queue.
 dequeue() − remove (access) an item from the queue.
Few more functions are
 peek() − Gets the element at the front of the queue without removing it.
 isempty() − Checks if the queue is empty.
20. What are the infix , postfix and prefix forms of the expression? (CO2,K1)
Infix notation: X + Y :Operators are written in-between their operands.
Ex:An expression such as A * ( B + C ) / D
Postfix notation (also known as "Reverse Polish notation"): X Y +: Operators are written after
their operands. Ex: A B C + * D /
Prefix notation (also known as "Polish notation"): + X Y: Operators are written before their
operands. The expressions given above are equivalent to / * A + B C D

21. Write the Algorithm for ENQUEUE operation


1. Check if the queue is full or not.
2. If the queue is full, then print overflow error and exit the program.
3. If the queue is not full, then increment the tail and add the element.

22. Write the Algorithm for DEQUEUE operation


1. Check if the queue is empty or not.
2. If the queue is empty, then print underflow error and exit the program.
3. If the queue is not empty, then print the element at the head and increment the head .

23. Convert into postfix and evaluate the following expression.

(a+b*c)/d
a=2 b=4 c=6 d=2
Post fix:
abc*+d/
Evaluation:
2 4 6 * +2/
=13

PART-B
1. With suitable examples explain the operations performed on singly linked list. (CO1,K2)
2. Discuss about the operations performed on doubly linked list with example. (CO1,K2)
3. Explain the operations performed on Circular Doubly linked list with example. (CO1,K2)
4. Write short notes i. array and structure (8)
ii. pointer and recursion function (8)
5. Discuss the operations for push and pop operation on a stack ADT using linked list.
6. Enumerate the operations of queue ADT using linked list.

UNIT IV-TREES
PART-A

1. Define a tree.
A tree is a non-linear data structure, which represents hierarchical relationship between individual data items.

2. Define the height of a Tree.


The height of a tree is the length of the longest path from the root to a leaf.In below tree h- indicate height.
3. Define a path in a tree.
A path in a tree is a sequence of distinct nodes in which successive nodes are connected by edges in the tree.
In above tree the path from root node 3 to node 4 is 3,6,5,4

4. Define terminal nodes in a tree.


A node that has no children is called as a terminal node. It is also referred as a leaf node. These nodes have
degree has zero.

5. Define non-terminal nodes in a tree.


All intermediate nodes that traverse the given tree from its root node to the terminal nodes are referred as a
non-terminal node.

6. Define a binary tree.


A binary tree is a tree in which every non-leaf node has atmost two children.

7. Define a full binary tree.


A full binary tree is a tree in which all leaves are on the same level and every non-leaf node has exactly two
children.

8. Define a complete binary tree.


A complete binary tree is a binary tree in which every level, except possibly the last, is completely filled, and
all nodes are as far left as possible.

9. Define a right-skewed binary tree.


A right-skewed binary tree is a tree, which has only right child nodes.
10. State the properties of a binary tree.
The properties of a binary tree includes,
 The maximum number of nodes on level n of a binary tree is 2n-1, where n≥1.
 The maximum number of nodes in a binary tree of height n is 2n-1,where n≥1.
 For any non-empty tree, nl=nd+1 where nl is the number of leaf nodes and nd is the number of nodes of
degree 2.

11. What are the different ways of representing a binary tree?


The different ways of representing a binary tree includes,
 Linear representation using arrays.
 Linked representation using pointers.

12. What is meant by binary tree traversal and list out the different binary tree traversal techniques
Traversing a binary tree, means moving through all the nodes in the binary tree, visiting each node in the tree
only once.

The different binary tree traversal techniques are,


 Preorder traversal
 Inorder traversal
 Postorder traversal

13. What are the tasks performed while traversing a binary tree?
The tasks performed while traversing a binary tree are,
 Visiting a node.
 Traverse the left subtree
 Traverse the right subtree.

14. What are the tasks performed during preorder traversal?


The tasks performed during preorder traversal,
 Process the root node
 Traverse the left subtree
 Traverse the right subtree.
15. What are the tasks performed during inorder traversal.
The tasks performed during inorder traversal,
 Traverse the left subtree.
 Process the root node.
 Traverse the right subtree.
16. What are the tasks performed during postorder traversal?
The tasks performed during postorder traversal,
 Traverse the left subtree
 Traverse the right subtree.
 Process the root node.

17. State the merits and demerits of linear representation of binary trees.
The merits of linear representation of binary trees includes
 Storage method is easy and can be easily implemented in arrays.
 It requires static memory allocation so it is easily implemented in all programming language.
The demerits of linear representation of binary trees includes,
 Insertions and deletions in a node, taker an excessive amount of processing time, due to data
movement up and down the array.

18. State the merits and demerits of linked representation of a binary tree.
The merits of linked representation of binary trees includes
 Insertions and deletions in a node, involves no data movement except the rearrangement of pointers,
hence less processing time.
The demerits of linked representation of binary trees includes,
 Given a node structure, it is difficult to determine its parent node.
 Memory spaces are wasted for storing null pointers for the nodes, which have one or no subtrees.
 It requires dynamic memory allocation, which is not possible in some programming languages.

19. Define a binary search tree.


A binary search tree is a special binary tree, which is either empty or if it should satisfy the following
characteristics.
 The values in any left subtree is less than the value of its parent node.
 The values in any right subtree is greater than the value of its parent node.
 The left and right subtrees of each node are again binary search trees.

20. What are the basic operations performed in a binary search tree.
The basic operations performed in a binary search tree are,
 Creation of a binary search tree
 Insertion of a node
 Deletion of a node.
 Searching a node
 View the contents of the binary search tree.

21. Define a min-heap.


The heap which satisfies the min-heap property, i.e., if for every node n except the root, has a value greater
than its parent is referred to as min heap.
22. Define max-heap.
The heap which satisfies the max-heap property, i.e., if for every node n except the root, has a value lesser
than its parent is referred to as max heap.

23. List out the heap property.


1. Structure property -It is a complete binary tree.
2. Heap property - For a "max heap", the property is that the value of each node is always less than or
equal to the value of its parent.

24.Write the Tree Traversals (Inorder, Preorder and Postorder) for a given tree.

(a) Inorder (Left, Root, Right) : 4 2 5 1 3


(b) Preorder (Root, Left, Right) : 1 2 4 5 3
(c) Postorder (Left, Right, Root) : 4 5 2 3 1

25. Terminologies of the tree


Root - In a tree data structure, the first node is called as Root Node. Every tree must have root node.
Edge- In a tree the connecting link between any two nodes is called as EDGE. In a tree with 'N' number of
nodes have maximum of 'N-1' number of edges
Parent node -can also be defined as "The node which has child / children"
Child node -node which has a link from its parent node is called as child node
Siblings- In a tree data structure, nodes which belong to same Parent are called as Sibling
Leaf- In a tree data structure, the node which does not have a child is called as LEAF/ terminal node
Internal node-In a tree data structure, the node which has atleast one child is called as internal node
Degree-In a tree data structure, the total number of children of a node is called as DEGREE of that Node
Level-In a tree data structure, the root node is said to be at Level 0 and the children of root node are at
Level 1 and the children of the nodes which are at Level 1 will be at Level 2 and so on.
PART – B
1. Explain three standard ways of traversing a binary tree T with a recursive algorithm.
2. Write an algorithm for inserting and deleting a node in a binary search tree (BST) with exam.
3. Enumerate the algorithm for AVL. Show the result of inserting 15,17,6,19,11,10,13,20,8,14,12 one at time
into an initially empty tree
4. Write the algorithm and transform the given expression to expression tree.

(ii) Compute infix expression, prefix expression and postfix expression.( CO3,K3)
5. Discuss in detail about the operation Threaded Binary Tree
6. Illusrate B Tree operations with their algorithms with Complexity analysis.
7. With example explain the B+ Tree operation write the algorithms and its analysis

UNIT V- SORTING AND HASHING


PART – A

1. Define Hashing.
Hashing is the transformation of string of characters into a usually shorter fixed length value or key that
represents the original string. Hashing is used to index and retrieve items in a database because it is faster to
find the item using the short hashed key than to find it using the original value.

2. What do you mean by hash table?


The hash table data structure is 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.

3. What do you mean by hash function?


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. A simple hash function is hash_key=key mod tablesize.

4. What do you mean by collision in hashing?


When an element is inserted, it hashes to the same value as an already inserted element, and then it
produces collision.

5. What do you mean by separate chaining?


Separate chaining is a collision resolution technique to keep the list of all elements that hash to the
same value Each linked list contains all the elements whose keys hash to the same index.

6. Write the advantage and disadvantages of separate chaining.


Advantage :
 More number of elements can be inserted as it uses linked lists.
Dis advantage:
 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.

9. What do you mean by open addressing?


Open addressing is a collision resolving strategy in which, if collision occurs alternative cells are
tried until an empty cell is found. hi(x)=(Hash(x)+F(i))mod Tablesize
10. What are the types of collision resolution strategies in open addressing?
 Linear probing
 Quadratic probing

11. What do you mean by Probing?


Probing is the process of getting next available hash table array cell.

12. What do you mean by linear probing and quadratic probing


Linear probing is an open addressing collision resolution strategy in which F is a linear function of i,
F(i)=i. hi(x)=(Hash(x)+F(i))mod Tablesize . i=1,2,3,4…..

Linear probing is an open addressing collision resolution strategy in which F is a linear function of i,
F(i)=I 2. hi(x)=(Hash(x)+F(i))mod Tablesize . i=1,2,3,4…..

13. List out various collision resolution techniques.


 Separate chaining
 Open Addressing
 Rehashing

14. Consider given numbers { 50, 700, 76, 85, 92, 73, 101 }and hash function h(X)=X(mod 7).Find
the hash address of each number using separate chaining.

15.Define sorting and its type


Sorting arranges data in a sequence which makes searching easier
1. Bubble Sort
2. Insertion Sort
3. Selection Sort
4. Quick Sort
5. Merge Sort
6. Heap Sort

16. Write algorithm for binary sort


Binary Search is applied on the sorted array or list. In search, we first compare the value with the
elements in the middle position of the array. If the value is matched, then we return the value. If the value is
less than the middle element, then it must lie in the lower half of the array and if it's greater than the element
then it must lie in the upper half of the array. We repeat this procedure until match is found.

17. Define Sorting


A Sorting Algorithm is used to rearrange a given array or list elements in ascending or descending
order. The comparison operator is used to decide the new order of element in the respective data structure.
18. What is Insertion Sort
Insertion sort is a simple sorting algorithm that works similar to the way you sort playing cards in your
hands. The array is virtually split into a sorted and an unsorted part. Values from the unsorted part are picked
and placed at the correct position in the sorted part.

19. How Selection Sort operate


The selection sort algorithm sorts an array by repeatedly finding the minimum element (considering
ascending order) from unsorted part and putting it at the beginning. The algorithm maintains two subarrays in
a given array.
1) The subarray which is already sorted.
2) Remaining subarray which is unsorted.
In every iteration of selection sort, the minimum element (considering ascending order) from the unsorted
subarray is picked and moved to the sorted subarray.

19. Write the steps involved in Quick Sort


Quick Sort is a Divide and Conquer algorithm. It picks an element as pivot and partitions the given array
around the picked pivot. There are many different versions of quick Sort that pick pivot in different ways.
1. Always pick first element as pivot.
2. Always pick last element as pivot (implemented below)
3. Pick a random element as pivot.
4. Pick median as pivot.

PART B

1. Briefly describe hashing techniques with its collision resolution strategies


2. Write an algorithm to sort ‘n’ number using heap sort. Show how the following numbers are sorted using
Heap sort 45, 28, 90, 1, 46, 39, 33, 87.
3. Describe in detail about insertion sort
4. With example enumerate the operation of selection sort
5. Discuss in detail about bubble sort
6. Illustrate the operation of Merge sort with explanation

You might also like