BCA Final Lab Records
BCA Final Lab Records
BCA Final Lab Records
Aim:
Algorithm:
Program:
import java.util.Scanner;
class LinearSearchAlgorithm
boolean presence=false;
int pos=0;
for(int n=0;n<arr.length;n++)
if (arr[n]==searchValue)
presence=true;
pos=n+1;
break;
if (presence)
System.out.println("Search value " + searchValue + " exists at " + pos +" position");
else
int arrSize=sc.nextInt();
for(int n=0;n<arrSize;n++)
arr[n]=sc.nextInt();
int searchValue=sc.nextInt();
Lsa.nSearch(arr,searchValue);
}}
Output:
43
23
65
78
34
23
55
65
Result:
Ex. No: 2 Implementation of Binary Search
Date:
Aim:
Algorithm:
Program:
import java.util.Scanner;
class BinarySearchAlgorithm
int first=0;
int last=arr.length-1;
first = midPoint + 1;
break;
else
last = midPoint - 1;
}
if ( first > last )
int arrSize=sc.nextInt();
for(int n=0;n<arrSize;n++)
arr[n]=sc.nextInt();
int searchValue=sc.nextInt();
bsa.bSearch(arr,searchValue);
}
Output:
10
12
23
45
67
77
79
82
89
91
93
67
Result:
Ex. No: 3 Implementation of Selection sorting method
Date:
Aim:
Algorithm:
Program:
import java.util.Scanner;
arr[i] = arr[j];
arr[j] = temp;
}
Output:
45
23
32
23
32
45
Result:
Ex. No: 4 Implementation of Bubble sorting method
Date:
Aim:
Algorithm:
Program:
import java.util.Scanner;
arr[j + 1] = temp;
}
Output:
65
45
34
88
74
34
45
65
74
88
Result:
Ex. No: 5 Implementation of Insertion sorting method
Date:
Aim:
Algorithm:
Program:
import java.util.Scanner;
arr[i + 1] = arr[i];
i--;
arr[i + 1] = key;
}
Output:
11
33
66
22
44
11
22
33
44
66
Result:
Ex. No: 6 Implementation of PUSH and POP operations of a STACK using ARRAYS
Date:
Aim:
Algorithm:
Program:
import java.util.Scanner;
class Stack {
void display() { for (int i = top; i >= 0; i--) System.out.print(arr[i] + " "); System.out.println();
}
while (true) {
switch (sc.nextInt()) {
}
Output:
10
Inserted: 10
20
Inserted: 20
20 10
Popped: 20
Size: 1
Result:
Ex. No: 7 Implementation of INSERT and DELETE operations of a QUEUE
Date:
Aim:
Algorithm:
Program:
import java.util.Scanner;
class Queue {
int[] items;
this.size = size;
else {
if (isEmpty()) front = 0;
items[++back] = item;
void deQueue() {
if (isEmpty()) System.out.println("Queue is empty");
else front++;
void display() {
void peak() {
while (true) {
switch (sc.nextInt()) {
case 1 -> queue.display();
}
D: \Chezhian Mgr/0.2022-2023-0dd\BCA-AI Lab Programs>java StackImplementation
10
20
30
10
20
30
Size: 3
5
Front value is: 10
1
20
30
1. Display 2. EnQueue 3. DeQueue 4. Size 5. Peak 0. Exit
Result:
Ex. No: 8 Implementation of Binary Tree Traversals
Date:
Aim:
Algorithm:
Program:
import java.util.*;
class BinaryTree {
class Node { int key; Node left, right; Node(int key) { this.key = key; } }
Node root;
return root;
void traverseLevelOrder() {
if (root == null) return;
queue.add(root);
while (!queue.isEmpty()) {
}
Output:
InOrder: 20 30 40 50 70
PreOrder: 50 30 20 40 70
Postorder: 20 40 30 70 50
LevelOrder: 50 30 70 20 40
Result:
Ex. No: 9 Implementation of Binary Search Tree (BST)
Date:
Aim:
Algorithm:
Program:
import java.util.Scanner;
class BinarySearchTree {
class Node { int key; Node left, right; Node(int key) { this.key = key; } }
Node root;
return root;
}
public static void main(String[] args) {
while (true) {
switch (sc.nextInt()) {
}
Output:
10
20
30
InOrder: 10 20 30
20
Found
Result:
Ex. No: 10 Implementation of INSERTING and DELETING nodes in Binary Tree.
Date:
Aim:
Algorithm:
Program:
import java.util.Scanner;
class BSTImplementation {
Node root;
Node insertRec(Node r, int k) { if (r == null) return new Node(k); if (k < r.key) r.left =
insertRec(r.left, k); else r.right = insertRec(r.right, k); return r; }
if (k < r.key) r.left = deleteRec(r.left, k); else if (k > r.key) r.right = deleteRec(r.right, k);
else if (r.left == null) return r.right; else if (r.right == null) return r.left;
while (true) {
switch (sc.nextInt()) {
}
Output:
10
20
10 20
10
20
Result: