Introduction to JAVA

Contributor: Dipal Modi

Java was convinced / developed by James Gosling and Sun Microsystem. In 1991, Sun Microsystem took 18 months for the first version and announced in 1993. Initial name of Java was “OAK”. But, it is renamed to Java in 1995. The primary motivation of Java was the need for the platform independent language i.e. “Write Once, Run Anywhere.” Java enables to build platform independent

read more

C/C++/Java for implementing the Depth First Search Algorithm

Using C/C++/Java for implementing the Depth First Search Algorithm

Code:

import java.io.*; class DepthFirst { static void dfs1(int a[ ][ ], int m[ ], int i, int n) { int j; System.out.println(“\t” + (i+1)); m[i] = 1; for(j=0; j<n; j++) if(a[i][j]==1 && m[j]==0) dfs1(a,m,j,n); } public static void main(String args[]) throws IOException { int  n, i, j; System.out.println(“How many vertices do you want ? : “); BufferedReader br= new

read more

C/C++/Java for implementing the Breadth First Search Algorithm

Write a program using C/C++/Java for implementing the Breadth First Search Algorithm

Code:

import java.io.*; class BreadthFirst { public static void main(String args[]) throws IOException { int i,n,j,k; System.out.println(“How many nodes do you want ?:”) ; BufferedReader br= new BufferedReader (new InputStreamReader(System.in)); n =Integer.parseInt(br.readLine()); int q[] = new int[10]; int m[] = new int[10]; int a[][] = new int[10][10]; for (i=0; i<10; i++) { m[i] = 0; }<br

read more

To demonstrate that a fuzzy system is a structured numerical estimator

A program in Lisp to demonstrate that a fuzzy system is a structured numerical estimator-using example of controlling an inverted pendulum

Assume: Enter two strings for angle of pendulum θ and angular velocity Δθ. Convert them into strings of fuzzy using five fuzzy set values NM (Negative medium), NS (Negative Small), ZE(Zero), PS (Positive Small) and PM ( Positive Medium). Apply FAM rules to find the output values v, the current to the motor control of the pendulum to each input set of (θ, Δθ). Create a string of fuzzy output values of the current.

Code:

(defun FAM (angpen anguvel) (cond ( ( equal angpen “NM”)<br

read more

A program in Lisp to perform roulette wheel selection

A program in Lisp to perform roulette wheel selection

Assume: Enter a population of binary strings. Consider fitness value as the number of repetitions of a specified bit (say 1) in the string.

Code:

(defun wheel(list1 list2 list3 list4) (setq llist1 (funlist list1)) (setq llist2 (funlist list2)) (setq llist3 (funlist list3)) (setq llist4 (funlist list4)) (print “The highest fitness of string is: “) (setq m1(max llist1 llist2 llist3 llist4)) (print m1) (if (= m1 llist1)(print “First

read more

A program in Lisp to demonstrate the crossover genetic operator

A program in Lisp to demonstrate the crossover genetic operator

Assume: Enter population of binary strings. Perform crossover based on a random crossing site value. Consider fitness value as the number of repetitions of specified bit in the string. Perform the evolution for a specified number generation.

Source Code:

(defun crossover(List1 List2)
(setq cnt 0)
(setq A ‘())
(setq B ‘())
(setq cpt (random(length List1)))

(loop (when (and (equal (first List1) nil) (equal (first List2) nil))(return)) (if (<= cpt cnt) (block blk1<br

read more

A program in Lisp to implement decision tree

A program in Lisp to implement decision tree

Assume:

Enter a decimal string of repeated entries of suitable length. Apply binary decision tree to find repetitions of each decimal digit in the string.

Code:

(defun MyTree(mylist) (setq CntrArr 0) (setq ResArr (make-array ‘(1 10))) (loop (when (equal CntrArr 10) (return)) (setf (aref ResArr 0 CntrArr) 0) (incf CntrArr) ) (loop (when (equal (first mylist) nil) (return)) (if (<= (first mylist) (/ 10 2)) (if (< (first mylist

read more