Professional Documents
Culture Documents
Roll No:MC-I-101
Class: FY-MCA
Title: Comparative Analysis of C++ and java Bubble sort Algorithm
Abstract: This comparative analysis explores the Bubble sort Algorithm
implemented in Python and Java, two widely used programming languages with
distinct characteristics. The study examines the execution speed, memory
access, and language features of both Python and Java, shedding light on their
suitability for different application domains.
Code:
import java.io.*;
class GFG {
static void bubbleSort(int arr[], int n) {
int i, j, temp;
boolean swapped;
for (i = 0; i < n - 1; i++) {
swapped = false;
for (j = 0; j < n - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
swapped = true;
}
}
if (swapped == false)
break;
}
}
static void printArray(int arr[], int size) {
int i;
for (i = 0; i < size; i++)
System.out.print(arr[i] + " ");
System.out.println();
}
Output:
C++
Program: Bubble sort
Code:
}#include <bits/std++.ch>
using namespace std;
Result:
Platform Line of File File Speed
code Capicity Capicity Accees
text
Java 36 4 kb 882 bytes 1 ms
C++ 34 4 kb 645 bytes 0 ms
Conclusion:
In conclusion, the comparison between Java and C++ for solving the Bubble
sort Algorithm problem reveals distinct characteristics of both programming
languages.
If execution time is a critical factor, C++ is likely to perform better than Java
for Bubble Sort and many other algorithms due to its lower-level control,
efficient memory management, and direct access to machine resources.
However, the exact performance difference can vary based on the specific
implementations, compiler settings, and hardware, so it's advisable to conduct
benchmarks for your specific use case to get a more accurate measurement of
the performance difference.