Professional Documents
Culture Documents
College of Engineering, Pune: (An Autonomous Institute of Govt. of Maharashtra)
College of Engineering, Pune: (An Autonomous Institute of Govt. of Maharashtra)
College of Engineering, Pune: (An Autonomous Institute of Govt. of Maharashtra)
Semester: - III
Max. Marks: - 60
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