Array Index or Key. An Array Is Stored Such That The Position of Each Element Can Be Computed From Its Index Tuple by
Array Index or Key. An Array Is Stored Such That The Position of Each Element Can Be Computed From Its Index Tuple by
A data structure is a storage that is used to store and organize data. It is a way of arranging data on a
computer so that it can be accessed and updated efficiently.
Types of DSA :
Array
Queue
Stack
Linked List
Hash Map
Tree
Graph
Array : it is a data structure consisting of a collection of elements of same type , each identified by at least one
array index or key. An array is stored such that the position of each element can be computed from its index tuple by
a mathematical formula.
System.out.println(array[index]);
Int n = in.nextInt();
Int i;
a[i] = in.nextInt();
System.out.print(a[i]); }
In.close();
}
Searching : it used to find a specific item or element within a collection of data.
Types :
Linear Search
Binary Search
Linear Search code :
import java.util.Scanner;
int c , n , s;
int[] a;
n = in.nextInt();
a = new int[n];
a[c] = in.nextInt();
s = in.nextInt();
if (a[c] == s) {
break;
if (c == n) {
}
Binary Search Syntax :
class Search {
if(r>=l){
if(a[mid] == x){
return mid;
if(a[mid]>x){
return search(a,l,mid-1,x);
return -1;
int[] a = { 2,3,4,10,40};
int n = a.length;
int x=10;
if(result == -1){
else{
Sorting : rearrangement of a given array or list of elements according to a comparison operator on the elements.
Types :
Selection Sort
Bubble Sort
Insertion Sort
Merge Sort
Quick Sort
Heap Sort
Counting Sort
Radix Sort
Selection Sort working : Selection sort works by taking the smallest element in an unsorted array and bringing it to
the front. You'll go through each item (from left to right) until you find the smallest one.
Code :
class Sorting{
int n = a.length;
int min = i;
min = j;
a[min] = a[i];
a[i] = temp;
int n = a.length;
System.out.print(a[i]+" "); }
System.out.println();
int[] a = {64,25,12,22,11};
ob.sort(a);
System.out.println("Sorted array");
ob.print(a);
Bubble Sorting working : Bubble sort is a sorting algorithm that starts from the first element of an array and
compares it with the second element. If the first element is greater than the second, we swap them. It continues this
process until the end of the array.
Code :
public class BubbleSort {
int n = a.length;
int temp = 0;
temp = a[j-1];
a[j-1] = a[j];
a[j] = temp;
int[] a ={3,60,35,2,45,320,5};
sort(a);
Insertion Sort :