Professional Documents
Culture Documents
MISSION:
To foster an intellectual and ethical environment in which both skill and spirit will thrive so as to
impart high quality education, training, and service with an international outlook. To create and
develop technocrats and business leaders who will strive to improve the quality of life.
VISION:
To become a world-class center in providing globally relevant higher education in the field of
management, technology and applied science embedded with human values.
MISSION:
Don Bosco Bangalore, Department of Computer Science and Engineering would like to nurture the
development of skill sets among the students in the area of software engineering, computer
networking, database, computer graphics, operating systems, artificial intelligence, numerical and
symbolic computation with the collaborative efforts of participants and industry.
VISION:
Don Bosco Bangalore, Department of Computer Science and Engineering looks forward to be a
quality centre of computation by imparting knowledge on various algorithms and data structures,
programming methodology and languages with an orientation of computer architecture as per the
standards of the industry with cohesive efforts of its students and staffs.
PROGRAMME EDUCATIONAL OBJECTIVES AND PROGRAMME OUTCOMES
PROGRAMME OUTCOMES:
a) An ability to apply knowledge of mathematics, science, and engineering.
b) An ability to design and conduct experiments, as well as to analyze and interpret data.
c) An ability to design a system, component, or process to meet desired needs within realistic
constraints such as economic, environmental, social, political, ethical, health and safety,
manufacturability, and sustainability.
d) An ability to function on multidisciplinary teams.
e) An ability to identify, formulates, and solves (complex) engineering problems.
f) An understanding of professional and ethical responsibility.
g) An ability to communicate effectively
h) The broad education necessary to understand the impact of engineering solutions
in a global,economic, environmental, and societal context.
i) Recognition of the need for, and an ability to engage in life-long learning.
j) Knowledge of contemporary issues,
k) An ability to use the techniques, skills, and modern engineering tools necessary for
engineering practice.
l) An ability to understand discrete mathematics and apply for the solution for the problem
Design and Analysis of Algorithm Lab
Contents
Sl.No. Program Page No.
1 Program to
a) Create n Student objects and print the USN, Name, Branch, and Phone of 1
these objects
b) Implement the Stack using arrays 3
2 Program to
a) Design super class and extend class 6
b) Read customer data as <name, dd/mm/yyyy> and display as <name, dd, 8
mm, yyyy> using StringTokenizer class
3 Program to
(a) Read two integers a and b and compute a/b 9
(b) Implement a multi-thread application that hashtree threads 10
4 Program to sort a given set of n integer elements using Quick Sort method and 12
compute its time complexity
5 Program to sort a given set of n integer elements using Merge Sort method and 14
compute its time complexity
6 Program that implements, the 0/1 Knapsack problem using
(a) Dynamic Programming method 16
(b) Greedy method 19
7 Program to find shortest paths to other vertices using Dijkstra's algorithm. 22
8 Program to find Minimum Cost Spanning Tree of a given undirected graph using
(a) Kruskal's algorithm 25
(b) Prim's algorithm 27
9 Program to
a) Implement All-Pairs Shortest Paths problem using Floyd's algorithm 30
b) Implement Travelling Sales Person problem using Dynamic programming 32
10 Design and implementation of
a) Subset sum Problem 34
b) Hamiltonian cycle in an undirected graph 37
2 A. Design a super class called Staff with details as StaffId, Name, Phone, Salary. Extend this class
by writing three subclasses namely Teaching (domain, publications), Technical (skills), and Contract
(period). Write a Java program to read and display at least 3 sttff objects of all three categories.
2 B. Write a Java class called Customer to store their name and date_of_birth. The date_of_birth
format should be dd/mm/yyyy. Write methods to read customer data as <name, dd/mm/yyyy> and
display as <name, dd, mm, yyyy> using StringTokenizer class considering the delimiter character as
“/”.
3 A. Write a Java program to read two integers t and b. Compute t/b and print, when b is not zero.
Raise an exception when b is equal to zero.
B. Write a Java program that implements a multi-thread application that hashtree threads. First thread
generates a random integer for every 1 second; second thread computes the square of the number and
prints; third thread will print the value of cube of the number.
5. Sort a given set of n integer elements using Merge Sort method and compute its time complexity.
Run the program for varied values of n > 5000, and record the time taken to sort. Plot a graph of the
time taken versus n on graph sheet. The elements can be read from a file or can be generated using the
random number generator. Demonstrate using Java how the divide and conquer method works along
with its time complexity analysis: worst case, average case and best case.
6. Implement in Java, the 0/1 Knapsack problem using (a) Dynamic Programming method (b) Greedy
method.
7. From a given vertex in a weighted connected graph, find shortest paths to other vertices using
Dijkstra's algorithm.. Write the program in Java.
10 A.. Design and implement in Java to find a subset of a given set S = {Sl, S2,.....,Sn} of n positive
integers whose SUM is equal to a given positive integer d.. For example, if S ={1, 2, 5, 6, 8} and d= 9,
there are two solutions {1,2,6}and {1,8}. Display a suitable message, if the given problem instance
doesn't have a solution.
10 B. Design and implement the presence of Hamiltonian Cycle in an undirected Graph G of n
vertices.
Graduate Attributes
• Engineering Knowledge
• Problem Analysis
• Modern Tool Usage
• Conduct Investigations of Complex Problems
• Design/Development of Solutions
OUTPUT :
Enter USN:-
4SN16CS049
Enter Name:-
SREEHAN
Enter Branch:-
CSE
Enter Phone number:-
9945081055
Student Details
USN Name Branch Phone
4SN16CS049 SREEHAN CSE 9945081055
Design and Analysis of Algorithm Lab
/* 1B. Write a Java program to implement the Stack using arrays.
Write Push(), Pop() and Display() methods to demonstrate its
working.*/
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package stackdemo;
import java.util.*;
public StackDemo(int n)
{
arraySize = n;
stackArray = new int[arraySize];
top = -1;
}
class Staff{
private int StaffId;
private String Name;
private String Phone;
private long Salary;
public Staff(int staffId,String name,String phone,
phone,long
long salary){
StaffId = staffId;
Name = name;
Phone = phone;
Salary = salary;
}
OUTPUT :
OUTPUT:
Enter Name :-
KALAM
Enter Date of birth:-
19/01/2000
KALAM,19 01 2000
Design and Analysis of Algorithm Lab
/* 3A. Write a Java program to read two integers a and b.
b Compute
a/b and print, when b is not zero. Raise an exception when b is
equal to zero.*/
import java.util.Scanner;
class MyException extends Exception {
public String toString() {
return "Denominator is 0! Division by zero ERROR";
}
}
class Compute {
private int a,b;
public Compute(int a, int b) {
super();
this.a = a;
this.b = b;
}
public void compute_a_by_b() {
try {
if (this.b != 0) {
System.out.println("Result a/b="+(float)1.0*this.a/this.b);
}
else throw new MyException();
} catch (MyException
MyException e) {
System.out.println("Error !!!!: " + e);
}
}
}
public class Lab3A {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Enter a ::-");
int a = in.nextInt();
System.out.print("Enter b:
b:-");
int b = in.nextInt();
Compute compute = new Compute(a, b);
compute.compute_a_by_b();
}
}
OUTPUT 1:
Enter a :-2
Enter b:-5
Result a/b=0.4
OUTPUT 2:
Enter a :-2
Enter b:-0
Error !!!!: Denominator is 0! Division by zero ERROR
Design and Analysis of Algorithm Lab
/* 3B. Write a Java program that implements a multi-thread
multi
application that hashtree threads. First thread generates a
random integer for every 1 second; second thread computes the
square of the number and prints; third thread will print the
value of cube of the number.*/
import java.util.Random;
import java.util.Random;
}
}
public Square_Num(int
int a) {
this.n = a;
}
}
OUPUT 1:
Square of a Number 2 is :4.0
36
Cube of a Number 2 is :8.0
65 82 26 72 45 90 89 41 3
OUPUT 2:
44
Square of a Number 2 is :4.0
Cube of a Number 2 is :8.0
73 61 69 35 10 66 96 33 76
Design and Analysis of Algorithm Lab
/*4. Sort a given set of n integer elements using the Quicksort
method and compute its time complexity. Run the program for
varied values of n > 5000 and record the time taken to sort. Plot
a graph of the time taken versus n on graph sheet. The elements
can be read from a file or can be generated using the random
number generator. Demonstrate using Java how the divide and
conquer method works along
along with its time complexity analysis:
worst case, average case and best case.*/
import java.util.Random;
import java.util.Scanner;
OUTPUT 1:
********** QUICK SORT PROGRAM *********
Enter the number of elements to be sorted
10
Array elements to be sorted are
36 64 13 82 9 19 53 0 72 23
The sorted elements are
0 9 13 19 23 36 53 64 72 82
OUTPUT 2:
********** QUICK SORT PROGRAM *********
Enter the number of elements to be sorted
20
Array elements to be sorted are
35 93 25 35 92 97 43 88 92 0 35 57 78 32 59 56 98 4 71 9
The sorted elements are
0 4 9 25 32 35 35 35 43 56 57 59 71 78 88 92 92 93 97 98
import java.util.Random;
import java.util.Scanner;
OUTPUT 1:
********** MERGE SORT PROGRAM *********
Enter the number of elements to be sorted
10
Array elements to be sorted are
34 83 89 21 62 36 48 90 36 85
The sorted elements are
21 34 36 36 48 62 83 85 89 90
OUTPUT 2:
********** MERGE SORT PROGRAM *********
Enter the number of elements to be sorted
20
Array elements to be sorted are
56 55 12 91 83 43 62 93 70 33 54 45 57 51 35 17 0 67 23 39
The sorted elements are
0 12 17 23 33 35 39 43 45 51 54 55 56 57 62 67 70 83 91 93
import java.util.Scanner;
The result is =
1.0 0.4 0.0 0.0
Maximum profit is = 20.4
*******************************************************
Design and Analysis of Algorithm Lab
/* 7. From a given vertex in a weighted connected graph, find
shortest paths to other vertices using Dijkstra's algorithm.
algorithm
Write the program in Java.*/
import java.util.Scanner;
}
}
}
import java.util.Scanner;
OUTPUT
********* KRUSKAL'S ALGORITHM *********
Enter the number of nodes:
5
Enter the cost matrix
0 1 2 999 6 1 0 3 999
999 2 3 0 4 999 999 999
4 0 5 6 999 999 5 0
The entered cost matrix is
0 1 2 999 6
1 0 3 999 999
2 3 0 4 999
999 999 4 0 5
6 999 999 5 0
1> minimum edge is :(1,2) and its cost is:1
2> minimum edge is :(1,3) and its cost is:2
3> minimum edge is :(3,4) and its cost is:4
4> minimum edge is :(4,5) and its cost is:5
The minimum spanning tree cost is : 12
********* *********************** **********
Design and Analysis of Algorithm Lab
import.java.util.scanner;
}
OUTPUT 1:
************** PRIMS ALGORITHM **************
Enter the number of nodes
5
Enter the cost matrix
0 1 2 999 6 1 0 3 999 999 2
3 0 4 999 999 999 4 0 5 6 999
999 5 0
The entered cost matrix is
0 1 2 999 6
1 0 3 999 999
2 3 0 4 999
999 999 4 0 5
6 999 999 5 0
Minimum Spanning Tree Edges and costs are
1) Minimum edge is (2,1) and its cost is :1
2) Minimum edge is (3,1) and its cost is :2
3) Minimum edge is (4,3) and its cost is :4
4) Minimum edge is (5,4) and its cost is :5
The minimum spanning tree cost is 12
******* ******************************** *******
Design and Analysis of Algorithm Lab
/* 9A. Write Java programs to implement All
All-Pairs
Pairs Shortest Paths
problem using Floyd's algorithm.*/
import java.util.Scanner;
}
Design and Analysis of Algorithm Lab
OUTPUT :
***********FLOYD'S ALGORITHM**********
import java.util.Scanner;
OUTPUT :
}
}
OUTPUT 1:
*********** SUBSET PROBLEM ************
Enter the number of elements:
5
Enter the elements in increasing order:
1 2 3 6 8
Enter the value of d:
9
SUM =20
Solution 1 is {1 2 6 }
Solution 2 is {1 8 }
Solution 3 is {3 6 }
********** ****************** *************
OUTPUT 2:
*********** SUBSET PROBLEM ************
Enter the number of elements:
3
Enter the elements in increasing order:
5 8 10
Enter the value of d:
25
SUM =23
Subset is not possible !
********** ****************** *************
OUTPUT 3:
*********** SUBSET PROBLEM ************
Enter the number of elements:
3
Enter the elements in increasing order:
3 5 9
Enter the value of d:
7
SUM =17
Subset is not possible !
OUTPUT 2:
*******************Hamiltonian cycle*****************
Enter no. of vertices
Department of CSE, DBIT,Bengaluru
Design and Analysis of Algorithm Lab
5
Enter adjacency matrix of graph
0 1 0 1 0 1 0 1 1 1 0 1 0 0 1 1 1 0 0 0 0
1 1 0 0
Entered adjacency matrix of graph is
0 1 0 1 0
1 0 1 1 1
0 1 0 0 1
1 1 0 0 0
0 1 1 0 0