1 A - Create a Java class called Student with the following details as variables within it.
 (i) USN
(ii) Name
(iii) Branch
 (iv) Phone
Write a Java program to create n Student objects and print the USN, Name, Branch, and Phone of these objects with suitable headings.

OUTPUT10A.png

1 B - Write a Java program to implement the Stack using arrays.
Write Push(), Pop(), and Display() methods to demonstrate its working.

2 A - Design a superclass 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 staff 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 a and b. Compute a/b and print, when b is not zero. Raise an exception when b is equal to zero.

3 B - Write a Java program that implements a multi-thread application that has three 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.

4 - Sort a given set of n integer elements using Quick 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 non 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.

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 non 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.

8 - Find Minimum Cost Spanning Tree of a given connected undirected graph using Kruskal's algorithm. Use Union-Find algorithms in your program.

9 - Find Minimum Cost Spanning Tree of a given connected undirected graph using Prim's algorithm.

10 - Write Java programs to (a) Implement All-Pairs Shortest Paths problem using Floyd's algorithm. (b) Implement Travelling Sales Person problem using Dynamic programming.

11 - 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.

12 - Design and implement in Java to find all Hamiltonian Cycles in a connected undirected Graph G of n vertices using backtracking principle.

QUICK SORT


QUICK SORT

1.1        OBJECTIVE:
Sort a given set of elements using the Quick sort method and determine the time required to sort the elements. Repeat the experiment for different values of n, the number of elements in the list to be sorted and plot a graph of the time taken versus n. The elements can be read from a file or can be generated using the random number generator.

1.2        RESOURCES:

            Dev C++ or C

1.3        PROGRAM LOGIC:

QuickSort is a Divide and Conquer algorithm. It picks an element as pivot and partitions the given array around the picked pivot. 

There are many different versions of QuickSort that pick pivot in different ways.
1.       Always pick first element as pivot.
2.       Always pick last element as pivot (implemented below)
3.       Pick a random element as pivot.
4.       Pick median as pivot.

The key process in QuickSort is partition. Target of partitions is, given an array and an element x of array as pivot, put x at its correct position in sorted array and put all smaller elements (smaller than x) before x, and put all greater elements (greater than x) after x. 

1.4        PROCEDURE: 

1.      Create: Open Dev C++, write a program after that save the program with .c extension.
2.      Compile: Alt +  F9
3.      Execute: Ctrl + F10

1.5        SOURCE CODE: 

   
<script src="https://ideone.com/e.js/9UhC6F" type="text/javascript" ></script>


Write a Java program to create nStudent objects and print the USN, Name, Branch, and Phone of these objects with suitable headings





Experiment No. 1                                                                     

1. A) Create a Java class called Student with the following details as variables within it. 
             (i) USN
     (ii)    Name
    (iii)  Branch
     (iv)   Phone
Write a Java program to create nStudent objects and print the USN, Name, Branch, and Phone of these objects with suitable headings.


import java.util.Scanner; public class student
 {
            String USN;
            String Name;
            String branch;
            int phone;
void insertRecord(String reg,String name, String brnch,int ph) {
USN=reg;
Name=name;
branch=brnch; 
phone=ph;
}

void displayRecord()
{
System.out.println(USN+" "+Name+" "+branch+" "+phone);
}

public static void main(String args[])
student s[]=new student [100]; 
Scanner sc=new Scanner(System.in);
System.out.println("enter the number of students");
int n=sc.nextInt();
for(int i=0;i<n;i++)  
      s[i]=new student();
for(int j=0;j<n;j++)
{       System.out.println("enter the usn,name,branch,phone")
         String USN=sc.next();    
         String Name=sc.next();    
        String branch=sc.next();     
         int phone=sc.nextInt();
    s[j].insertRecord(USN,Name,branch,phone);

}

for( int m=0;m<n;m++)
{
  s[m].displayRecord();
}

}
}



OUTPUT
enter the number of students 
2
enter the usn,name,branch,phone 
1
monika 
cse
93411
enter the usn,name,branch,phone 
12 
gowda
cse 9785
students details are
 1 monika cse 93411
12 gowda cse 9785