Marking 2022 - DSA
Marking 2022 - DSA
Answer Sheet
iii) Write a Java method to check if User input string is a palindrome or Not. using a
loop. (07 Marks)
iv) Write a Java method to find Maximum Number in 10 unsigned integers an Array
(07 Marks)
Give One more mark to the coding written by the student.
v) Find the Big O of the given equation F(n)=n3 +4n2 +5 (04 Marks)
i.) Consider following JAVA code and Write a Java program to add two metrics
(metricsA , metricsB ) and display it as a Metrics ( metricsC )
int metricsA[][]={{10,12,13},{11,15,16},{20,21,23}};
int metricsB[][]= {{14,9,8},{1,2,3},{60,71,73}}; (08 Marks)
Inserting a Node
Deleting a Node
iii) Draw Graphically Following operation in STACK, its size is 4 (09 Marks)
a.)Empty STACK
b.)x=isEmpty();
Top=-1
X=true
c.)push(10);
10
Top=0
d.)Push(12);
12
10
Top=1
e.)push(15);
15
12
10
Top=2
f)y=pop();
15
12
10
Top=1
Y=15
g.)push(90);
90
12
10
Top=2
h.)push(100);
j.)z=isFull();
100
90
12
10
Top=3
Z=true
i.) a.) Define the parent node. Give an example. (02 Marks)
The node which is a predecessor of another node is known as a parent
node. B, C, D
b.) What is Height of a Tree (02 Marks)
c.) Define the leaf nodes. Give two examples. (03 Marks)
A node that does not have any child node is called a leaf node.
Binary Search Tree is a node-based binary tree data structure which has
the following properties:
• The left subtree of a node contains only nodes with keys lesser than the
node’s key.
• The right subtree of a node contains only nodes with keys greater than
the node’s key.
• The left and right subtree each must also be a binary search tree.
Sequential Search: In this, the list or array is traversed sequentially and every
element is checked.
int sequentialSearch(a[],n,t) //It returns the location of the target t in the array a[] with
n elements.
for i = 0 to n-1
if (a[i]=t)
return i;
next i
return -1;
iii.) Write a Java program to search 99 in given numbers in an Array using Sequential/Linear
Search
int num[] = {4, 65, 2, -31, 0, 99, 2, 83, 782, 1}; (05 Marks)
(04Marks)
v.) “Selection sort algorithm is better than bubble sort algorithm”. Do you agree?
Justify your answer (05 Marks)
Yes
Space
Sorting Algorithm Time Complexity Complexity
Average Worst
Best Case Case Case Worst Case
Bubble Sort O(N) O(N 2 ) O(N 2 ) O(1)
Selection sort algorithm O(N 2 ) O(N 2 ) O(N 2 ) O(1)
Bubble sort algorithm is considered to be the most simple and inefficient algorithm, but
selection sort algorithm is efficient as compared to bubble sort. Bubble sort also consumes
additional space for storing temporary variable and needs more swaps.’