Posts

Algorithm I

Image
This is the first post in Algorithms.From this post I am looking forward to write about sorting algorithms. Sorting Algorithms What are Sorting Algorithms A sorting algorithm is an algorithm that puts elements of a list in a certain order. The most-used orders are numerical order and lexicographical order. Efficient sorting is important for optimizing the use of other algorithms which require input data to be in sorted lists. Some main sorting algorithms are : Insertion Sort. Selection Sort. Bubble Sort Merge Sort. Counting Sort. Quick Sort. Radix Sort.  Let's see about the first sorting with more details. Insertion Sort Insertion sort is a simple sorting algorithm that is relatively efficient for small lists and mostly sorted lists, and often is used as part of more sophisticated algorithms. It works by taking elements from the list one by one and inserting them in their correct position into a new sorted list. In arrays, the new list and the remaini...

The stack abstract data type

Image
This post is the second post of the data structures.This post will be cover the main topic in data structures.  The stack abstract data type. First let's discuss about the first topic. The stack abstract data type The stack abstract data type is defined by the following structure and operations. The stack ordered "Last in first out" mechanism. The stack operations are given below. stack( ) creates a new stack that is empty. It needs no parameters and returns an empty stack. push( item ) adds a new item to the top of the stack. It needs the item and returns nothing. pop( ) removes the top item from the stack. It needs no parameters and returns the item.The stack  is not modified. peek( ) returns the top item from the stack but does not remove it. It needs no parameters. The stack is not modified. isEmpty( ) tests to see whether the stack is empty. It needs no parameters and returns a Boolean. size( ) returns the number of items on th...

Abstract Data Types

Image
This is the first post of Data Structures. Linear Data Structures We will begin four study of Data Structures by considering four simple but very powerful concepts. Stack Queue Deque (double ended queue) List  The above data collections whose items are ordered depended on how they are added or removed. Once an item is added, it stays in that position relative to the other elements that came before and came after it. Collections such as these are often referred to as linear data structures . Let's consider about the first simple Data Structure. Stack ( push down stack ) A stack  is an ordered collection of items where the addition of new items and the removal of existing items always takes place at the same end. This end is commonly referred to as the “top” The end opposite the top is known as the “base”. The basic rule in the stack is The most recently added item is the one that is in position to be removed first. This ordering principle is sometimes calle...

while loop and do-while loop

Image
After long time had a time to write a blog post. Today I will  teach u about while loop and do-while loop in java. Firstly i will explain u about the while loop while loop The while statement continually a block of statements while a particular condition is TRUE. Its syntax can be expressed as : while ( expression ){          statement(s); }   Example 1 : while loop you can also make a infinite loop also using the while loop. while ( true ){       // your code comes here } i will explain a another simple code with while loop Example 2 : while loop do-while loop Now I will explain u about the do-while loop. The java programming language also provides a do-while statement , which can be expressed as follows. do{      statement ( s ) }while ( expression ); The difference between do-while and while is that do-while evaluates its expres...

Loops

Image
A simple introduction about Loops in java programming There are mainly three types of loops.                  1.For loop                  2.While loop                  3.Do While loop As in the name the "Loop" means a cycle ,which it stops after a certain boolen condition. In this post i will describe about the For loop. Here is a small Example for the for loop. class Myjava {     public static void main(String args[]){         for(int x=0 ; x<5 ; x++){         System.out.print("kamal-->");         System.out.println(x);         }     } } out put of the ...

Methods

A simple introduction to the Methods Declaring a Method A Small Example for declaring a method. void count( ){ } I explain the above method. void   - The keyword "void" is the return type of the method. count - Name of the method. ( )      - Inside these brackets we can have the method parameters. A simple programme for explain methods Example 1 -     class Test{     int x= 8;     int y=3;     void Add(){         System.out.println("Addition :"+(x+y));     }     void Sub(){         System.out.println("Subtraction :"+(x-y));     }     void Multiply(){         System.out.println("Multiplication :"+(x*y));     }     void Divide(){         System.out.println("Division :"+(x/y));     }     public static void main(String args[ ]){...

variables

A simple introduction to the variables in a programming language Today i will write about the variables in a programming language. There are two types of variables           1.Primitive variables           2.Reference Variables 1. Primitive Variables byte                    short int long float double boolean char a simple programme to get an idea about primitive variables. Example 1 - public class Test1{        public static void main(String args[]){            int x; // declare a int type variable(variable name is x)            x=10; // initialize the variable x to value 10            System.out.println("The value of the x :"+x);            x=20; // reinitialize the variable         ...