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

Cs 20001 (Spring End April 25) Etc

The document is an examination paper for the 4th Semester B.Tech (ETC) students, covering topics such as Big O notation, GCD computation using recursion, memory addressing in arrays, tree properties, and various sorting and searching algorithms. It includes theoretical questions, proofs, and practical coding tasks. The paper tests knowledge on data structures and algorithms, including stacks, queues, and graph representations.

Uploaded by

2304062
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)
12 views9 pages

Cs 20001 (Spring End April 25) Etc

The document is an examination paper for the 4th Semester B.Tech (ETC) students, covering topics such as Big O notation, GCD computation using recursion, memory addressing in arrays, tree properties, and various sorting and searching algorithms. It includes theoretical questions, proofs, and practical coding tasks. The paper tests knowledge on data structures and algorithms, including stacks, queues, and graph representations.

Uploaded by

2304062
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

SPRING END SEMESTER EXAMINATION-2025

4th Semester, B.Tech (ETC)


SUBJECT: CDSA
CODE: CS 20001

1(a)
(i) T (n)=4n2 + 3n log (n), express T (n) in Big (O) notation.

The function T(n) = 4n2 + 3n log (n) in Big O notation is O(n2). The dominant term in the expression is 4n2,
and we drop the lower-order terms and constant coefficients when expressing it in Big O

If T(n)≤c.f(n) for all n≥n0, for some constants c>0 and n0,
then we write:

T(n)=O(f(n))

We want to find the simplest possible f(n) such that this condition holds.

Asymptotic growth of common functions (from slower to faster):

log n<n<nlogn<n2<n3<2n<n!

n2 grows faster than n log n

We want to find a constant c such that:

T(n)=4n2 + 3n log (n)≤ c.n2 for large enough n


(We chose 5 as a safe upper bound)

Final Big-O Expression

T(n)=4n2 + 3n log (n)≤5n2 for n≥2⇒T(n)=O(n2)

(ii) Write down a C function to find out the GCD of two nos. using recursive technique.

#include <stdio.h>

// Recursive function to compute GCD

