Académique Documents
Professionnel Documents
Culture Documents
Question.1
Modify the bubble sort algorithm in which the direction of bubbling changes in each iteration: in one iteration, the
smallest element is bubbled up; in the next, the largest is bubbled down; in the net, the second smallest is bubbled up;
and so forth. Write an algorithm in C to implement this and find its time complexity.
Ans.
Bubble sort with Required Modification:
Question 2:
Write an algorithm in C to convert an infix expression to a postfix expression. Execute your algorithm with the
following infix expression as your input.
(m+n)*(k+p)/(g/h) (a b/c)
Note: you must execute the program and submit the program logic, sample inputs and outputs along with the necessary
documentation for this question. Assumptions can be made wherever necessary.
Ans
Algorithm converts an expression from infix to postfix:
Let us now present an outline of an algorithm to an infix without parentheses into a postfix string. Since we assume no
parentheses in the input string, the only governor of the order in which operators appear in the postfix is precedence. (The line
numbers that appear in the algorithm will be used for future reference.)
opstk=the empty stack;
while=(not end of input) {
symb=next input character;
if(symb is an operand)
add symd to the postfix string
else {
while (!empty (opstk)&& pred (stack top (opstk),symb)) {
topsymo=pop (opstk);
add topsymb to the postfix string;
}/* end while */
push (opstk,symb);
}/* end else */
}/* end while */
/* output any remaining operators */
while (! Empty (opstk);
top symb=pop(opstk);
add topsymb to the postfix string;
MCS-025 1 http://geocities.com/ignoumca/
}/* end while */
Simulate the algorithm with such infix strings as “A*B+C*D” and “A+B*C$D$E” to convince yourself that it is correct. What
modification must be made to this algorithm to accommodate parentheses? The answer is surprisingly little. When a opening
parenthesis is read, it must push into the stack. This can be done by establishing the convention that prod(op,‘(‘) equals
FLASE, for any operator symbol op other than a ring parenthesis. In addition, we define prod(‘(‘,op) to be FLASE for any
operator symbol op. this ensures that an operator symbol appearing after a left parenthesis is pushed onto the stack.
However, since the closing parenthesis should not be pushed onto stack, line g is replaced by the statement.
if(empty)||symd!=‘)’)
push(opstk,symb);
else /* pop the open parenthesis and discard it */
topsymb=pop(opstk);
Input Output
S.No. Symbol Postfix string Opstk
1 ( ……. (
2 m m (
3 + m (+
4 n mn (+
5 ) mn+ ……
6 * mn+ *
7 ( mn+ *(
8 k mn+k *(
9 + mn+k *(+
10 p mn+kp *(+
11 ) mn+kp+ *
12 / mn+kp+ */
13 ( mn+kp+ */(
14 g mn+kp+g */(
15 / mn+kp+g */(/
16 h mn+kp+gh */(/
17 ) mn+kp+gh/ */
18 mn+kp+gh/ */
19 ( mn+kp+gh/ */
20 a m n + k p + g h /a */(
21 m n + k p + g h /a */(
22 b m n + k p + g h /a b */(
23 / m n + k p + g h /a b */(
24 c m n + k p + g h /a b c
*/(/
25 ) m n + k p + g h /a b c / / *
*/(/
Answer :::
/*
ALGORITHM
Design a structure called INFIX.
- contains two character arrays Target and Stack that store the Postfix
expression (string) and the Operators (that would be pushed onto stack)
respectively.
- The two character pointers s and t are used in the conversion process.
- The variable Top points to the top of the Stack.
Accept arithmetic expression (consisting of digits, alphabets and operators)
from the user into a string Expr.
Assign the base address of the input string (Expr) to character pointer s.
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#define MAX 50
int main( )
{
struct infix p; // infix expression
char expr[MAX]; // input expression
initinfix(&p);
clrscr();
printf("\nEnter an expression in Infix form: ");
gets(expr);
//strcpy(expr, "(m+n)*(k+p)/(g/h)$(a$b/c)");
setexpr(&p, expr);
convert(&p);
printf("\nThe Postfix expression is: ");
show(p);
getch();
return(0);
} // end of main()
/* Left Bracket */
if(*(p->s) == '(')
{
push(p, *(p->s));
p->s++;
} // end of if(left bracket)
/* Right Bracket */
if(*(p->s) == ')')
{
opr = pop(p);
while((opr) != '(')
{
*(p->t) = opr;
p->t++;
opr = pop(p);
} // end of while(NOT Left bracket)
p->s++;
} // end of if(right bracket)
} // end of while(*(p->s))
/* Empty Stack */
while(p->top != -1)
{
opr = pop(p);
*(p->t) = opr;
p->t++;
}
*(p->t) = '\0';
} // end of convert()
MCS-022
Question 1:
MCS-025 5 http://geocities.com/ignoumca/
Write a shell script that prints list of every unique word (exceeding 4 characters in length) in a file in reverse
alphabetical order.
Question 2:
I. What is the output of ls-lm and ls-ml? Which option takes procedure? What is the result of is-d?
II. How would you set the IP address of a LAN card in Linux?
Question 3:
I. Protect Data by using Encrypting File system (EFS) and Recover Encrypted Data with a Data Recovery Agent.
Show the result with the help of your own example?
II. Configure Window 2000 to have a remote access feature and the result.
MCS-023
Question 1:
There are many private college affiliate to a state University. The University wants to computerize all its affiliated
colleges to keep update information about student, faculty, generate different types of reports and monitor
performance of these colleges. After creating the database you must perform the following tasks:
Produce a report showing number of student registered in each program of each college.
1. Find out number of faculty positions vacant in computer science programme in all colleges.
2. List the name of students with their enrollment nm\umber who have topped in their respective program in
their colleges.
3. Produce a report of faculties who are going to retire within 6 months.
4. List the name of the faculties with the highest number of research papers in international journals.
Ans
Relation 1 : College(college_name,college_code,location,contact_no)
Description : All those college,with are affiliated to the university are details with this Relation.
Key : College_code
Table :
College
College_name College_code Location Contact_no
Vidyanagar C0001 Anand 24556667
Nirma C0002 Ahmedabad 35664555
H.L C0003 Ahmedabad 24553452
NICM C0004 Gandhinagar 25234673
Somlalit C0005 Ahmedabad 24556345
Relation 2 : Program_pffered(college_code,program_code)
Description : This relation list programs offered by each college.
Key : College_code,program_code
Table :
Program_offered
College_code Program_code
C0001 P0001
C0002 P0002
C0003 P0003
C0004 P0001
C0004 P0002
C0005 P0004
C0005 P0005
Relation 3 : Program_detail(program_code,program_name,duration,total_credits)
Description : Details of each program can be viewed from this relation.
Key : program_code(program_code is unique for all university i.e. B.Tech(cs) ‘Computer Science’ for all college,
which offer computer Engineering.
Table:
Program_details
Program_code Program_name Duration Total_credit
P0001 MCA 3 10
MCS-025 6 http://geocities.com/ignoumca/
P0002 MBA 2 10
P0003 Computer Science 3 9
P0004 BCOM 3 12
P0005 BE 4 20
Relation 4 : Faculty_position(college_code,program_code,faculty_positions,faculty_avail)
Description : Details of each faculty positions and faculty available for each program and college is maintained in this
table.
Key : college_code,program_code.
Table:
Faculty_position
College_code Program_code Faculty_positions Faculty_avail
C0001 P0001 2 1
C0001 P0004 3 2
C0002 P0002 1 1
C0002 P0003 5 2
C0003 P0001 3 1
C0003 P0002 2 2
C0004 P0003 1 1
C0005 P0004 2 2
C0005 P0005 1 1
Relation 5 :Faculty_position(college_code,Faculty_name,Faculty_address,Faculty_contact,Faculty_qualication,
date_of_join,date_of_birth,college_code,program_code)
Description : Apersonal details of each faculty is maintained in this table. It also maintained his/her appointment details
like college,and programs are also maintained her.
Key : program_code(program_code is unique for all university i.e. B.Tech(cs) ‘Computer Science’ for all college,
which oFaculty_ID(Faculty_ID is unique for each faculty among all faculty of university)
Table:
Faculty
Faculty_ Faculty_na Faculty_addre Faculty_co Faculty Designa Date_of_joi Date_of_birt College Progr_c
ID me ss ntact _qulif tion n h _code ode
F0001 Madhvi Gurukul 24546788 MCA Leet 12/2/2004 6/1/1981 C0001 P0001
F0002 Maghna Maninagar 44564566 BSC Prof 9/4/2001 9/14/1985 C0002 P0003
F0003 Payal Gandhinagar 24546788 BCOM Leet 7/19/2005 5/11/1980 C0003 P0002
F0004 Devendra Kalapinagar 56734556 MBA Leet 1/8/2002 1/12/1978 C0004 P0004
F0005 Jainam Naranpure 24546234 BE Leet 4/22/2006 3/11/1984 C0001 P0001
Relation 6 : Faculty_Paper(Faculty_ID,research_topic,paper_title,journal,publish_at)
Description : Details of each resurch paper published by each faculty is record in this table.
Key : Faculty_ID,paper_title.
Table:
Faculty_paper
Faculty_ID Research_topic Paper_title Journal Publish_at
F0001 Web Service .NET paper .NET International
F0002 WareHousing WareHousing MBA National
F0003 System Lifecycle SAD MCA International
F0004 Accounting Princples Accounting BCOM International
F0005 Bio-Checmist Bio-Checmist BSC National
Table :
MCS-025 7 http://geocities.com/ignoumca/
Student
Studen name MNa Lname correspond Present_ad Local_co Permane Res Progra College
t_code me ence_addre dress ntact nt_contac ult m_code _code
ss t
S0001 Meena U Gazzar Ahmedabad Ahmedabad 3434234 23423444 67 P0001 C0001
S0002 Jinal L Patel Ahmedabad Ahmedabad 4563424 4563424 80 P0002 C0002
S0003 Pinky O Sanghavi Gandhinagar Gandhinagar 6734444 6734444 75 P0003 C0004
S0004 Jaya A Mehta Gandhinagar Gandhinagar 56453245 56453245 69 P0004 C0003
S0005 Sagar P Nayak Anand Ahmedabad 4532434 12323234 76 P0005 C0005
S0006 Jainam U Shah Ahmedabad Ahmedabad 2455344 2455344 59 P0002 C0003
Report 1:
SQL
SELECT Sum(Faculty_position.faculty_positions-Faculty_position.faculty_avail) AS Vacancy, Faculty_position.college_code
FROM Faculty_position INNER JOIN Program_details ON Faculty_position.program_code=Program_details.program_code
Where(((Program_detail.program_name)=’Computer Science’)) Group BY Faculty_position.college_code;
OUTPUT:
Vacancy College_code
3 C0002
0 C0004
Report 2:
SQL :
SELECT Student.Stydent_code, Student.Fname,Student.MName,Student.Lname,Max(Student.result) AS MaxOfresult,
Student.college_code,Program_detail.program_name, College.college_name FROM(College INNER JOIN Student ON
College.college_code=Stuydent.college_code) INNER JOIN Program_detail ON
Student.program_code=program_detail.program_code, Student.Fname,Student.college_code,
Program_detail.program_name,College.college_name;
OUTPUT:
Student Fname MName Lname MaxOf result College code Program name College_name
code
S0001 Meena U Gazzar 67 C0001 MCA Vidyanagar
S0002 Jinal L Patel 80 C0002 MBA Nirma
S0003 Pinky O Sanghavi 75 C0004 Computer NICM
Science
S0004 Jaya A Mehta 69 C0003 BCOM H.L
S0005 Sagar P Nayak 76 C0005 BE Somlalit
S0006 Jainam U Shah 59 C0003 MBA H.L
Report 3:
SQL:
SELECT faculty_id,Faculty_name FROM faculty HHERE DATEDIFF(‘m’,CURDATE,’12/2/2007’)<=6;
OUTPUT:
Faculty_ID
F0005
Report 4:
SQL
SELECT faculty.faculty_name from Where faculty.faculty_id In (select faculty.faculty_id from
Faculty.publish_at=’International’ Group by Faculty.faculty_id having Count(faculty.paprer_title)>=(select count(paper_title)
From faculty_paper Where publish_at=’International;’ Group by faculty_id));
OUTPUT:
Faculty_name
Madhavi
MCS-025 8 http://geocities.com/ignoumca/
Meghna
MCS-024
Question 1:
I. Write a java program to demonstrate the use of different bitwise operators.
II. Write a java program, which create variable size array in java. This program also should take two 33
matrices as input and display sum of these matrices.
Question 2:
I. Write a java program that take your name as input and display the reverse of it. Also read names of two of
your friends and attend it to your name and display the final string.
II. Write a java program to explain how a thread with higher priority will execute before a thread of low priority.
Question 3:
I. Write a java program to create a file and copy the contents of an already existing file into it.
II. Create an Applet program, which takes your name, address, and a detailed description of advantages of using
java-programming language. After giving input when you press submit button your program display “You are
right, java is really a very good programming language”, Use appropriate GUI components and layout in this
program.
Question 1:
(i) Write a Java program to demonstrate the use of different bitwise operators.
Answer::
Bitwise operators: Java provides Bit wise operators to manipulate the contents of variables at the bit level. These variables
must be of numeric data type (char, short, int, or long). Java provides seven bitwise operators. They are AND, OR, Exclusive-
OR, Complement, Left-shift, Signed Right-shift, and Unsigned Right-shift. An example program is shown below that
demonstrates the different Bit wise operators in java.
The result of applying bitwise operators between two corresponding bits in the operands is shown in the Table below.
1 1 0 1 1 0
1 0 0 0 1 1
0 1 1 0 1 1
0 0 1 0 0 0
Program:
public class BitwiseOperatorsDemo {
public static void main(String args[]){
int x = 0xFAEF; //1 1 1 1 1 0 1 0 1 1 1 0 1 1 1 1
int y = 0xF8E9; //1 1 1 1 1 0 0 0 1 1 1 0 1 0 0 1
(ii) Write a Java program, which create variable size array in Java. This program also should take two 3× 3 matrices
as input and display sum of these matrices.
Answer ::
import java.io.*;
public class MatrixMult {
if(col1 == row2){
System.out.println("The answer is:");
for(int i=0;i<row1;i++){
for(int j=0;j<col2;j++){
tempVal=0;
for(int k=0;k<col1;k++){
tempVal+= matrix1[i][k]*matrix2[k][j];
}
System.out.print(tempVal+"\t");
}
System.out.println();
}
}else{
MCS-025 10 http://geocities.com/ignoumca/
System.out.println("Multiplication is not possible::");
}
}catch(IOException e){
e.printStackTrace();
}
}
}
/*
::::::::::::OUTPUT::::::::::::::
Enter rows and columns of first matrix::
3
3
Enter rows and columns of second matrix::
3
3
enter values for matrix 1:
1
1
1
1
1
1
1
1
1
enter values for matrix 2:
2
2
2
2
2
2
2
2
2
The answer is:
6 6 6
6 6 6
6 6 6
*/
Question 2:
(i) Write a Java program that take your name as input and display the reverse of it. Also read names of two of your
friends and attend it to your name and display the final string.
Answer ::
import java.io.*;
public class StringBufferOp {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
String str2 = null;
StringBuffer str1 = new StringBuffer("Rikin Patel");
System.out.println("string buffer capacity:::"+str1.capacity());
System.out.println("Enter string to concate with str1::");
try{
str2 = br.readLine();
MCS-025 11 http://geocities.com/ignoumca/
}catch(Exception e){
e.printStackTrace();
}
str1.append(str2);
System.out.println("String after concat:::"+str1);
}
/*::::OUTPUT:::::
string buffer capacity:::27
Enter string to concate with str1::
NISHIT DHARA
String after concat:::Rikin Patel NISHIT DHARA
*/
(ii) Write a Java program to explain how a thread with higher priority will execute before a thread of low priority
Answer:::
import javax.swing.*;
import java.awt.event.*;
public ThreadPriorityDemo()
{
super( "Demo" );
output = new JTextArea( 10, 20 );
getContentPane().add( output );
setSize( 250, 200 );
setVisible( true );
}
}
/*::::::::OUTPUT:::::::*/
Question 3:
(i) Write a java program to create a file and copy the contents of an already existing file into it.
Answer::
import java.io.*;
public class FileCopy {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
MCS-025 13 http://geocities.com/ignoumca/
int str = 0;
while((str = reader.read()) > 0){
writer.print((char)str);
}
writer.flush();
writer.close();
reader.close();
System.out.println("File Copy Completed");
}catch(Exception e){
e.printStackTrace();
}
/*
::::::::OUTPUT:::::::::::::
Enter source and destination file::
C:/rikin.txt
c:/temp.txt
File Copy Completed
*/
(ii) Create an Applet program, which takes your name, address, and a detailed description of advantages of using java-
programming language. After giving input when you press submit button your program display“You are right, java is
really a very good programming language”. Use appropriate GUI components and layout in this program
Answer:::
Applet ::: An applet is a small Java application that can be sent along with a Web page to a user, much the same way an
image is included. It is a software component that runs in the context of another program, for example a web browser.
import java.applet.Applet;
import java.awt.Button;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
this.add(namelbl);
this.add(nametxt);
this.add(addresslbl);
this.add(addresstxt);
this.add(desclbl);
this.add(desctxt);
MCS-025 14 http://geocities.com/ignoumca/
this.add(oplbl);
this.add(optxt);
this.add(submitbtn);
this.add(clearbtn);
submitbtn.addActionListener(this);
clearbtn.addActionListener(this);
}
/*:::::::OUTPUT:::::::::*/
MCS-025 15 http://geocities.com/ignoumca/