Upload
mahesh
View
216
Download
0
Embed Size (px)
Citation preview
7/24/2019 Endsem Dsa 2014
1/4
MIS Number
COLLEGE OF ENGINEERING, PUNE(An Autonomous Institute of Govt. of Maharashtra)
En !emester E"amination # Novem$er, %&'
( C %&* ) +ata !trutures
C-ass / .0. 1.eh (Com2uter En3ineerin3 4Information ehno-o35)
0ear / %&'/'* !emester / III
+uration / 6 7ours Ma". Mar8s / 9&Instructions:
1. All questions are compulsory.
2. This is an open book test. You can read your textbooks/notes, but exchane is not
allo!ed.
3. Some questions may not ha"e de#inite ans!ers.
4. $se the i"en type de#initions and #unction prototypes #or !ritin your ans!ers.
5. You can make assumptions i# required, but you should state them.
6. %ode must be indented, commented, and !ritten in ANSI %. You can !rite the code !ith
a bold pencil.
7. You can explain your ans!er in Marathi/&indi.:' A 'ra! diaram o# the data structure created by #ollo!in code(
int main() {struct test {
struct data {char a[3];int i;
}b, *bp;
float f;}p, *pp;pp = &p;pp->bp = &(p.b);p.b.i = 30;p.b.a[2] = 'x';
}
%
1 )or a binary search tree o# inteers, !rite a #unction !hich computes the sum*total o#
"alues o# all nodes in the tree. $se the #ollo!in type de#inition and #unction
prototype.
int sumtotal(tree t);typedef struct node {int val;
struct node *left, *right;}node;typedef struct node *tree;
%
C Mention all bus/limitations about the code i"en belo!.#define lim 128int f() { int a[lim]; int i = 0;
while(a[i] < 20 || i < lim) printf(%d , a[i++]);
%
7/24/2019 Endsem Dsa 2014
2/4
:' + -rite a proram, !hich opens a #ile and counts the number o# occurrences o# a
particular character in it. oth the #ilename and the character are i"en as command
line aruments.
%
E -rite a #unction !hich replaces e"ery instance o# a character old !ith another
charcter ne! in a i"en strin str and returns number o# replacements done.int replacechar(char *str, char old, char new);For example: if str="somethings", old='s' and new='t' then str becomes 'tomethingt'
and function returns 2.
%
F 'eri"e the equation #or time taken by #ollo!in code.int f(int a, int b) { int m; for(i = 0; i < a; i ++)
for(j = 0; j < b; j * = 2)m = i + j;
}
%
G Sho! the contents o# the array a#ter each iteration o# selection sort #or #ollo!in data13 6 18 5 12
%
:% A $sin the type de#inition
typedef struct node { float f;struct node *next;
}node;typedef struct node *ll;-rite a recursi"e #unction to create a copy o# a sinly linked N$00 terminated list.ll copy(ll l);
6
1 1econstruct the binary tree 2dra! the diaram3, #or !hich the inorder and preorder
tra"ersals are i"en belo! and !rite the postorder tra"ersal.inorder: a e g m n o
preorder: m e a g n o
6
C -rite code #or store #unction o# a hashin scheme !hich uses chainin #or collisionresolution. The data to be stored in hash table is #ollo!in structure(struct account { float rate; int number;};The search key is rate. You may add appropriate code to the type de#inition.
6
+ -rite an implementation o# a stack usin an array o# si4e +5. -hen the array
becomes #ull, the stack uses a #ile to !rite the data, so the stack is ne"er #ull.
6
E -rite the itoa#unction !hich con"erts an inteer into its strin representation andreturns the strin.char *itoa(int x);
6
6/
7/24/2019 Endsem Dsa 2014
3/4
:% F 7i"en #ollo!in type de#initions #or a sparse matrix, and i"en that entries are stored
in the array 8arr8 in unsortedorder, !rite a #unction to add t!o sparse matrices and
return the resultant sparse matrix. 9ther "ariables ha"e same meanin as discussed in
class.typedef struct elem {
int r, c, v;
}elem;
typedef struct spm {
elem arr[128];// Note: Entries are not in sorted order
int nrow, ncol, nelem;
}spm;
spm *spmadd(spm *a, spm *b);
6
G )ind out the time #ollo!in code takes in the !orst case.char *substr (char *a, char *b) { char *p = a, *q = b; while(*p != '\0' && *q != '\0') { if(*p == *q) { p++;
q++; } else { if(q == b) p++; else { p = p - (q- b) + 1; q = b; } } }
if(*q == '\0') return p - (q - b) - a; else return -1;}
6
:6 A 'esin data structure #or a spread sheet. :ust dra! a diaram and !rite the type
de#initions in %.
Spread sheet is a program which allows the users to store (assume text data in cellsof a sheet. !onsider the following operations for the design: ntering data in a cell,
editing data in a cell, sorting all or selected columns on a particular column,
inserting and deleting a column or row. #opular examples of spread sheets are$ibreoffice !alc or %icrosoft xcel. &ou are expected to design data structure onl
for the storing the data and pa no attention to the graphical interface.
*
;/
7/24/2019 Endsem Dsa 2014
4/4
:6 1 -rite a #unction !hich cuts a doubly circular linked list in the middle. A#ter split the
list remains as the #irst hal#, and the #unction returns the second part o# the linked list
as another doubly circular linked list.
.g. if the list was )* 2* +* * -* * / , then after the function is called the listremains as )* 2* +*/ and the list * -* */ is returned b the function. For 0dd
1o. of data elements, the bigger part remains in the original list.
typedef struct node {int val;
struct node *prev, *next;}node;typedef struct dcll { node *head, *tail;}dcll;dcll cutmiddle(dcll *l);
*
C You ha"e been i"en an array o# inteers. The si4e is not kno!n, so consider the si4e
to be practically unlimited2 !hich means do not bother about sementation #ault dueto array index "iolations3. The array is sorted in ascendin order. -rite code #or an
efficient#unction !hich #inds a i"en number in the array and returns its location.int findno(int *a, int x); x is the number to be found in arra gi3en
b a.
*
+ -rite implementation o# a eneric queue !hich can store elements o# any type. You
need to decide the prototypes o# the queue #unctions. You are allo!ed to modi#y the
tpical textbook prototypes o# enqueue23, dequeue23 and other #unctions also.)or example( 9ne should be able to enqueue23, an int, #loat, struct, char, etc< and on a
dequeue23 one should et back the data, alon !ith the in#ormation about the type o#
the data.
*
E -rite an implementation o# a list type usin a queue type.
You are i"en a queue type, !ith the #ollo!in #unctions(
void 1init(queue *q);void enqueue(queue *q, char ch);char dequeue(queue *q);int qempty(queue *q);int qfull(queue *q);You are required to !rite a list type, usin the abo"e queue type. The list type should
ha"e #ollo!in #unctions(void init(list *l);void insert(list *l, char str, int pos); //insert at position=pos
char remov(list *l, int pos);
//remove an element from position=posvoid append(list *l, char str);int length(list *l);
*
/