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

Module 2 _Data Structure (2, 5, 10 respectively)

Uploaded by

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

Module 2 _Data Structure (2, 5, 10 respectively)

Uploaded by

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

1 Define a binary search tree (BST) and explain its key properties.

Explain the difference between a binary tree and a binary search tree (BST).
2 Provide an example of each.
Discuss the advantages and disadvantages of a singly linked list compared
3 to an array. Provide specific examples for each.
4 Explain the concept of enqueue and dequeue operations in a queue.
#define f(a,b) a+b
#define g(a,b)a*b
main()
{
int m;
m=2*f(3,g(4,5));
printf("\n m is %d", m);
}
5 What is the value of m?
6 How many different types of trees that can be realised are with six nodes?
Consider the following C declaration
struct {
short s [5]
union{
float y;
long z;
}u;
}t;
7 What is the memory requirement for variable t?
Find the maximum number of binary trees that can be formed with three
8 unlabeled nodes.
Suppose the numbers 7, 5, 1, 8, 3, 6, 0, 9, 4, 2 are inserted in that order into an
initially empty binary search tree. The binary search tree uses
the usual ordering on natural numbers. What is the inorder traversal sequence of
the resultant
9 tree?
Find the number of pointers affected for an insertion operation in a doubly
10 linked list.
The function of the given Linked List with the first node as the head is:-
void funx1(struct node* head)
{
if (head == NULL)
return;
funx1 (head -> next) ;
printf (" %d ", head -> data ) ;
11 }
What is the output?
Which algorithms among Insertion Sort, Quick Sort, Heap Sort, and Merge Sort,
can be used to sort a random linked list with minimum time complexity? Explain
12 your answer.
How many stacks are needed to implement a queue? Consider the situation
13 where no other data structure like arrays, linked list is available to you.
Predict the output of:
void main() {
float x=1.1; double y= 1.1;
if(x==y)
printf("I see You");
else
14 printf("I hate You"); }
How many 32K × 1 RAM chips are needed to provide a memory capacity of 256
15 K bytes?
16 Which Data Structure is useful to find Depth First Search on a given graph?
Consider a weighted complete graph G on the vertex set {v1, v2, ..vn} such that
the weight of the edge (vi, vj) is 2|i−j|. Calculate the weight of a minimum
17 spanning tree of G.
The following sequence of operation is performed on a stack:
PUSH(10), PUSH(20), POP, PUSH(10),
PUSH(20), POP, POP, POP, PUSH(20), POP.
18 Find the sequence of values popped out.
Suppose the numbers 7, 5, 1, 8, 3, 6, 0, 9, 4, 2 are inserted in that order into an
initially empty binary search tree. The binary search tree uses
the usual ordering on natural numbers. Find the inorder traversal sequence of the
resultant
19 tree?
global int i = 100, j = 5;
void P(x) {
int i = 10;
print(x + 10);
i = 200;
j = 20;
print (x);
}
main() {P(i + j);}
20 What will be the values printed by the above program.
What are the advantages of using shared, dynamically linked libraries as opposed
21 to using statically linked libraries?
22 int f(int n)
{
static int i = 1 ;
if (n >= 5) return n;
n = n+i;
i++;
return f(n);
}
What will be the value returned by f(1).
What does the following program print?
#include <stdio.h>
void f (int *p, int * g) {
p = q;
*p = 2;
}
int i = 0, j =1;
int main ( ){
f(&i, & j);
print f ("%d %d ", i, j );
return 0;
23 }
Consider the following recursive C function that takes two
arguments:
unsigned int foo (unsigned int n, unsigned int r) {
if (n>0)
return ((n% r) + foo (n/r, r) ); else
return 0;
}
What is the return value of the function foo when
24 it is called foo(345, 10)?
What is printed by the following C program?
int f(int x, int *py, int **ppz) {
int y, z;
**ppz + = 1; z = **ppz;
*py + = 2; y = *py;
x + = 3;
return x + y + z:
}
void main() {
int c, *b, **a;
c = 4; b = &c; a = &b;
print f("%d", f(c, b, a));
25 }
Let T(n) be the number of different binary
search trees on n distinct elements. Then

Analyze the value of x ?


