Module 2 _Data Structure (2, 5, 10 respectively)
Module 2 _Data Structure (2, 5, 10 respectively)
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
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)