Tuesday, 11 October 2016

Why jQuery?


·        It’s open source, and the project is licensed under an MIT and a GNU General Public License (GPL)     license.

·        It’s small (18 KB minified) and zipped (114 KB, uncompressed).

·    It’s incredibly popular, which is to say it has a large community of users and a healthy amount of contributors who participate as developers and evangelists.

·        It normalizes the differences between web browsers so that you don’t have to.

·        It’s intentionally a lightweight footprint with a simple yet clever plugin architecture.

·        Its repository of plugins is vast and has seen steady growth since jQuery’s release.

·        Its API is fully documented, including inline code examples, which in the world of JavaScript libraries is a luxury. Heck, any documentation at all was a luxury for years.

·        It’s friendly, which is to say it provides helpful ways to avoid conflicts with other JavaScript libraries.

·     Its community support is actually fairly useful, including several mailing lists, IRC channels, and a freakishly insane amount of tutorials, articles, and blog posts from the jQuery community.

·        It’s openly developed, which means anyone can contribute bug fixes, enhancements, and development help.

·        Its development is steady and consistent, which is to say the development team is not afraid of releasing updates.

·        Its adoption by large organizations has and will continue to breed longevity and stability (e.g., Microsoft, Dell, Bank of America, Digg, CBS, Netflix).

·        It’s incorporating specifications from the W3C before the browsers do. As an example, jQuery supports a good majority of the CSS3 selectors.

·        It’s currently tested and optimized for development on modern browsers (Chrome 1, Chrome Nightly, IE 6, IE 7, IE 8, Opera 9.6, Safari 3.2, WebKit Nightly, Firefox 2, Firefox 3, Firefox Nightly).
·        It’s downright powerful in the hands of designer types as well as programmers. jQuery does not discriminate.

·        Its elegance, methodologies, and philosophy of changing the way JavaScript is written is becoming a standard in and of itself. Consider just how many other solutions have borrowed the selector and chaining patterns.

·        Its unexplainable by-product of feel-good programming is contagious and certainly unavoidable; even the critics seem to fall in love with aspects of jQuery.

·        Its documentation has many outlets (e.g., API browser, dashboard apps, cheat sheets) including an offline API browser (AIR application).

·        It’s purposely bent to facilitate unobtrusive JavaScript practices.
·        It has remained a JavaScript library (as opposed to a framework) at heart while at the same time providing a sister project for user interface widgets and application development (jQuery UI).

·        Its learning curve is approachable because it builds upon concepts that most developers and designers already understand (e.g., CSS and HTML).

Sunday, 9 October 2016

Understanding HTML, XHTML, and HTML5


  • ·        HTML is an acronym for Hypertext Markup Language, which is the language we have used to create webpages since the first webpages arrived on the web.
  • ·        HTML roots are from an older markup language that was used in document publishing, called SGML (Standard Generalized Markup Language).
  • ·        Like SGML, HTML uses tags to provide formatting features such as <b>this is bold</b>, which would cause the text within the starting b tag and ending b tag to render as bolded text.
  • ·        Notice the difference between the first and second tag; the second tag has a slash (/) to indicate that it’s an ending tag. Many but not all HTML tags have a matching end tag.
  • ·        HTML tags such as <br> and <img> did not have ending tags because the <br> just rendered a line break, and the <img> tag just rendered an image.
  • ·        One interesting aspect of HTML and its relationship with browsers was that browsers were designed to be backward compatible and forward compatible. Creating a browser that is backward compatible is relatively easy because the problem domain is known, but how is forward compatibility accomplished? Browsers were created to ignore tags that they didn’t recognize.
  • ·        For example, if a browser came across a <xyz> tag that it didn’t recognize, it would skip over the tag as though it didn’t exist. Although HTML served its purpose for quite some time, people wanted more.
  • ·        Another evolving technology, called XML (eXtensible Markup Language), was becoming popular.
  • ·        XML looks a lot like HTML because both languages use tags. However, there are several big differences.
  • ·        First, XML always requires matching end tags for every tag, although you can use a shortcut notation to denote a starting tag and ending tag together.
  • ·        Another difference is that HTML has a very specific set of tag names, and each of these tags denotes a formatting feature that is to be applied to the rendered webpage.
  • ·        XML doesn’t have a defined set of tag names, so you create your own tag names, and the tags can represent anything.
  • ·        XML tags are typically metadata tags: tags that describe the data that is within the tag. Although there are many other differences, one other large difference is that XML uses XML Schema Definition (XSD) technology, which validates the format of an XML document to ensure that all aspects of a document are valid before processing the XML document.
  • ·        HTML’s lack of rigid structure prevented the creation of a technology such as XSD that could validate HTML documents.
  • ·        The World Wide Web Consortium, also known as W3C (http://ww.w3c.org), is responsible for developing open standards for the web. The W3C introduced XHTML to solve the problems in HTML, which was up to version 4.
  • ·        XHTML is an XML-based specification that tightened the HTML specification to make HTML adhere to the XML rules that describe a well-formed document, such as having a matching end tag for each starting tag.
  • ·        This meant that XHTML documents could be validated by using XSD files and could be edited by using XML tools.
  • ·        Although XHTML solved some problems, other problems still needed a solution. There was a need for an increasing amount of multimedia on the web. Companies wanted the flashiest (pun intended) website.
  • ·        Cascading Style Sheets (CSS) provided support for adding styles such as colors and fonts consistently across a website, but companies wanted more. They wanted their webpages to be highly interactive, with video and animations.
  • ·        Browsers added programmable support bzy providing JavaScript, but early versions of JavaScript were slow and difficult to program.
  • ·        The browsers became extensible by providing an application programming interface (API) that would allow third parties to create plug-ins that could run in the browser’s environment. One such plug-in is Flash, which has a very large installed base.
  • ·        Flash provides a development environment that can be used to create a rich user experience. Although third-party plug-ins solved the immediate need for technology to create flashy websites, there was still a need for tighter integration of multimedia with the browser, especially on small devices.
  • ·        HTML5 does not originate from XHTML; HTML5 originates from HTML 4.01. As a rule, however, applying XHTML rules to your HTML5 will make your webpage more compliant with a wider variety of browsers and webpage readers, generators, and validators.
  • ·        HTML5 represents a reinvented HTML, CSS, and JavaScript in a way that solves the need for rich, interactive websites that can play audio and video and support animations from within the browser without the need for plug-ins. HTML5 contains most of the tags from HTML 4.01, but many of the tags have been redefined to be semantic tags.



Friday, 7 October 2016

JavaScript Introduction

Java Script:

JavaScript started life as LiveScript, but Netscape changed the name, possibly because of the excitement being generated by Java.to JavaScript. JavaScript made its first appearance in Netscape 2.0 in 1995 with a name LiveScript.
JavaScript is a lightweight, interpreted programming language with object-oriented capabilities that allows you to build interactivity into otherwise static HTML pages.
The general-purpose core of the language has been embedded in Netscape, Internet Explorer, and other web browsers
The ECMA-262 Specification defined a standard version of the core JavaScript language.
JavaScript is:

  • JavaScript is a lightweight, interpreted programming language
  • Designed for creating network-centric applications
  • Complementary to and integrated with Java
  • Complementary to and integrated with HTML
  • Open and cross-platform

Client-side JavaScript:


  • Client-side JavaScript is the most common form of the language. The script should be included in or referenced by an HTML document for the code to be interpreted by the browser.
  • It means that a web page need no longer be static HTML, but can include programs that interact with the user, control the browser, and dynamically create HTML content.
  • The JavaScript client-side mechanism features many advantages over traditional CGI server-side scripts. For example, you might use JavaScript to check if the user has entered a valid e-mail address in a form field.
  • The JavaScript code is executed when the user submits the form, and only if all the entries are valid they would be submitted to the Web Server.
  • JavaScript can be used to trap user-initiated events such as button clicks, link navigation, and other actions that the user explicitly or implicitly initiates.


Advantages of JavaScript:

The merits of using JavaScript are:

  • Less server interaction: You can validate user input before sending the page off to the server. This saves server traffic, which means less load on your server.
  • Immediate feedback to the visitors: They don't have to wait for a page reload to see if they have forgotten to enter something.
  • Increased interactivity: You can create interfaces that react when the user hovers over them with a mouse or activates them via the keyboard.
  • Richer interfaces: You can use JavaScript to include such items as drag-and-drop components and sliders to give a Rich Interface to your site visitors.


Limitations with JavaScript:


  • We can not treat JavaScript as a full fledged programming language. It lacks the following important features:
  • Client-side JavaScript does not allow the reading or writing of files. This has been kept for security reason.
  • JavaScript can not be used for Networking applications because there is no such support available.
  • JavaScript doesn't have any multithreading or multiprocess capabilities.


Thursday, 6 October 2016

Basic Sorting Techniques

Sorting:
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 such as search and merge algorithms, which require input data to be in sorted lists; it is also often useful for canonicalizing data and for producing human-readable output.

Bubble sort :
Bubble sort, also referred to as sinking sort, is a simple sorting algorithm that works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items and swapping them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted. The algorithm gets its name from the way smaller elements "bubble" to the top of the list. Because it only uses comparisons to operate on elements, it is a comparison sort. Although the algorithm is simple, most of the other sorting algorithms are more efficient for large lists.


Bubble sort has worst-case and average complexity both О(n2), where n is the number of items being sorted. There exist many sorting algorithms with substantially better worst-case or average complexity of O(n log n). Even other О(n2) sorting algorithms, such as insertion sort, tend to have better performance than bubble sort. Therefore, bubble sort is not a practical sorting algorithm when n is large.Performance of bubble sort over an already-sorted list (best-case) is O(n).

Selection Sort:
The selection sort is a combination of searching and sorting. During each pass, the unsorted element with the smallest (or largest) value is moved to its proper position in the array. The number of times the sort passes through the array is one less than the number of items in the array. In the selection sort, the inner loop finds the next smallest (or largest) value and the outer loop places that value into its proper location.

                                    
Selection sort is not difficult to analyze compared to other sorting algorithms since none of the loops depend on the data in the array. Selecting the lowest element requires scanning all n elements (this takesn − 1 comparisons) and then swapping it into the first position. Finding the next lowest element requires scanning the remaining n − 1 elements and so on, for (n − 1) + (n − 2) + ... + 2 + 1 = n(n − 1) / 2 Θ(n2) comparisons. Each of these scans requires one swap for n − 1 elements.


Insertion Sort :
Insertion sort is a simple sorting algorithm, it builds the final sorted array one item at a time. It is much less efficient on large lists than other sort algorithms.

Advantages of Insertion Sort:
1) It is very simple.
2) It is very efficient for small data sets.
3) It is stable; i.e., it does not change the relative order of elements with equal keys.
4) In-place; i.e., only requires a constant amount O(1) of additional memory space.
Insertion sort iterates through the list by consuming one input element at each repetition, and growing a sorted output list. On a repetition, insertion sort removes one element from the input data, finds the location it belongs within the sorted list, and inserts it there. It repeats until no input elements remain.



The best case input is an array that is already sorted. In this case insertion sort has a linear running time (i.e., Θ(n)). During each iteration, the first remaining element of the input is only compared with the right-most element of the sorted subsection of the array. The simplest worst case input is an array sorted in reverse order. The set of all worst case inputs consists of all arrays where each element is the smallest or second-smallest of the elements before it. In these cases every iteration of the inner loop will scan and shift the entire sorted subsection of the array before inserting the next element. This gives insertion sort a quadratic running time (i.e., O(n2)). The average case is also quadratic, which makes insertion sort impractical for sorting large arrays. However, insertion sort is one of the fastest algorithms for sorting very small arrays, even faster than quicksort; indeed, good quicksort implementations use insertion sort for arrays smaller than a certain threshold, also when arising as subproblems; the exact threshold must be determined experimentally and depends on the machine, but is commonly around ten.

Quick Sort :
Quick sort algorithm is developed by C. A. R. Hoare. Quick sort is a comparison sort. The working of  quick sort algorithm is depending on a divide-and-conquer strategy. A divide and conquer strategy is  dividing  an array  into two sub-arrays. Quick sort is one of the fastest and simplest sorting algorithm. The complexity of quick sort in the average case is  Θ(n log(n)) and in the  worst case is Θ(n2).
Code description:
In quick sort algorithm pick an element from array of elements. This element is called the pivot. Then compare the the values from left to right until a greater element is find then swap the values. Again start comparison from right with pivot. When lesser element is find then swap the values. Follow the same steps until  all elements which are less than the pivot come before the pivot and all elements greater than the pivot come after it. After this partitioning, the pivot is in its last position. This is called the partition operation. Recursively sort the sub-array of lesser elements and the sub-array of greater elements. 

Working of quick sort algorithm:
Input:
12 9 4 99 120 1 3 10 13



Output:1 3 4 10 12 13 99 120




Dhtml

What is dynamic html?
DHTML is the combination of several built-in browser features in fourth generation browsers that enable a web page to be more dynamic.
DHTML is NOT a scripting language (like JavaScript or VBscript), but a browser feature- or enhancement- that makes the browser dynamic
It uses a host of different technologies - JavaScript, VBScript, the Document Object Model (DOM), layers, cascading stylesheets - to create HTML that can change even after a page has been loaded into a browser
It is considered to be made up of
HTML
Cascading Style Sheets (CSS)
Scripting language
All three of these components are linked via Document Object Model (DOM)
DOM is the interface that allows scripting languages to access the content, style, and structure of the web documents and change them dynamically


Difference between HTML and DHTML


  • HTML is a mark-up language, while DHTML is a collection of technology.
  • DHTML creates dynamic web pages, whereas HTML creates static web pages.
  • DHTML allows including small animations and dynamic menus in Web pages.
  • DHTML used events, methods, properties to insulate dynamism in HTML Pages.
  • DHTML is basically using JavaScript and style sheets in an HTML page.
  • HTML sites will be slow upon client-side technologies, while DHTML sites will be fast enough upon client-side technologies.
  • HTML creates a plain page without any styles and Scripts called as HTML. Whereas, DHTML creates a page with HTML, CSS, DOM and Scripts called as DHTML.
  • HTML cannot have any server side code but DHTML may contain server side code.
  • In HTML, there is no need for database connectivity, but DHTML may require connecting to a database as it interacts with user.
  • HTML files are stored with .htm or .html extension, while DHTML files are stored with .dhtm extension.
  • HTML does not require any processing from browser, while DHTML requires processing from browser which changes its look and feel.


Tools of DTHML

 HTML and XML
Partitions and Organizes the content
 CSS
Defines the Presentation of the content
 Scripting - JavaScript, JScript, VBScript 
Adds interactivity to the page
 DOM- Document Object Model
Defines what and how elements are exposed for script access

Data Structures Basics

Data Structure:
A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently. Data structures provide a means to manage large amounts of data efficiently. efficient data structures are a key to designing efficient algorithms.
List of Data Structures
·       Stacks
·       Queues
·       Linked List
Stack:


A Stack is an abstract data type or collection where in Push,the addition of data elements to the collection, and Pop, the removal of data elements from the collection, are the major operations performed on the collection. The Push and Pop operations are performed only at one end of the Stack which is referred to as the 'top of the stack'.
In other words,a Stack can be simply defined as Last In First Out (LIFO) data structure,i.e.,the last element added at the top of the stack(In) should be the first element to be removed(Out) from the stack.
Stack Operations:
Push: A new entity can be added to the top of the collection.
Pop: An entity will be removed from the top of the collection.
Peek or Top: Returns the top of the entity without removing it.
Overflow State: A stack may be implemented to have a bounded capacity. If the stack is full and does not contain enough space to accept an entity to be pushed, the stack is then considered to be in an overflow state.
Underflow State: The pop operation removes an item from the top of the stack. A pop either reveals previously concealed items or results in an empty stack, but, if the stack is empty, it goes into underflow state, which means no items are present in stack to be removed.
A stack is a restricted data structure, because only a small number of operations are performed on it. The nature of the pop and push operations also means that stack elements have a natural order. Elements are removed from the stack in the reverse order to the order of their addition. Therefore, the lower elements are those that have been on the stack the longest.
Efficiency of Stacks
In the stack, the elements can be push or pop one at a time in constant O(1) time. That is, the time is not dependent on how many items are in the stack and is therefore very quick. No comparisons or moves are necessary.
Queue:


A queue is a kind of abstract data type or collection in which the entities in the collection are kept in order and the only operations on the collection are the addition of entities to the rear terminal position, called as enqueue, and removal of entities from the front terminal position, called as dequeue. The queue is called as First-In-First-Out (FIFO) data structure. In a FIFO data structure, the first element added to the queue will be the first one to be removed. This is equivalent to the requirement that once a new element is added, all elements that were added before have to be removed before the new element can be removed. Often a peek or front operation is also entered, returning the value of the front element without dequeuing it. A queue is an example of a linear data structure, or more abstractly a sequential collection.
Queues provide services in computer science, transport, and operations research where various entities such as data, objects, persons, or events are stored and held to be processed later. In these contexts, the queue performs the function of a buffer.
Queue Operations:
enqueue: Adds an item onto the end of the queue.
front: Returns the item at the front of the queue.
dequeue: Removes the item from the front of the queue.
Overflow State: A queue may be implemented to have a bounded capacity. If the queue is full and does not contain enough space to accept an entity to be pushed, the queue is then considered to be in an overflow state.
Underflow State: The dequeue operation removes an item from the top of the queue. A dequeue operation either reveals previously concealed items or results in an empty queue, but, if the queue is empty, it goes into underflow state, which means no items are present in queue to be removed.
Efficiency of Queue
The time needed to add or delete an item is constant and independent of the number of items in the queue. So both addition and deletion can be O(1) operation.
Deque:
A double-ended queue (dequeue or deque) is an abstract data type that generalizes a queue, for which elements can be added to or removed from either the front or rear. Deque differs from the queue abstract data type or First-In-First-Out List (FIFO), where elements can only be added to one end and removed from the other. This general data class has some possible sub-types:
1) An input-restricted deque is one where deletion can be made from both ends, but insertion can be made at one end only.
2) An output-restricted deque is one where insertion can be made at both ends, but deletion can be made from one end only.

You can use Deque as a stack by making insertion and deletion at the same side. Also you can use Deque as queue by making insetting elements at one end and removing elements at other end.
The common way of deque implementations are by using dynamic array or doubly linked list. Here this example shows the basic implementation of deque using a list, which is basically a dynamic array.
The complexity of Deque operations is O(1), when we not consider overhead of allocation/deallocation of dynamic array size.
Priority Queue:
A priority queue is an abstract data type, it is like a regular queue or stack data structure, but where additionally each element has a priority associated with it. In a priority queue, an element with high priority is served before an element with low priority. If two elements have the same priority, they are served according to their order in the queue.
There are a variety of simple ways to implement a priority queue. For instance, one can keep all the elements in an unsorted list. Whenever the highest-priority element is requested, search through all elements for the one with the highest priority. In big O notation: O(1) insertion time, O(n) pull time due to search.
Linked List:
A linked list is a data structure consisting of a group of nodes which together represent a sequence. Each node is composed of a data and a link or reference to the next node in the sequence. This structure allows for efficient insertion or removal of elements from any position in the sequence.The last node is linked to a terminator used to signify the end of the list.

Linked lists are the simplest and most common data structures. They can be used to implement several other abstract data types, including lists, stacks, queues, associative arrays, and S-expressions, etc.
The benefits of a linked list over a conventional array is that the linked list elements can easily be inserted or removed without reallocation or reorganization of the entire structure because the data items need not be stored contiguously in memory or on disk. Linked lists allow insertion and removal of nodes at any point in the list.
On the other hand, simple linked lists do not allow random access to the data, or by using indexing. Thus, many basic operations like obtaining the last node of the list, or finding a node with required data, or locating the place where a new node should be inserted, may require scanning most of the list elements.
Single Linked List:
Singly Linked Lists are a type of data structure. It is a type of list. In a singly linked list each node in the list stores the contents of the node and a pointer or reference to the next node in the list. It does not store any pointer or reference to the previous node. It is called a singly linked list because each node only has a single link to another node. To store a single linked list, you only need to store a reference or pointer to the first node in that list. The last node has a pointer to nothingness to indicate that it is the last node.
Here is the pictorial view of singly linked list:

Here is the pictorial view of inserting an element in the middle of a singly linked list:


Here is the pictorial view of deleting an element in the middle of a singly linked list:


Double Linked List:
A doubly-linked list is a linked data structure that consists of a set of sequentially linked records called nodes. Each node contains two fields, called links, that are references to the previous and to the next node in the sequence of nodes. The beginning and ending nodes previous and next links, respectively, point to some kind of terminator, typically a sentinel node or null, to facilitate traversal of the list. If there is only one sentinel node, then the list is circularly linked via the sentinel node. It can be conceptualized as two singly linked lists formed from the same data items, but in opposite sequential orders.
Here is the pictorial view of doubly linked list:


The two node links allow traversal of the list in either direction. While adding or removing a node in a doubly-linked list requires changing more links than the same operations on a singly linked list, the operations are simpler and potentially more efficient, because there is no need to keep track of the previous node during traversal or no need to traverse the list to find the previous node, so that its link can be modified.
Here is the pictorial view of inserting an element in the middle of a doubly linked list:

Here is the pictorial view of deleting an element in the middle of a doubly linked list:

Basic C Programs

1)Write a C program to find the largest of 3 numbers?
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("\nProgram to find the greatest of  numbers");
printf("\nEnter  values");
scanf("%d%d%d",&a,&b,&c);
if(a<b && a>c)
printf("\nA=%d is the greatest number",a);
else if(b>a && b>c)
printf("\nB=%d is the greatest number",b);
else if(a==b && b==c)
printf("\nAll are equal");
else
printf("\nC=%d is the greatest number",c);
getch();
}

2) Write a C program to find the sum of first 15 even numbers and calculate the square of the sum?
#include<stdio.h>
#include<conio.h>
void main()
{
int i,sum=0;
clrscr();
printf("\nProgram to find sum of first even 15 even numbers and square of sum\n");
for(i=0;i<=15;i++)
if(i%2==0)
{
printf("%d",i);
sum=sum+i;
}
printf("\nSum=%d",sum);
printf("\nSquare of sum=%d",sum*sum);
getch();
}
3) Write a C program to find the total and average of the marks given in an array?
#include<stdio.h>
#include<conio.h>
void main()
{
int i,a[10],n,tot=0;
float avg;
clrscr();
printf("\nProgram to find the total and average of the marks in an array\n");
printf("\nHow many subjects you want");
scanf("%d",&n);
printf("\nEnter %d subject values\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("\nMarks in various subjects are\n");
for(i=0;i<n;i++)
{
printf("\nSubject %d:\t%d\n",i+1,a[i]);
tot=tot+a[i];
avg=tot/n;
}
printf("\nTotal of given elements %d",tot);
printf("\nAverage=%f",avg);
getch();
}

4) Write a C program whether the given number is Armstrong or not?
#include<stdio.h>
#include<conio.h>
void main()
{
int n,r,am=0,m;
clrscr();
printf("\nProgram to find whether the given number is Armstrong or not");
printf("\nEnter a number");
scanf("%d",&n);
m=n;
while(n!=0)
{
r=n%10;
am=am+r*r*r;
n=n/10;
}
if(m==am)
printf("Yes, the given number is Armstrong");
else
printf("\nNo, it is not an Armstrong number");
getch();
}

5) Write a C program whether the given number is perfect or not?
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,sum=0;
clrscr();
printf("\nProgram to find whether the given number is perfect or not\n");
printf("\nEnter a number\n");
scanf("%d",&n);
printf("\nFactors for the given number are\n");
for(i=1;i<n;i++)
{
if(n%i==0)
{
printf("%d",i);
sum=sum+i;
}
}
printf("\n sum=%d",sum);
if(n==sum)
printf("\nYes the given number is perfect number");
else
printf("\nNo the given number is a perfect number");
getch();
}