1
Find the postfix expression for the infix expression
2 A + B * (C + D)/E + F * G.
Postorder traversal of a given binary search tree T
produces the following sequence of keys
10, 9, 23, 22, 27, 25, 15, 50, 95, 60, 40, 2. Find the
3 inorder traversal of the tree T?
The following postfix expression with single-digit
operands is evaluated using a stack:
823∧ /23*+51*−
Note that ∧ is the exponentiation operator. Find
the top two elements of the stack after the first *
4 is evaluated.
Analyze the value printed by the following C
program?
#include <stdio.h>
int f(int * a, int n)
{
if (n<= 0)return 0;
else if(*a% 2= = 0)
return * a + f(a
+1,n - 1);
else return * a -
f(a + 1, n - 1);
}
int main( )
{
int a[ ] = {12, 7,
13, 4, 11, 6};
printf("%d",f(a,6));
return 0;
5 }
Analyze the value printed by the following C
program?
# include <stdio.h>
int fun(int n, int * f_p) {
int t, f;
6 if (n <= 1) {
* f_p =1;
return 1;
}
t = fun (n - 1, f_p);
f = t+ * f_p;
* f_p = t;
return f;
}
int main() {
int x = 15;
printf (" % d\ n", fun(5, & x));
return 0;
}
Consider the following C program that attempts
to locate an element x in an array Y[ ] using binary
search. The program is erroneous.
1. f(int Y[10], int x) {
2. int u, j, k;
3. i = 0; j = 9;
4. do {
5. k = (i + j) / 2;
6. if (Y[k] < x) i = k;
else j = k;
7. } while ((Y[k]! = x) &&
(i < j));
8. if (Y [k] == x) print f ("x is in
the array");
9. else print f ("x is not in the
array");
10. }
Analyze where the correction needed in the
7 program to make it work properly.
The preorder traversal of a binary search tree is
15, 10, 12, 11, 20, 18, 16, 19. Evaluate post-order
8 traversal.
9 Write an algorithm to reverse a singly linked list
Write an algorithm to delete an element from a
10 singly linked list if the item available in the list.
Write an algorithm to sort a singly linked list in
descending order. Assume numbers in the list are
11 random.
Suppose a circular queue of capacity (n – 1)
12 elements is implemented with an array of n
elements. Assume that the insertion and deletion
operation are carried out using REAR and FRONT
as array index variables, respectively. Initially,
REAR = FRONT = 0. Write down the algorithm
to detect whether the queue is full and queue
empty.
Write C function takes a simply linked list as input
argument. It modifies the list by moving the last
element to the front of the list and returns the
13 modified list.
Write C function to compute the height of a binary
14 tree rooted at the tree pointer root.
Write C function for enqueue and dequeue
15 operations on queues.
A priority queue is implemented as a max-heap. Initially, it has five elements. The
level-order traversal of the heap is given below:
10, 8, 5, 3, 2. Two new elements `1’ and `7’ are inserted in the heap in that order.
Evaluate the level-order traversal of the heap after the insertion of the elements.
1
The C function takes a simply linked
list as input argument. It modifies the list by
moving the last element to the front of the list
and returns the modified list. Implement the above function.
2
Consider two binary operators ” and `↓’ with the precedence of operator ↓ being
lower than that of the operator . Operator is right associative while
3 operator ↓ is left associative. Evaluate the parse tree for the expression (7↓343↓2).
Consider the following recursive C function that takes two arguments:
unsigned int foo (unsigned int n,
unsigned int r) {
if (n>0) return ((n% r) + foo (n/r, r) );
else return 0;
}
Evaluate the return values of the function foo when it is called foo(345, 10) and
4 foo(513, 2).
Calculate the minimum and maximum number of element comparisons involved in
5 2 way merge sort assuming n is power of 2.
Evaluate how many nodes (apart from s) does the Depth First Search algorithm
discover before discovering t when starting from s.

6
Create an AVL tree by the following elements in Lexicographic order: Jan, Feb,
Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov & Dec. Show balance factors after
7 insertion of each element.
Consider a sequence a of elements a0 = 1, a1 = 5, a2 = 7, a3 = 8, a4 = 9, and a5 = 2.
The following operations are performed on a stack S and a queue Q, both of which
are initially empty.
I: push the elements of a from a0 to a5 in that order into S.
II: enqueue the elements of a from a0 to a5 in that order into Q. III: pop an element
8 from S.
IV: dequeue an element from Q. V: pop an element from S.
VI: dequeue an element from Q.
VII: dequeue an element from Q and push the same element into S. VIII: Repeat
operation VII three times.
IX: pop an element from S. X: pop an element from S.
Show the stack and the queue at each intermediate step.

(a) Consider a binary search tree (BST) containing the following elements: {20, 10,
30, 5, 15, 25, 35}. Draw the BST after inserting all the elements in the given order.
Then, explain the process of finding the minimum and maximum elements in a
BST. (5 marks)

(b) What are AVL trees, and how do they differ from regular binary search trees?
Discuss the rotation operations (left rotation, right rotation, left-right rotation, right-
left rotation) used in AVL trees to maintain balance. Explain how these rotations
help in maintaining the balance property of AVL trees. (5 marks)

9
a) Explain the difference between a min-heap and a max-heap. How are these
structures implemented in an array, and what are the properties that must be
maintained to ensure the integrity of these heaps? (5 marks)

b) A binary min-heap is used to efficiently implement a priority queue. Describe


how the operations of insertion and deletion of the minimum element are
performed in a binary min-heap. Provide the time complexities of these operations.
10 (5 marks)

You might also like