int gcd (int a, int b) {

if (b == 0)

return a;

else

return gcd (b, a % b); // Recursive call

}
int main() {

int num1, num2;

printf("Enter two integers: ");

scanf("%d %d", &num1, &num2);

printf("GCD of %d and %d is %d\n", num1, num2, gcd(num1, num2));

return 0;

1(b)

(i)

(ii)

Row-Major Order: The address of a location in Row Major System is calculated as:

Address of A [i][j] = BA + w * [ n * ( i – Lr ) + ( j – Lc ) ]

Column-Major Order: The address of a location in Column Major System is

calculated as:

Address of A [i][j] = BA + w * [( i – Lr ) + m * ( j – Lc )]

· Row-major address of A[4,2] = 3556

· Column-major address of A[4,2] = 3580

2(a)
Ans: 6,1

· Push 8 → Stack: [8]

· Push 2 → Stack: [8, 2]

· Push 3 → Stack: [8, 2, 3]

· Operator ^ → Pop 3 and 2 → 2^3 = 8 → Push 8


→ Stack: [8, 8]

· Operator / → Pop 8 and 8 → 8 / 8 = 1 → Push 1


→ Stack: [1]

· Push 2 → Stack: [1, 2]

· Push 3 → Stack: [1, 2, 3]

· Operator * → Pop 3 and 2 → 2 * 3 = 6 → Push 6

Final Answer: 6 and 1 (top two elements after first *)


Top: 6
Second: 1

2(b)

Final expression: A B * C D + - E F + - F H I ^ / +

3(a)

Pre-order: G, B, Q, A, C, K, F, P, D, E, R, H
In-order: Q, B, K, C, F, A, G, P, E, D, H, R

3(b)
expression trees corresponding to the following:
A = 10/4 + 2*(5+1)
E= (2a +5b) (x-7y)4

4(a)
(i) Prove the hypothesis that “A tree having ‘m’ nodes has exactly
(m–1) edges or branches”.

Proof: Let m be the number of vertices in a tree (T). If m=1, then the number of edges=0. If m=2 then the
number of edges=1. If 3=3 then the number of edges=2. Hence, the statement (or result) is true for m=1, 2, 3.

Let the statement be true for m=n. Now we want to prove that it is true for m=n+1.

Let e be the edge connecting vertices say Vi and Vj. Since G is a tree, then there exists only one path between
vertices Vi and Vj. Hence if we delete edge e it will be disconnected graph into two components G1 and G2 say.

These components have less than n+1 vertices and there is no circuit and hence each component G1 and G2
have n1 and n2 vertices.

Now, the total no. of edges = (n1-1) + (n2-1) +1= (n1+n2)-1= n+1-1

=n

Hence for m=n+1 vertices there are n edges in a tree (T). By the mathematical induction the graph exactly has
m-1 edges.

(ii) Find out the maximum and minimum height of a binary tree, where n is the number of nodes in the
binary tree.
Maximum height: n-1
For example, the left skewed binary tree shown with 6 nodes has a height of 6-1 = 5
Minimum height:
binary tree of height “h”, maximum number of nodes will be

20 + 21 + …. 2h = 2h+1 – 1

n≤2h+1 – 1

h ≥ log2(n+1) - 1

=>Height of the binary with maximum “n” nodes => h = ⌈ log(n+1) ⌉ - 1

4(b)
For Binary search tree: in-order traversal will be ascending order.
Hence, in-order traversal: 10, 15, 20, 23, 25, 30, 35, 39, 42
Given, pre-order traversal: 30, 20, 10, 15, 25, 23, 39, 35, 42
So post order traversal will be: 15, 10, 23, 25, 20, 35, 42, 39, 30

5(a)
STACK: A Stack is a linear data structure that follows a particular order in which the
operations are performed. The order may be LIFO (Last In First Out) or FILO (First In Last
Out). LIFO implies that the element that is inserted last, comes out first and FILO implies that the
element that is inserted first, comes out last.
Algorithms for PUSH and POP

5(b)
Advantages of circular queue:

 It avoids wasted space by reusing the front area when the queue is full, unlike a linear
queue that leaves gaps after dequeuing.
 It allows for continuous, cyclic processing of data without needing to reset or reorganize
the queue.
 In a circular queue, both enqueue and dequeue operations can happen without leaving
unused memory, unlike in a linear queue where memory may be wasted at the front.
 Both enqueue and dequeue operations are still O (1) but without the need to shift
elements, as might happen in a linear queue.

Dequeue: It is the process by which an element is removed from the queue. Its operation is
shown below.
Limitations of Linked List
 Traversal: In a linked list, traversal is more time-consuming as compared to an array.
Direct access to an element is not possible in a linked list as in an array by index. For
example, for accessing a node at position n, one has to traverse all the nodes before it.
 Reverse Traversing: In a singly linked list reverse traversing is not possible, but in the
case of a doubly linked list, it can be possible as it contains a pointer to the previously
connected nodes with each node. For performing this extra memory is required for the back
pointer hence, there is a wastage of memory.
 Random Access: Random access is not possible in a linked list due to its dynamic memory
allocation.
 Memory usage: More memory is required in the linked list as compared to an array.
Because in a linked list, a pointer is also required to store the address of the next element
and it requires extra memory for itself.

6(a)
Complete Graph: a graph in which every vertex is directly connected to every other vertex.

6(b)
(i) Directed graph:

Adjacency matrix: In graph theory, an adjacency matrix is a square matrix that


represents a graph, where each entry indicates whether two vertices are connected
by an edge.
Example:
ii) Adjacency matrix of given graph

7(a)
Bubble sort Selection sort

7(b)
Binary search to find element 23
Given array: 12, 23, 19, 27, 56, 40, 90, 5, 21
Index 0 1 2 3 4 5 6 7 8
Bottom = 0, Top = 8, Mid = 4
Since, array [4] > Key element 23, hence search will be continued in left array.
Hence, for this iteration, Bottom = 0, Top = 3, Mid = 1
Since, array[1] = Key element 23, hence element is found and it is at index 1 of the array.
Binary search to find element 32
Bottom = 0, Top = 8, Mid = 4
Since, array [4] > Key element 32, hence search will be continued in left array.
Hence, for this iteration, Bottom = 0, Top = 3, Mid = 1
Since, array[1] < Key element 32, hence search will be continued in right sub array.
Hence, for this iteration, Bottom =2, Top = 3, Mid = 2,
Since, array[2] ≠ 32, hence element is not found in the array.
Binary search to find element 56
Bottom = 0, Top = 8, Mid = 4
Since, array [4] = Key element 56, hence element is found at index 4in the array.

----------------------------------------------End of the solution----------------------------------------------

You might also like