0% found this document useful (0 votes)
24 views9 pages

Marking 2022 - DSA

Uploaded by

mmhalith3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views9 pages

Marking 2022 - DSA

Uploaded by

mmhalith3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

[All Rights Reserved]

SRI LANKA INSTITUTE OF ADVANCED TECHNOLOGICAL EDUCATION


(Established in the Ministry of Higher Education, vide in Act No. 29 of 1995)

Higher National Diploma in Information Technology


Second Year, First Semester Examination – 2022
HNDIT3032 – Data Structure and Algorithms

Answer Sheet

Question 01 (Total Marks 20)

i) What is the Data Structure (03 Marks)

An organization and representation of data

ii) What is ADT? Give two examples of ADT (2+2 = 04 Marks)

List, Array, Stack, Queue

iii) Write a Java method to check if User input string is a palindrome or Not. using a
loop. (07 Marks)

Give two more marks to the coding written by the student.

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)

F(n)<=n3 +4n3 +5n3


F(n)<=10n3
F(n)<=c*g(n3 ) if the n is very large
Big O (n3)

Question 02 (Total Marks 25)

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)

ii.) Compare and Contrast LINKED List Vs an Array (04 Marks)

HNDIT3032 – Data Structure and Algorithms


Pa ge - 2
iii.) Write Four Operation In LINKED LIST (04 Marks)

Appending a Node to the List

Traversing the List

Inserting a Node

Deleting a Node

iv.) Write a pseudocode appending Node in LINKED LIST (04 Marks)


Create a new node.
Store data in the new node.
If there are no nodes in the list
Make the new node the first node.
Else
Traverse the List to Find the last node.
Add the new node to the end of the list.
End If.

v.) class LinkedList {


Node head; // head of list

/* Linked list Node*/


static class Node {
int data;
Node next;

// Constructor to create a new node


// Next is by default initialized
// as null
Node(int d) { data = d; }
}
} (05 Marks)

HNDIT3032 – Data Structure and Algorithms


Pa ge - 3
Question 03 (Total Marks 20)

i.) Consider following Java coding in Queue implementation Java Program


public class ArrayQuequ {
public int size;
int front,rear;
public int que[]=new int[size];
public ArrayQuequ(int size, int[] arr) {
this.size = size;
this.que = arr;
front=-1;
rear=-1;}
public int getSize() {
return size;}
public int[] getQue() {
return que;}
a.) Write a reason why take two variable rear and front implementing Queue data
structure. (02 Marks)
Queue is First in First Out. Insert and Delete operation need to use two variables
b.) Write Java Method to represent enqueue operation in a queue (04 Marks)
public void enqueue(int n)
{
if(isFull()==true) {
System.out.println("Queuse is Full");
}
else{
rear++;
que[rear]=n;
}}
c.) Briefly explain why circular queue representation is introduced. (05 Marks)
The circular queue solves the major limitation of the normal queue. In a
normal queue, after a bit of insertion and deletion, there will be non-usable
empty space. Here, indexes 0 and 1 can only be used after resetting the
queue (deletion of all elements). This reduces the actual size of the queue.
ii) What is STACK? Discuss the LIFO behavior of a STACK (03 Marks)
A stack is a logical concept that consists of a set of similar elements. The term
is often used in programming and memory organization in computers.
Programming stacks are based on the principle of last in first out (LIFO), a
commonly used type of data abstract that consists of two major operations,
push and pop. The push operation adds an element to the bottom of stack
while the pop operation removes an element from the top position.

iii) Draw Graphically Following operation in STACK, its size is 4 (09 Marks)
a.)Empty STACK

HNDIT3032 – Data Structure and Algorithms


Pa ge - 4
Top=-1

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);

HNDIT3032 – Data Structure and Algorithms


Pa ge - 5
100
90
12
10
Top=3

j.)z=isFull();

100
90
12
10
Top=3
Z=true

Question 04 (Total Marks 20)

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.

HNDIT3032 – Data Structure and Algorithms


Pa ge - 6
I,J,E,G,H
d.) Write Down Path From A to J (02 Marks)
ABFJ
ii.) Define the Binary Search Tree(BST) (04 Marks)

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.

iii.) Insert given Number Set in to BST (23,33,45,30,10,55,15,8,42,17) (05 Marks)


Give five Marks suitable answer
iv.) What is Selection short (02 Marks)
selection sort is a simple and efficient sorting algorithm that works by repeatedly
selecting the smallest (or largest) element from the unsorted portion of the list and
moving it to the sorted portion of the list.

HNDIT3032 – Data Structure and Algorithms


Pa ge - 7
v.) Sort the numbers 6, 7,72, 4, 32, 65, 9, 56 using bubble sort (05 Marks)

Question 05 (Total Marks 25)

i.) What is search algorithm? (06 Marks)

A search algorithm is an algorithm for finding an item among a collection of items.

Sequential Search: In this, the list or array is traversed sequentially and every
element is checked.

Binary Search is defined as a searching algorithm used in a sorted array


by repeatedly dividing the search interval in half

ii.) Write a java code to Sequential/Linear Search (05 Marks)

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)

public class Sequsearch {


static int sequentialSearch(int a[], int n, int t)
{
int i;
for (i = 0; i < n; i++)

HNDIT3032 – Data Structure and Algorithms


Pa ge - 8
if (a[i]==t) return i;
return (-1);
}
public static void main(String a[])
{
int num[] = {4, 65, 2, -31, 0, 99, 2, 83, 782, 1};
int n=num.length;
int t=99;
if(sequentialSearch(num,n,t)==-1)
{
System.out.println("Can not Fine Value in Array");
}
else
{
System.out.println("Fine Value in Array
"+sequentialSearch(num,n,t));
}}}

iv.) Discuss Efficiency of Sequential/Linear Search and Binary search algorithm

(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.’

HNDIT3032 – Data Structure and Algorithms


Pa ge - 9

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy