-->

Thursday, January 30, 2014

Algorithmic Notation in DataStructure, C Programming

Algorithm is a sequential, finite non-complex step-by-step solution, written in English like statements, to solve a problem. Here we can consider some points about the algorithmic notation, which are helpful in writing algorithms to understand the basic data structure operations clearly. Algorithm writing is first step in implementing the data structure.

1.Name of the algorithm and parameters: Name of the algorithm may be written in capital letters and the name is chosen according to the problem or operation specification. The name may depict the work done by algorithm is called can be given as parameter names immediately followed by name of the algorithm in a pair of parenthesis.
           e.g.     TRAVERSELIST (LIST, SIZE)
                       LINEARSEARCH (LIST, SIZE, ITEM)

The name of algorithm serves the purpose of start for algorithm and it is the heading of algorithm, and further statements of algorithm are written after the heading.
s using any of the programming languages.

 2.Comments: The comments that are necessary to explain the purpose of algorithm or the things used in an algorithm in detail as non-executable statements of a program are written in a pair of square brackets.
            e.g.       LINEARSEARCH (LIST, SIZE, ITEM)
                         [Algorithm to search an ITEM in the LIST of size SIZE].

3.Variable names: The variable names are written in capital letters without any blank spaces within it. Underscore (_) may be used in case of multi-word names to separate the words. The name should start with an alphabet and may have any number of further alphabets or numbers.
            e.g.       LIST, SIZE, ITEM, NUM1, FIRST_NUM etc.
                         Single letter names like I, J, K can be used for index numbers.

4.Assignment operator:  To set the values of a variable an assignment operator—may be used or = sign along with SET and value may be used. In this book—is used.
           e.g. SET COUNT=0, COUNT+1 etc.
           The second type is most commonly used.

5.Input and Output: To input the value of a variable Read: and to output the values of variable Write: are used. The message to be outputted may be placed between single quotes ‘ ‘.
             e.g.   Read:  NUM
                       Write: The Value is’, SUM
                       Write: NUM etc.


6.Sequential statements are written one after the other, usually in separate lines. If two statements are to be written on the same line they may be separated by means of comma,. Arithmetic operators +,-, *, /, % can be used for addition, subtraction, multiplication, division, mod operation respectively, to write arithmetic expressions.
               e.g.   SUM—0; NUM—15
                         SUM—SUM+NUM
                         Write: ‘Sum is’, SUM

7.Selective statements or conditional statements can be written using If-Then:,  If-Then:   Else:. The relational operators >,>=<,<=,<>,= can be used for greater than, greater than or equal, less than, less than or equal, not equal, equal respectively. For logical connection of two conditions AND, OR can be used. NOT can be used to negate the condition.



8.Repetitive or Iterative statements can be written between Repeat For … [Endo For] or Repeat While …[End of While]. Repeat For is used for the purpose of repeating the statements for fixed number of times    where as Repeat while is used to repeat the statements till a condition is true.


9.Exit is used terminate the Algorithm and Return may be used to return a value from the algorithm.

Or   


10.The array elements can be referred by means of the Name of the array and subscript in a pair of square brackets. The fields of a static struct can be referred by means of placing the name of the struct variable, a. (dot) and field name. The fields of a dynamic struct can be referred by means of placing the name of struct variable,        (arrow) and field name. The arrow operator is framed as a combination of – (minus) and > (greater than operators).
           e.g. LIST[1], LIST[I], LIST[J] etc.
                  NODE--->LINK, NODE--->INFO etc.
                  EMP.ENO, EMP.SALARY etc.      

Wednesday, January 29, 2014

Character and Boolean Data Types used in Java Programming

Java programming have some more data types for storage of single character and even true/false values. These data types are called Character and Boolean in programming language.

Character Type

The character data type (char) data type of Java is used to store characters. A character in Java can represent all ASCII (American standard Code for Information Interchange) as well as Unicode characters.

The Unicode character representation code can represent nearly all languages of world such as Hindi, English, German, French, Chinese, and Japanese etc. And because of Unicode character, size of char data type of Java is 16 bits i.e., 2 bytes in contrast to 1 byte characters of other programming languages that support ASCII.

  • Type: Char (Single Character)
  • Size:   16bits (2 bytes)
  • Range: 0 to 65536

Boolean Type

Another type of the primitive data type is Boolean. A Boolean value can have one of two values: true or false. So this data type is used to store such type of values.

In a Java program, the words true and false always mean these Boolean values. The data type Boolean is named after a nineteenth century mathematics- George Boole, who discovered that a great many things can be done with true/false value. A special branch of algebra Boolean algebra, is based on Boolean values.

  • Type: Boolean (Logical values)
  • Size:   reserve 8 bits uses 1 bit
  • Range: true or false

Following tables lists examples of various data items of different data types. Here are some examples of literal values of various primitive types:

Character and Boolean Data Types used in Java Programming


Draw graphics in ASP.NET

You can draw graphics on browser window using Graphics class. This class exists in System.Drawing namespace. It provide different types of graphics methods, such as DrawArc, DrawImage, DrawIcon, DrawLine and many more. Graphics class hold pen instance for creating graphics onto the screen.

Algorithm Behind the drawing

Step-1 : First define the graphics area on browser window using Bitmap class.
Step-2 : Create instance of Graphics class and initialize with Bitmap class instance.
Step-3 : Create Pen class object with specified color and width.
Step-4 : Create starting point and ending point using Point class.
Step-5 : Draw graphics and save into Bitmap instance.

Lets take an simple example of drawing Line , Rectangle in asp.net

 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    <asp:Image ID="Image1" runat="server" Height="83px" Width="95px" />
    </form>
</body>
</html>

CodeBehind Code Draw Rectangle

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Drawing.Imaging;

public partial class Default3 : System.Web.UI.Page
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
         Bitmap bmp = new Bitmap(500,200);  
        Graphics g = Graphics.FromImage(bmp);  
        g.Clear(Color.Green);
        Pen p1 = new Pen(Color.Orange, 3);

        g.DrawRectangle(p1, 20, 20, 80, 40);

        string path = Server.MapPath("~/Image/rect.jpeg");
        bmp.Save(path, ImageFormat.Jpeg);

        Image1.ImageUrl = "~/Image/rect.jpeg";


        g.Dispose();
        bmp.Dispose();

    }
}

Code Generating the following output

Draw Rectangle in asp.net

CodeBehind Code for Draw Line

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Drawing.Imaging;

public partial class Default3 : System.Web.UI.Page
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
         Bitmap bmp = new Bitmap(500,200);  
        Graphics g = Graphics.FromImage(bmp);  
        g.Clear(Color.Green);
        Pen p1 = new Pen(Color.Orange, 3);
        
        g.DrawLine(p1, 20, 20, 100, 100);
        string path = Server.MapPath("~/Image/line.jpeg");
        bmp.Save(path, ImageFormat.Jpeg);

        Image1.ImageUrl = "~/Image/line.jpeg";


        g.Dispose();
        bmp.Dispose();

    }
}

Code Generating the following output

Draw line in asp.net

Operations on Data Structures, C programming

Basically there are six operations one can do on the data structures. They are Traversing, Searching, Sorting, Insertion, Deletion and Merging.

1.  Traversing: Basically to process a data structure if every element of data structure is visited once and only once, such type of operation is called as TRAVERSING. For example to display all the elements of an array, every element is visited once and only once, so it is called as traversing operation.
            Suppose we have an array of 20 students’ average makes, and if we need to calculate the average of group, we visit (read) each individual average and accumulate (sum) them. Then we will find the array are visited once and only once. Then it is traversing of an array.

2.  Insertion: When an element of the same type is added to an existing data structure, the operation we are doing is called as Insertion operation. The element can be added anywhere in the data structure in the data structure. When the element is added in the end it is called as special type addition, Appending. In case of adding an element to the data structure we may come across ‘Overflow’ If the size of the data structure is fixed and it is full, then if we try insertion operation on the data structure it is said to be overflow of data structure or the data structure is full.

           Suppose we have an array of size 20 used to store marks obtained by the students in Computer Science subject. If we have already added 15 students’ marks according to an ascending order, then we can add another student marks at appropriate place, by shifting the already stored element accordingly. Then it is called Insertion operation.

3.  Deletion: When an element is removed from the data structure, the operation we are doing is called as Deletion operation. We can delete an element  from data structure from any position. In case of deleting an element from the data structure we may come across ‘Underflow’. If no elements are stored in the data structure, then if we try deletion operation on the data structure it is said to be underflow of data structure or data structure is empty.

         Suppose we have an array of size 20 used to store marks obtained by the students in Computer Science subject. If we have already added 15 student s’ marks according to an ascending order, then we can delete one student’s marks from any place, by shifting the already  stored elements accordingly. Then it is called Deletion operation.

4.  Searching: When an element is checked for its presence in a data structure, that operation we are doing is called as ‘searching’ operation. The element that is to be searched is called as key element. The searching can be done using either ‘linear search’ or ‘binary search’.

        Suppose we have an array of size 10 and assume elements stored are 1,2,3,23,34,54,56,21,32,33 and assume we want to search the number 23. So here the number ‘23’ is key element. The key is searched through the array starting from the first element till end. When it is compared with the fourth element in it is present in the list (array) of numbers. So search is successful. This type of searching is called as Linear Search because the last element. In order to apply linear search, the list may not be in any particular order but when binary search is applied the list must be an ordered one.

5.  Sorting: When all the elements of array are arranged in either ascending or descending order, the operation used to do this process is called as Sorting. The Sorting can be done using Insertion, Selection or Bubble sort techniques.
           Suppose we have an array of size 10 and assume elements stored are 1,2,3,23,34,54,56,21,32,33. The elements of the array are not in proper order. If they are arranged in ascending order the list (array) becomes 1,2,3,21,23,32,34,54,56.

6.  Merging: When two lists List A and List B of size M and N respectively, of same type of elements, clubbed or joined to produce the third list, List C of size (M+N), and the operation done during the process is called as Merging.

           Suppose we have a list of size 6, containing the elements 1,2,3,4,71,87 and we have another list of size 5, containing the elements 9,13,21,65,67. Here both the lists are in ascending order. We can produce the third list of size 11 that will also be in ascending order, containing the element 1,2,3,4,9,13,21,65,67,71,87. The third list is called the merged list of first and second lists. In order to merge two lists into single list one needs to compare each element from both the lists and one of them will   go the merged list.

Tuesday, January 28, 2014

Type of Fractional Numeric Data Types used in Java Programming

The integral numbers covered in earlier article could store only whole numbers i.e. they could not have decimal values. Fractional data types can store fractional numbers i.e. numbers having decimal points. There are also called floating-point data types.

Following list displays various floating-point data types available in Java, along with their ranges.

  • Float (Size – 32 bits), Single precision having range -3.4E+38 to +3.4E +38. This data type precision up to 6 digits like temperatures, currency, and percentage or may be some length.
  • Double (Size - 64 bits), Double precision having range -17E+308 to 1.7E+308. This data type precision up to 15 digits like large numbers or high precision, such as for astronomy or subatomic physics.

Now depending upon your requirements for the decimal precision of the data, you can select from float or double types.

For example, you can store the salary values of an employee using a data variable of the float type. To store decimal values with a higher degree of precision, such as values calculated using the functions, sin() and sqrt(), you see the double data type.

By default, Java treats fractional numbers as of double data type e.g. if you write 0.123, it will treated as a double value. To explicitly specify it to be of float type, use suffix F or f i.e. write 1.234f or 1.234F. Similarly if you use suffix d or D, it means double i.e., 1.234D or 1.234d means it is a double value.

How to Querying Data using Joins in Sql Programming

In a normalized database, the data to be viewed can be stored in multiple tables. When you need to view data from related tables together, you can query the data by joining the tables with the help of common attributes. You can also use subqueries where the result of a query is used as an input for the condition of another query.

This article discusses about how to query data from multiple tables by applying various types of joins, such as an inner join, outer join, cross join, equijoin, or self-join.

Querying Data by Using Joins

As a database developer, you may need to retrieve data from more than one table together as a part of a single result set. In such a case, different columns in the result set can obtain data from different tables. To retrieve data from multiple tables, the SQL Server allows you to apply joins. Joins allow you to view data from related tables in a single result set. You can join more than one table based on common attribute.

Depending on the requirements to view data from multiple tables, you can apply different types of joins listed below:

Inner Join

An inner join retrieves records from multiple tables by using a comparison operator on a common column. When an inner join is applied, only rows with values satisfying the join condition in the common column are displayed. Rows in both tables that do not satisfy the join condition are not displayed.

A join is implemented by using the SELECT statement, where the SELECT list contains the name of the columns to be retrieved from the tables. The FROM clause contains the names of the tables from which combined data is to be retrieved. The WHERE clause specifies the condition, with a comparison operator, based on which the tables will be joined.

The syntax of applying an inner join in the SELECT query is:

SELECT column_name, column_name [, column_name]
FROM table1_name JOIN table2_name
ON table1_name.ref_column_name join_operator
Table2_name.ref_column_name

Where
  • Table1_name and table2_name are the name of the tables that are joined join_operator is the comparison operator based on which the join is applied
  • Table1_name.ref_column_name and table2_name.ref_column_name are the names of the columns on which the join is applied.
Whenever a column is mentioned in a join condition, the column should be referred by prefixing it with the table name to which it belongs or with a table alias. A table alias is a name defined in the FROM clause of the SELECT statement to refer to the table with another name or to uniquely identify the table.

The following query displays the Employee ID and Title for each employee from the Emoloyee table and the Rate and PayFrequency columns from the EmployeePayHistory table

SELECT e.BusinessEntityID,e.JobTitle, eph.Rate, eph.PayFrequency
from HumanResources.Employee e
JOIN HumanResources.EmployeePayHistory eph
ON e.BusinessEntityID = eph.BusinessEntityID

In the preceding query, the Employee and EmployeePayHistory tables are joined on the common column, ID. The query also assigns e as the alias of the Employee table and eph as the alias of the EmployeePayHistory table. The column names are also listed with the table alias names.

How to Querying Data using Joins in Sql Programming

Based on the relationship between tables, you need to select the common column to set the join condition. In the preceding example, the common column is ID, which is the primary key of the Employee table and the foreign key of the EmployeePayHistory table.

Observe the result set after the join. The record of the employee with D as 1 from the Employee table is joined with the record of the employee with ID as 1 from the EmployeePayHistory table.

The transfer fails if a user tries to upload a file in ASP.NET

Size restriction protects your web application from malicious users. They will upload numerous large files to your Web server. So Developers take the default size limitation is 4MB. The transfer fails if a user tries to upload a file that is larger then 4096kb. Now, if you want to change the default size limitation, you make some changes in either the root we.config file , which is found in that path (c:\Windows\Microsoft.NET\Framework\v4.0.xx\config) or in your application's web.config file.

How to Increase uploaded file size 

<httpRuntime> section takes different properties but two properties , The maxRequestLength and executionTimeout properties are very nice. If you want to change the default uploaded file size then you must to change the value of maxrequestLength. It take the size in KiloBytes. Lets take a simple syntax here.

maxRequestLength= 11000

The user can upload around 10mb files using file upload control. Also must to change the executionTimeout property, This property sets the time ( in seconds ) for a request to attempt to execute to the server before ASP.NET shuts down the request. try this into your web.config file

<system.web>
    <httpRuntime executionTimeout ="300" maxRequestLength ="11000"/>
</system.web>
© Copyright 2013 Computer Programming | All Right Reserved