College of Engineering, Pune: (An Autonomous Institute of Govt. of Maharashtra)

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

MIS Number

COLLEGE OF ENGINEERING, PUNE


(An Autonomous Institute of Govt. of Maharashtra)

End Semester Examination November, 2014

( CT 205 ) Data Structures


Class: - T.Y. B.Tech (Computer Engineering &Information Technology)
Year: - 2014-15
Duration: - 3 Hours
Instructions:

Semester: - III
Max. Marks: - 60

1. All questions are compulsory.


2. This is an open book test. You can read your textbooks/notes, but exchange is not
allowed.
3. Some questions may not have definite answers.
4. Use the given type definitions and function prototypes for writing your answers.
5. You can make assumptions if required, but you should state them.
6. Code must be indented, commented, and written in ANSI C. You can write the code with
a bold pencil.
7. You can explain your answer in Marathi/Hindi.
Q1 A Draw diagram of the data structure created by following code:
intmain(){
structtest{
structdata{
chara[3];
inti;
}b,*bp;
floatf;
}p,*pp;
pp=&p;
pp>bp=&(p.b);
p.b.i=30;
p.b.a[2]='x';
}
B For a binary search tree of integers, write a function which computes the sum-total of
values of all nodes in the tree. Use the following type definition and function
prototype.
intsumtotal(treet);
typedefstructnode{
intval;
structnode*left,*right;
}node;
typedefstructnode*tree;
C Mention all bugs/limitations about the code given below.
#definelim128
intf(){
inta[lim];
inti=0;
while(a[i]<20||i<lim)
printf(%d,a[i++]);
}
1/4

Q1

G
Q2

D
E

Write a program, which opens a file and counts the number of occurrences of a
particular character in it. Both the filename and the character are given as command
line arguments.
Write a function which replaces every instance of a character 'old' with another
charcter 'new' in a given string 'str' and returns number of replacements done.
intreplacechar(char*str,charold,charnew);
For example: if str="somethings", old='s' and new='t' then str becomes 'tomethingt'
and function returns 2.
Derive the equation for time taken by following code.
intf(inta,intb){
intm;
for(i=0;i<a;i++)
for(j=0;j<b;j*=2)
m=i+j;
}
Show the contents of the array after each iteration of selection sort for following data
13618512
Using the type definition
typedefstructnode{
floatf;
structnode*next;
}node;
typedefstructnode*ll;
Write a recursive function to create a copy of a singly linked NULL terminated list.
llcopy(lll);
Reconstruct the binary tree (draw the diagram), for which the inorder and preorder
traversals are given below and write the postorder traversal.
inorder:aegmno
preorder:meagno
Write code for store function of a hashing scheme which uses chaining for collision
resolution. The data to be stored in hash table is following structure:
structaccount{
floatrate;
intnumber;
};
The search key is 'rate'. You may add appropriate code to the type definition.
Write an implementation of a stack using an array of size 16. When the array
becomes full, the stack uses a file to write the data, so the stack is never full.
Write the itoa function which converts an integer into it's string representation and
returns the string.
char*itoa(intx);

2/4

2
3

3
3

Q2

Q3

Given following type definitions for a sparse matrix, and given that entries are stored
in the array "arr" in unsorted order, write a function to add two sparse matrices and
return the resultant sparse matrix. Other variables have same meaning as discussed in
class.
typedefstructelem{
intr,c,v;
}elem;
typedefstructspm{
elemarr[128];//Note:Entriesarenotinsortedorder
intnrow,ncol,nelem;
}spm;
spm*spmadd(spm*a,spm*b);
Find out the time following code takes in the worst 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(qb)+1;
q=b;
}
}
}
if(*q=='\0')
returnp(qb)a;
else
return1;
}
Design data structure for a spread sheet. Just draw a diagram and write the type
definitions in C.
Spread sheet is a program which allows the users to store (assume) text data in cells
of a sheet. Consider the following operations for the design: Entering 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. Popular examples of spread sheets are
Libreoffice Calc or Microsoft Excel. You are expected to design data structure only
for the storing the data and pay no attention to the graphical interface.

3/4

Q3

Write a function which cuts a doubly circular linked list in the middle. After split the
list remains as the first half, and the function returns the second part of the linked list
as another doubly circular linked list.
E.g. if the list was [10 20 30 40 50 60 ] , then after the function is called the list
remains as [10 20 30] and the list [40 50 60] is returned by the function. For Odd
No. of data elements, the bigger part remains in the original list.
typedefstructnode{
intval;
structnode*prev,*next;
}node;
typedefstructdcll{
node*head,*tail;
}dcll;
dcllcutmiddle(dcll*l);
You have been given an array of integers. The size is not known, so consider the size
to be practically unlimited( which means do not bother about segmentation fault due
to array index violations). The array is sorted in ascending order. Write code for an
efficient function which finds a given number in the array and returns it's location.
intfindno(int*a,intx); // x is the number to be found in array given
by a.
Write implementation of a generic queue which can store elements of any type. You
need to decide the prototypes of the queue functions. You are allowed to modify the
typical textbook prototypes of enqueue(), dequeue() and other functions also.
For example: One should be able to enqueue(), an int, float, struct, char, etc; and on a
dequeue() one should get back the data, along with the information about the type of
the data.
Write an implementation of a list type using a queue type.
You are given a queue type, with the following functions:
void1init(queue*q);
voidenqueue(queue*q,charch);
chardequeue(queue*q);
intqempty(queue*q);
intqfull(queue*q);
You are required to write a list type, using the above queue type. The list type should
have following functions:
voidinit(list*l);
voidinsert(list*l,charstr,intpos);
//insertatposition=pos
charremov(list*l,intpos);
//removeanelementfromposition=pos
voidappend(list*l,charstr);
intlength(list*l);

4/4

You might also like