Skip to main content


Showing posts from November, 2013

Bubble Sort

SortAverageBestWorstSpaceStabilityRemarksBubble sortO(n^2)O(n^2)O(n^2)ConstantStableAlways use a modified bubble sortModified Bubble sortO(n^2)O(n)O(n^2)ConstantStableStops after reaching a sorted arraySelection SortO(n^2)O(n^2)O(n^2)ConstantStableEven a perfectly sorted input requires scanning the entire arrayInsertion SortO(n^2)O(n)O(n^2)ConstantStableIn the best case (already sorted), every insert requires constant timeHeap SortO(n*log(n))O(n*log(n))O(n*log(n))ConstantInstableBy using input array as storage for the heap, it is possible to achieve constant spaceMerge SortO(n*log(n))O(n*log(n))O(n*log(n))DependsStableOn arrays, merge sort requires O(n) space; on linked lists, merge sort requires constant spaceQuicksortO(n*log(n))O(n*log(n))O(n^2)ConstantStableRandomly picking a pivot value (or shuffling the array prior to sorting) can help avoid worst case scenarios such as a perfectly sorted array.

this is bubble sort example

lets make it c language

#include <stdio.h>…

Selection sort

Example. Sort {5, 1, 12, -5, 16, 2, 12, 14} using selection sort.

lets make it C language

#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
 int arr[] = {5, 1, 12, -5, 16, 2, 12, 14};
 int i=0;
 int j=0;
 int count=0;
 int min=0;
 int temp;

 count = sizeof(arr)/sizeof(arr[0]);

 for(i;i<count-1; i++){
  min =i;
  for(j=i+1;j<count; j++){
  temp = arr[i];
  arr[i] = arr[min];
  arr[min] = temp;
 for(i=0; i<count; i++){
  printf("%d ", arr[i]);
 return 0;

Html Youtube Link

this would be a good example

This is basic concept of Memoization in Javascript

<!--  Basic use -->
function square(num){
return num*num;


function squareMemoization(num){
var result= '';
console.log("computing value..");
result = num * num;
squareMemoization.cache[num]= result;

return squareMemoization.cache[num];


squareMemoization.cache = {};

console.log(squareMemoization(10)); //First time when we call this function. It calculates the value &amp; cache it.
console.log(squareMemoization(10)); // Second time onwards it return the result from cache.
console.log(squareMemoization(20)); // square function will calculate again if its a new value.

var a = ["a", "b", "c"];


console.log(', 1)');
console.log(, 1));


make javascript Speed Up (2)

Asynchronous Transfer Mode getting script

function loadScript

this is sample

<!DOCTYPE html>
 window.onload = loadAllScript;
 function loadScript(url, callback){
  var script = document.createElement("script");
  script.type = "text/javascript";
  if(script.readState){ //IE
   script.onreadystatechange =function(){
    if(script.readState =="loaded" || script.readyState =="complete"){
     script.onreadstatechage= null;
  }else{ //ELSE



 function loadAllScript(){
  loadScript("", function(){


make javascript Speed Up (1)

Do you Think which sample is better between two samples

1. <html>
         <script type ="text/javascript" src="file1.js"></script>
         <script type ="text/javascript" src="file2.js"></script>
         <script type ="text/javascript" src="file3.js"></script>

2. <html>
//end of body
         <script type ="text/javascript" src="file1.js"></script>
         <script type ="text/javascript" src="file2.js"></script>
         <script type ="text/javascript" src="file3.js"></script>

First is well-known pattern when we use javascript, and also we learn like 1 sample

but until scripts are fully loaded we will see white page

Second sa…

how to compare string values using jstl fn

At first~!

in html we need to add Declare using jstl

<%@ taglib prefix="c" uri="" %>
<%@ taglib prefix="fn" uri="" %>
<!DOCTYE html>

this is really good i think

        <jsp:useBean id="extension" class="java.util.HashSet" scope="request">

basic javascript 3type alert

JavaScript supports three important types of dialog boxes. These dialog boxes can be used to raise and alert, or to get confirmation on any input or to have a kind of input from the users.

Here we will see each dialog box one by one:

Alert Dialog Box:
An alert dialog box is mostly used to give a warning message to the users. Like if one input field requires to enter some text but user does not enter that field then as a part of validation you can use alert box to give warning message as follows:

<head> <script type="text/javascript"> <!-- alert("Warning Message"); //--> </script> </head>
Nonetheless, an alert box can still be used for friendlier messages. Alert box gives only one button "OK" to select and proceed.

Confirmation Dialog Box:
A confirmation dialog box is mostly used to take user's consent on any option. It displays a dialog box with two buttons: OK and Cancel.

If the user clicks on OK button the wi…

Maven Using filter~ It is Awesome

When you use maven Filter is very good for user
We can easily control enviroment of the project

Let's use Porifle

Ex> pom.xml

<project xmlns="" xmlns:xsi=""
 <name>SpringMVC Maven Webapp</name>
  <!-- Spring framework -->

Spring escapeXMl using StringEscapeUtils

escape xss from hacker

we have to  change value using  StringEscapeUtils.escapeXml(str)

this is apache library
import org.apache.commons.lang.StringEscapeUtils;

//handling xml special character & in Java String
        String xmlWithSpecial = "Java & HTML"; //xml String with & as special characters
        System.out.println("Original unescaped XML String: " + xmlWithSpecial);
        System.out.println("Escaped XML String in Java: "
                            +  StringEscapeUtils.escapeXml(xmlWithSpecial));

        //handling xml special character > in String on Java
        xmlWithSpecial = "Java > HTML"; //xml String with & as special characters
        System.out.println("Original unescaped XML String: " + xmlWithSpecial);
        System.out.println("Escaped XML String : " + StringEscapeUtils.escapeXml(xmlWithSpecial));

        //handling xml and html special character < in String