DSA - TT2 - Practice Questions
DSA - TT2 - Practice Questions
1) Write an algorithm/pseudocode to insert a node at the beginning and end of a doubly linked
list.
2) Write an algorithm/pseudocode to insert a node at the beginning and end of a circular linked
list.
3) Write an algorithm/pseudocode to delete a node at the end and from the beginning of a doubly
linked list.
4) Write an algorithm/pseudocode to delete a node at the end and from the beginning of a
circular linked list.
5) Write an algorithm/pseudocode to count the number of nodes in a Singly Linked List?
6) Write algorithms to perform the following operations on a doubly linked list. (i) Insert a node
with data ‘y’ after a node whose data is ‘x’. (ii) Delete a node whose data is ‘s’ . (iii) Insert a
node with data ‘a’ as the 1st node of the list.
7) How a stack and queue can be implemented using linked list?
8) How a singly linked list can be used to represent a polynomial 4x 4 +4x2 +3x+12? Write an
algorithm to add two polynomials using linked list.
Sorting and Searching (Module 5)
1) Write an algorithm to perform bubble sort on a collection of ‘n’ numbers
2) Write algorithm for (i) Insertion sort (ii) Bubble sort (b) Illustrate the insertion sort algorithm
and bubble sort algorithm on input [30,20,10,60,70,40]
3) Design an algorithm/ pseudocode for selection sort. Illustrate the working of selection sort on
the following array with 7 elements : 30,45,25,32,55,60,49
4) Explain Merge Sort algorithm/pseudocode with the help of an example? Mention the best
case and worst case time complexity of Merge sort algorithm?
7) Write an algorithm/pseudocode to sort elements using Heap sort technique? Illustrate the
working of Heap sort algorithm on the following input : 35,15,0,1,60
8) Construct max heap for the following elements: 40, 80 , 30 , 20 ,10 ,40 ,30 ,60 ,100 ,70 ,160.
Explain the technique.
9) Trace the steps of recursive merge sort algorithm to sort the following elements: 12, 25, 5,9,
1, 84, 63, 7, 15, 4, 3.
10) Arrange the following list of elements in descending order using heap sort: 9, 3, 5, 27, 4, 67,
18, 31. Clearly show the sorting process at each step.
12) Write a program to sort the elements using radix sort. Also discuss its time and complexity.
15) A certain sorting technique was applied on the following data set.
45,1,63,36,54,90
After two passes, the rearrangement of the data set is given as below:
1,45,63,36,54,90
Identify the sorting algorithm(Bubble/Insertion/Selection) which was applied with
justification.
16) Draw the binary tree whose sequential(array)l representation is given below.
17)
Hashing questions
18) A hash table contains 7 buckets and uses linear probing to solve collision. The key values are
integers and the hash function used is key%7. Draw the table that results after inserting in the
given order the following values: 16,8,4,13,29,11,22.
20) Given the values {2341, 4234, 2839, 430, 22, 397, 3920} a hash table of size 7 and a hash
function h(x) = x mod 7, show the resulting table after inserting the values in the given order
with each of the following collision strategies. (i) separate chaining
(ii) linear probing (iii) double hashing with second hash function h1(x) = (2x – 1) mod 7
21) Define hashing. What are the properties of a good hash function?
22) Define collision. What is linear probing? The following keys 10, 16, 11, 1, 3, 4,23 and 15 are
inserted into an initially empty hash table of length 10 using open addressing with hash
function h(k) = k mod 10 and linear probing. What is the resultant hash table?
25) Consider a hash table with size=10. Using linear and quadratic probing (take c 1=1,c2=2),
insert the keys 27,72,63,42,36,18,29 and 101 into the table.
26) Consider a hash table with size=11. Using double hashing, insert the keys
27,72,63,42,36,18,29 and 101 into the table. Take h1=k mod 10 and h2=k mod 8
27) What is Hashing? Hash the following data in a table of size 10 using linear probing and
quadratic probing. Also find the number of collisions in both the cases
36, 82, 84, 77, 53, 87, 23, 75, 10, 44
28) What you mean by Open Addressing and Closed Addressing?
29) What do you mean by space complexity and time complexity of an algorithm? Write an
algorithm/pseudo code for binary search and mention the best case and worst case time
complexity of Binary Search algorithm?
30) Compare Binary Search and Linear Search. b) Write an algorithm to perform binary
search on a given set of ‘n’ numbers. Using the algorithm search for the element 23 in the set
[12, 23, 34, 44, 48, 53, 87, 99]