Algorithm Of solving Determinant using Echelon Form
- As we there is general method available for solving determinant of given matrix but that is not efficient. But if we solve that through Echelon form method that it is quite easier to get determinant.
- Because if your able to get Echelon form of given matrix that just multiply diagonal element of that echelon form matrix and that is answer of given matrix determinant.
- As we can see in graph that if you take general algorithm for solving determinant than it take too much time for higher dimension matrix at that time it is efficient to use EF algorithm for solving determinant computerized.
Algorithm Of Finding Inverse Of Matrix Using Row Reduced Echelon Form Method
- Here I have one nice algorithm for solving inverse of square matrix with help of echelon form algorithm which i have available on this blog which is quite efficient than any other method.
Doubly Link List
- As we can see here two nodes are connected among themselves with two links between them.
- For first Node node0, next Node is node1 and node1 is connected with previous link between node0 and node1.
- Here first node is head and the last Node is tail. Both have value null and we same logic which we have in singly link list.
/*
**
Doubly Link List - Generic Class
Shreyas Patel
**
*/
class Node
{
public T Data;
public Node Next;
public Node Pre;
public Node(){}
public Node(T data)
{
Data = data;
Next = Pre = null;
}
}
class Doubly_Link
{
private Node Head;
private Node Tail;
private int SIZE;
public Doubly_Link()
{
Head = Tail = null;
SIZE = 0;
}
public void Add_At_First(T data)
{
Node n = new Node(data);
if(Head==null)
{
Head = n;
Tail = Head;
}
else
{
Head.Pre = n;
n.Next = Head;
Head = n;
}
SIZE++;
}
public void Add_At_Last(T data)
{
Node n=new Node(data);
if(Head==null)
{
Head=n;
Tail=Head;
}
else
{
n.Pre=Tail;
Tail.Next=n;
Tail=n;
}
SIZE++;
}
public void Add_At_Position(T data,int Pos)
{
if(Pos==1)//Means first add
{
Add_At_First(data);
return;
}
if(Pos==SIZE)//Means last add
{
Add_At_Last(data);
return;
}
////Else position add
Node n=new Node(data);
Node Dummy=null;
if(Pos<=SIZE/2)
{
int count = 0;
Dummy = Head;
while(Dummy.Next!=null)
{
count++;
if(count==Pos)
{break;}
else{Dummy=Dummy.Next;}
}
}
else
{
int count = SIZE;
Dummy = Tail;
while(Dummy.Pre!=null)
{
if(count==Pos)
{break;}
else{Dummy=Dummy.Pre;}
count--;
}
}
Node Previous = Dummy.Pre;
n.Pre = Previous;
Previous.Next = n;
Dummy.Pre = n;
n.Next = Dummy;
SIZE++;
}
public void Delete_From_First()
{
if(Head.Next==null)
{
Head=null;Tail=null;
}
else
{
Head=Head.Next;
}
SIZE--;
}
public void Delete_From_Last()
{
if(Tail.Pre==null)
{
Head=null;Tail=null;
}
else
{
Node Previous = Tail.Pre;
Previous.Next = null;
Tail = Previous;
}
SIZE--;
}
public void Delete_From_Position(int Pos)
{
if(Pos==1){Delete_From_First();return;}
if(Pos==SIZE){Delete_From_Last();return;}
Node Dummy=null;
if(Pos<=SIZE/2)
{
int count = 0;
Dummy = Head;
while(Dummy.Next!=null)
{
count++;
if(count==Pos)
{break;}
else{Dummy=Dummy.Next;}
}
}
else
{
int count = SIZE;
Dummy = Tail;
while(Dummy.Pre!=null)
{
if(count==Pos)
{break;}
else{Dummy=Dummy.Pre;}
count--;
}
}
Node Previous = Dummy.Pre;
Node UpNext = Dummy.Next;
UpNext.Pre = Previous;
Previous.Next = UpNext;
SIZE--;
}
public void Display()
{
Node Dummy = Head;
if(Head==null){System.out.println("\nNo data available.\n");return;}
while(Dummy!=null)
{
System.out.println(Dummy.Data);
Dummy = Dummy.Next;
}
}
}
///Main Function
class Doubly_LinkList
{
public static void main(String[] args)
{
System.out.println("\nNow for String.\n");
Doubly_Link d= new Doubly_Link();
d.Add_At_First("Shreyas");
d.Add_At_First("Kaksh");
d.Add_At_First("Mayuri");
d.Add_At_Last("Girishbhai");
d.Add_At_Position("Kiritbhai",3);
d.Display();
//d.Delete_From_First();
//d.Delete_From_Last();
//d.Delete_From_Last();
//d.Delete_From_Last();
//d.Delete_From_Last();
//d.Delete_From_Last();
System.out.println("\nAt delete from position 3.\n");
d.Delete_From_Position(3);
d.Display();
System.out.println("\nAt delete from position 1.\n");
d.Delete_From_Position(1);
d.Display();
System.out.println("\nAt delete from position 2.\n");
d.Delete_From_Position(2);
d.Display();
System.out.println("\nAt delete from position 1.\n");
d.Delete_From_Position(1);
d.Display();
System.out.println("\nAt delete from position 1.\n");
d.Delete_From_Position(1);
d.Display();
System.out.println("\nNow for Integer.\n");
Doubly_Link i = new Doubly_Link();
i.Add_At_First(4);
i.Add_At_First(1);
i.Add_At_First(8);
i.Add_At_Last(2);
i.Add_At_Position(7,3);
i.Display();
System.out.println("\nAt delete from position 3.\n");
i.Delete_From_Position(3);
i.Display();
System.out.println("\nAt delete from position 1.\n");
i.Delete_From_Position(1);
i.Display();
System.out.println("\nAt delete from position 2.\n");
i.Delete_From_Position(2);
i.Display();
System.out.println("\nAt delete from position 1.\n");
i.Delete_From_Position(1);
i.Display();
System.out.println("\nAt delete from position 1.\n");
i.Delete_From_Position(1);
i.Display();
}
}
ArrayList
- Here we are going to implement List program with help of ArrayList Algorithms
- Main function should be Add_At_Position,Delete_From_Position,Display,GetSize,Sorting,etc.
import java.util.*;
class ArrayList
{
private int Item[];
private int position;
private int SIZE;
public ArrayList(int no)//parametrized contractor
{
position=-1;
SIZE=no;
Item=new int[no];
}
public void FirstAdd(int text)//For add member at first
{
position++;
Item[position]=0;
int j;
for(int i=position;i>=0;i--)
{
if(i!=0)
{
j=i;
int temp=Item[j];
Item[j]=Item[j-1];
Item[j-1]=temp;
}
else
{
Item[i]=text;
System.out.println("\nSuccessfully added.\n");
}
}
}
public void LastAdd(int text)//For member at last
{
position++;
Item[position]=text;
System.out.println("\nSuccessfully added.\n");
}
public void PositionAdd(int text)//for add member at given position
{
Scanner x=new Scanner(System.in);
System.out.println("\nThere are this many list in List :- "+(++position));
System.out.print("\nAT which position you want to add :- ");
int pos=x.nextInt();
pos--;
int j;
for(int i=position;i>=pos;i--)
{
if(i!=pos)
{
j=i;
int temp=Item[j];
Item[j]=Item[j-1];
Item[j-1]=temp;
}
else
{
Item[i]=text;
System.out.println("\nSuccessfully added.\n");
}
}
}
public void Display()//display data function
{
System.out.println("\n\n\nLIST OF MEMBERS\n\n\n");
for(int i=0;i<=position;i++)
{
int k=i;k++;
System.out.println(k+" :- "+Item[i]);
}
}
public int Search(int text)//search by value
{
for(int i=0;i<=position;i++)
{
if(text==Item[i])
{
return i+1;
}
}
return -1;
}
public int Searchpos(int pos)//search by position
{
pos--;
if(pos<=position)
return Item[pos];
else
return -1;
}
public void Delete(int number,int pos)//delete function
{
pos--;
if(number==0)
{
position--;
System.out.println("\nSuccessfully Deleted.\n");
return;
}
else if(number==(SIZE-1))
{
position--;
System.out.println("\nSuccessfully Deleted.\n");
return;
}
else
{
for(int i=pos;iItem[j])
{
int Temp=Item[i];
Item[i]=Item[j];
Item[j]=Temp;
}
}
}
}
public int Getpos()
{
return position;
}
}
Generic Class
- In this picture as we can see we have three different clots for driver, if you put slotted than you can fix that pin, if you put crossed on driver than you can fix that pin and so on.
- Just like we have generic class which says that you build class one time and that class for all different object like String, Int, Float etc.
- Suppose, we have one list program define for int object but now you are in need of same list
for String Object or double Object than every time define same thing for different Object is
difficult for us.So what we should do that create generic class.
- Create generic class and use that for different datatypes or Object.How we can implement that
is as below.
Generic class
public class Generic {
private T[] array;
private int size;
private int position;
//constractor
public Generic(int size){
this.size = size;
position = 0;
array =(T[]) new Object[size];
}
public void StoreData(T item){
array[position] = item;
position++;
}
public String GetList()
{
int i;
String list="";
for(i=0;i<=position;i++){
list = array[i]+"__";
}
return list;
}
}
Main class
public class GenericClass {
public static void main(String[] args) {
// TODO code application logic here
Generic glist=new Generic(5);
glist.StoreData("Apple");
glist.StoreData("Banana");
glist.StoreData("Mangoes");
System.out.println("\nList of fruits :- "+glist.GetList());
}
}
LinkedList
- Graph Of linking between Nodes
- Here we are going to implement List program with help of LinkedList Algorithms
- Main function should be Add_At_Position,Delete_From_Position,Display,GetSize,Sorting,etc.
- Main advantage of using link list is that it is dynamic.
- Here first we are going to make Node with help of Node class
import java.util.*;
///Node class for linking between to Data nodes
class Node
{
public int Data;
public Node Next;
public Node(int data)
{
Data=data;
Next=null;
}
public int GetData()
{return Data;}
}
//Linked list class
class LinkedList
{
private Node Head;
private int SIZE;
//contractor
public LinkedList()
{
Head=null;
SIZE = 0;
}
//General function for add data at any position
public void Add_Data(int Pos,int Data)
{
Node Previous_Address=null;
Node Dummy=Head;
int counter=0;
while(true)
{
if(Dummy!=null)
{
counter++;
if(counter==Pos-1)
{
Previous_Address=Dummy;
}
if(counter==Pos)
{
Node n=new Node(Data);
if(Pos==1)
{
n.Next=Head;
Head=n;
}
else if(Pos==GetSize())
{
Dummy.Next=n;
}
else
{
n.Next=Dummy;
Dummy=n;
Previous_Address.Next=Dummy;
}
break;
}
else
{
Dummy=Dummy.Next;
}
}
else
{
if(GetSize()==0)
{
Node n=new Node(Data);
n.Next=Head;
Head=n;
break;
}
}
}
System.out.println("\n\nSUCCESSFULLY ADDED IN LIST\n\n");
SIZE++;
}
//General function for deleting data from any position
public void Delete_Data(int Pos)
{
Node Dummy=Head;
Node Previous_Address=null;
int counter=0;
while(true)
{
if(Dummy!=null)
{
counter++;
if(counter==Pos-1)
{
Previous_Address=Dummy;
}
if(counter==Pos)
{
if(Pos==1)
{
Head=Head.Next;
}
else
{
Dummy=Dummy.Next;
Previous_Address.Next=Dummy;
}
SIZE--;
break;
}
else
{
Dummy=Dummy.Next;
}
}
else
{
System.out.println("\nYOU ENTER WRONG POSITION.\n\nOR DATA IS NOT AVAILABLE AT THAT POSITION.");
break;
}
}
}
//Display function
public void Display()
{
System.out.println("\n\t\t\t-----LIST-----\n\n");
Node Dummy=Head;
while(true)
{
if(Dummy!=null)
{
System.out.println("\t\t\t\t"+Dummy.GetData());
Dummy=Dummy.Next;
}
else
{
break;
}
}
}
//Function for searching element's position by it's value.
public int SearchElementByValue(int Value)
{
Node Dummy=Head;
int counter=0;
while(Dummy!=null)
{
counter++;
if(Dummy.GetData()==Value)
{
return counter;
}
Dummy=Dummy.Next;
}
return -1;
}
//Function for searching position
public int SearchByPosition(int Pos)
{
Node Dummy=Head;
int counter=0;
while(Dummy!=null)
{
counter++;
if(counter==Pos)
{
break;
}
else
{
Dummy=Dummy.Next;
}
}
if(Dummy!=null)
return Dummy.GetData();
else
return -1;
}
//For getting number of elements in list
public int GetSize()
{
return SIZE;
}
//Function for sorting list
public void Sorting()
{
System.out.println("\n\n\t\t\tSORTED LIST");
for(int i=1;i
Algorithm Of Solving Echelon Form Of Matrix
- Here I have one nice algorithm for solving matrix Echelon form which is very helpful finding determinant of matrix, for RREF, for LU factorization etc.
import java.util.Scanner;
public class Matrix {
private int Row; //NO OF ROWS
private int Column; //NO OF COLUMNS
private float [][]Elements;//FOR CARRING ELEMENTS
public Matrix(int No_Row,int No_Column)//PARAMETERIZED CONSTRUCTOR
{
if(No_Row>0 && No_Column>0)
{
Row=No_Row;
Column=No_Column;
Elements = new float[No_Row][No_Column];
}
else
{
write=false;
System.out.println("\nYOU CAN NOT MAKE MATRIX WITH THIS DIMENTIONS.\n");
}
}
public void SET_ELEMENTS_OF_MATRIX()
{
Scanner x=new Scanner(System.in);
for(int i=0;iR;j--)
{
if(Elements[j][i]!=0)
{
Temp=j;
break;
}
}
if(Temp!=-1)
{
count++;
for(int f=0;f
Main Class
public class Main
{
public static void main(String[] args)
{
Matrix M=new Matrix(3,3);
M.SET_ELEMENTS_OF_MATRIX();
M.Algorithms_of_EF();
M.Display();
}
}
Algorithm Of Solving Row Reduced Echelon Form Of Matrix
- As this guy say, no one have time for solving Row Reduce Echelon Form for Matrix.
- Here I have Algorithm for solving RREF for your Matrix
import java.util.Scanner;
public class Matrix {
private int Row; //NO OF ROWS
private int Column; //NO OF COLUMNS
private float [][]Elements;//FOR CARRING ELEMENTS
public Matrix(int No_Row,int No_Column)//PARAMETERIZED CONSTRUCTOR
{
if(No_Row>0 && No_Column>0)
{
Row=No_Row;
Column=No_Column;
Elements = new float[No_Row][No_Column];
}
else
{
write=false;
System.out.println("\nYOU CAN NOT MAKE MATRIX WITH THIS DIMENTIONS.\n");
}
}
public void SET_ELEMENTS_OF_MATRIX()
{
Scanner x=new Scanner(System.in);
for(int i=0;iR;j--)
{
if(Elements[j][i]!=0)
{
Temp=j;
break;
}
}
if(Temp!=-1)
{
count++;
for(int f=0;f=0;k--)
{
float []Array=new float[Column];
for(int l=0;l
Main Class
public class Main {
public static void main(String[] args) {
Matrix M=new Matrix(3,3);
M.SET_ELEMENTS_OF_MATRIX();
M.GET_RREF_FORM();
}
}