Skip to main content

Sorting Algorithms


Java Implementation for Sortings:

Bubble Sort:

import java.util.Scanner;
public class BubbleSort {
      public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("input size");
int n = scan.nextInt();
int[] ar = new int[n];
System.out.println("input elements");
for (int i = 0; i < ar.length; i++) {
ar[i] = scan.nextInt();
}
bubbleSort(ar);
for (int i = 0; i < ar.length; i++) {
System.out.print(ar[i]+"\t");
}
System.out.println();
scan.close();
}
private static void bubbleSort(int[] ar) {
// TODO Auto-generated method stub
int temp = 0;
for (int i = 0; i < ar.length; i++) {
for (int j = 1; j < (ar.length-i); j++) {
if(ar[j-1]>ar[j]){
temp = ar[j-1];
ar[j-1] = ar[j];
ar[j] = temp;
}
}
        }
}
}


Insertion Sort:

import java.util.Scanner;
public class InsertionSort {
    public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("input size");
int n = scan.nextInt();
int[] ar = new int[n];
System.out.println("input elements");
for (int i = 0; i < ar.length; i++) {
ar[i] = scan.nextInt();
}
insertionSort(ar);
for (int i = 0; i < ar.length; i++) {
System.out.print(ar[i]+"\t");
}
System.out.println();
scan.close();
}
private static void insertionSort(int[] ar) {
int key,j;
for (int i = 1; i < ar.length; i++) {
key = ar[i];
j=i-1;
while(j>=0 && ar[j]>key){
ar[j+1] = ar[j];
j--;
}
ar[j+1] = key;
}
}
}

Comments

Popular posts from this blog

Unshackling the 65mm Format: Inside the ARRI ALEXA 265

  Introduction If you’ve ever tried to shoot dynamic, kinetic movement with a 65mm digital cinema camera, you know the physical toll it takes. Hauling a 10.5-kilogram brain around requires specialized remote heads, heavy-duty stabilization, and an operator with iron shoulders. The sheer physics of large-format glass and massive sensor blocks historically meant sacrificing agility for image quality. Directors had to choose: do we want the immersive, medium-format aesthetic, or do we want to move fast in tight locations? The ARRI ALEXA 265 eliminates that compromise entirely. By stripping the 65mm form factor down to a staggering 3.3 kilograms and injecting the absolute cutting-edge of REVEAL Color Science, ARRI hasn’t just updated a camera—they have fundamentally altered how and where we can shoot large format. Let's break down why this is a seismic shift for visual creators. The Physics of Shrinking 65mm The most immediate shock when looking at the ALEXA 265 is the footprint. It i...

The Only Linear Light You’ll Ever Need? An In-Depth Look at the ARRI Omnibar

  Introduction We’ve all been there: you’re trying to hide a tube light in a tight corner, but the diffusion is too wide and spills everywhere. Or worse, you’re shooting in the rain, and your "weather-resistant" gear starts flickering. For too long, linear lighting has felt like a compromise between portability and professional-grade reliability. ARRI just ended that compromise. The Omnibar isn't just a response to the "tube light" trend; it’s a surgical tool designed to solve the most frustrating problems we face on set. Advanced Optics: Changing the Quality of Light Most linear lights give you one look: soft and wide. The Omnibar flips the script with a magnetic mounting system. By swapping the Round Diffuser for the Intensifier , you can tighten the beam to 60° and gain 50% more output. This means you can actually use a linear light as a punchy key or a controlled rim light without needing massive barn doors or honeycombs. Rugged Reliability and "Infi...

Pixels, Robots, and Dirty Glass: The 2025 Cinematography Cheat Sheet

If you think filmmaking is still just a guy holding a heavy camera and yelling "Action!", I’ve got news for you. In 2025, the movie set looks more like a NASA lab mixed with a high-end gaming lounge. This guide breaks down the latest technological shifts in simple terms for the modern filmmaker and content creator. 1. The Virtual Frontier: "The Volume" The traditional green screen is being retired in favor of Virtual Production (VP) and LED Volume Stages . Think of this as shooting live action in front of a giant, high-definition television. 1 Real-Time Light: Unlike green screens, LED walls emit "emissive lighting." This means the neon city or Martian sunset on the screen actually reflects off the actors’ skin and eyes in real-time, eliminating the need for complex "fixes" in post-production. 1 The Parallax Effect: Through advanced camera tracking, the 3D environment on the wall shifts perspective perfectly as the camera moves. This creates a...