Sunday, 31 July 2016

SHELL SORT JAVA


import java.util.Arrays;
import java.util.Scanner;


public class ShellSort {

public static void Sort( int arr[] )
{
int inner, outer;
int valueToInsert;
int interval = 1;  
int i = 0;
 
while(interval <= arr.length/3) {
interval = interval*3 +1;                  
}

while(interval > 0) {
System.out.println("iteration #:" + i);
System.out.println(Arrays.toString(arr));

for(outer = interval; outer < arr.length; outer++) {
valueToInsert = arr[outer];
inner = outer;

while(inner > interval -1 && arr[inner - interval]
>= valueToInsert) {
arr[inner] = arr[inner - interval];
inner -=interval;
System.out.println(" item moved: " + arr[inner] + "\n");
}
       
arr[inner] = valueToInsert;
System.out.println(" item inserted :" + valueToInsert + " at position " + inner +"\n");
}

interval = (interval -1) /3;          
i++;
}        
}

public static void main(String[] args) {
// TODO Auto-generated method stub
        Scanner scan = new Scanner( System.in );      
        System.out.println("Shell Sort\n");
        int n, i;
        /* Accept number of elements */
        System.out.println("Enter number of integer elements");
        n = scan.nextInt();
        /* Create integer array on n elements */
        int arr[] = new int[ n ];
        /* Accept elements */
        System.out.println("\nEnter "+ n +" integer elements");
        for (i = 0; i < n; i++)
            arr[i] = scan.nextInt();
        Sort(arr);
        System.out.println("\nElements after sorting ");      
        for (i = 0; i < n; i++)
            System.out.print(arr[i]+" ");          
        System.out.println();    
}

}

MERGE SORT IN JAVA

import java.io.*;
import java.util.Arrays;
import java.util.Scanner;

public class MergeSort {

    public static void main(String[] args) throws IOException{
    Scanner scanner = new Scanner(System.in);
        System.out.println("Enter number of elements");
        int size = scanner.nextInt();
        int[] data = new int[size];
        System.out.println("Enter " + size + " integers");
        for (int i = 0; i < size; i++) {
            data[i] = scanner.nextInt();
        }
        Divide(data);

        for (int j = 0; j < data.length; j++) {
            System.out.println(data[j]);
        }

    }

    public static void Divide(int[] A) {
    //divides into two equal halves
        if (A.length > 1) {
            int q = A.length/2;
            int[] leftArray = Arrays.copyOfRange(A, 0, q);
            int[] rightArray = Arrays.copyOfRange(A,q,A.length);
           
            //Logic for recursive division
            Divide(leftArray);
            Divide(rightArray);
            //Combine after every right array division complete
            combine(A,leftArray,rightArray);
        }
    }

    public static void combine(int[] a, int[] l, int[] r) {
        int totallength = l.length + r.length;
        int i, li, ri;
        i = li = ri = 0;
        while ( i < totallength) {
            if ((li < l.length) && (ri < r.length)) {
                if (l[li] < r[ri]) {
                //left array copies
                    a[i] = l[li];
                    i++;
                    li++;
                }
                else {
                //right array copied
                    a[i] = r[ri];
                    i++;
                    ri++;
                }
            }
            else {
                if (li >= l.length) {
                //right array copied
                    while (ri < r.length) {
                        a[i] = r[ri];
                        i++;
                        ri++;
                    }
                }
                if (ri >= r.length) {
                //left array copied
                    while (li < l.length) {
                        a[i] = l[li];
                        li++;
                        i++;
                    }
                }
            }
        }

    }

}

QUICK SORT IN JAVA

import java.util.Arrays;


public class QuickSort {
public static void main(String[] args) {
int[] x = { 9, 2, 4, 7, 3, 7, 10 };
System.out.println(Arrays.toString(x));

int low = 0;
int high = x.length - 1;

quickSort(x, low, high);
System.out.println(Arrays.toString(x));
}

public static void quickSort(int[] arr, int low, int high) {
if (arr == null || arr.length == 0)
return;

if (low >= high)
return;

// pick the pivot
int middle = low + (high - low) / 2;
int pivot = arr[middle];

// make left < pivot and right > pivot
int i = low, j = high;
while (i <= j) {
while (arr[i] < pivot) {
i++;
}

while (arr[j] > pivot) {
j--;
}

if (i <= j) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
i++;
j--;
}
}

// recursively sort two sub parts
if (low < j)
quickSort(arr, low, j);

if (high > i)
quickSort(arr, i, high);
}
}

T SQL NOTES

Primary Key, Foreign Key, Unique, Not Null
INF - each set of column must have a unique value, There is a primary key
2NF - for a table that has concatenated primary key, each column in the table that is not part of the primary key must depend upon the entire concatenated key for its existence
3NF - there should not be the case that a non-prime attribute is determined by another non-prime attribute,
4NFevery non-prime attribute of table must be dependent on primary key

CREATE  TABLE <table name> {<columnname> <type> <NOT NULL|UNIQUE> ... Constraint <constraint name> <PRIMARY KEY | FOREIGN KEY>(<column name>) REFERENCES <TABLE NAME (COLUMN NAME)> }
varchar(max), int, bigint, money, float [ (precision) ], date, datetime, time [ (fractional second) ], text, image, binary, varbinary(max)
PRIMARY KEY, UNIQUE, FOREIGN KEY, CHECK, NOT NULL
INDEX

ALTER TABLE <table name>
ADD <column> or ALTER <column> or DROP <column>

DROP TABLE <table name>

INSERT INTO <table name> (<column names>) VALUES (<column values>)

UPDATE <table name>
SET <modification> //modifies column value
WHERE <condition>

DELETE FROM <table name> //deletes row
WHERE <condition>

BEGIN  TRAN  <transaction name>
<INSERT/UPDATE/DELETE>
COMMIT  TRAN  <transaction name> or ROLLBACK  TRAN  <transaction name>

SELECT select_list [AS]
[ INTO new_table_name ] (specifies that the result set is used to create a new table)
FROM table_list
[ WHERE search_conditions ]
[ GROUP BY group_by_list ] (partitions the result set into groups based on the values)
[ HAVING search_conditions ] (an additional filter that is applied to the result set)
[ ORDER BY order_list [ ASC | DESC ] ]

OPERTORS USED
DISTINCT, SUM, AVG, MAX, MIN, COUNT

Conditional Operators FOR WHERE:
= <> > < >= <=
IN , NOT IN (test for several values)
BETWEEN, NOT BETWEEN (intervals)
IS NULL, IS NOT NULL
LIKE, NOT LIKE ( % or _ )
EXISTS, NOT EXISTS (sub queries)
AND, OR

JOINS:
SELECT column_name(s)
FROM  table_name1 INNER JOIN table_name2
ON    table_name1.column_name = table_name2.column_name

table_name1 INNER JOIN table_name2 - excludes data that does NOT satisfy the join
table1 LEFT OUTER JOIN table2 - all rows from table 1 will be included
table1 RIGHT OUTER JOIN table2 - all rows from table 2 will be included
table1 FULL OUTER JOIN table2 - all rows from each table will be included
table_name1 CROSS table_name2Each - row in one table is paired to every row in the other table

QUERY [UNION | INTERSECT | EXCEPT] QUERY


ROW FUNNCTIONS:

SELECT <ROW FUNCTION>

MATH:
ABS, DEGREES, RAND, ACOS
EXP, ROUND, ASIN, LOG, SIN
ATN2, LOG10, SQRT, CEILING
FLOOR, SIGN, ATAN,PI
SQUARE, COS, POWER
TAN, COT, RADIANS

STRING:
ASCII, NCHAR, SOUNDEX, CHAR, PATINDEX
SPACE, CHARINDEX, DIFFERENCE, REPLACE
STUFF, LEFT, REPLICATE, SUBSTRING
QUOTENAME, STR,LEN, REVERSE
UNICODE, LOWER, RIGHT
UPPER, LTRIM, RTRIM

DATE/TIME:
DATEADD, DATEDIFF
DATENAME, DATEPART
DAY, MONTH, YEAR
GETDATE, GETUTCDATE

DATA TYPE CASTING:
CAST( 'abc'  AS varchar(5) )
SUBSTRING(Name, 1, 30)  AS  ProductName
CONVERT(int, ListPrice) LIKE '3%';

CASE:
SELECT  title, price,
Budget = CASE price
WHEN price > 20.00 THEN 'Expensive‘
WHEN price BETWEEN 10.00 AND 19.99 THEN 'Moderate'
WHEN price < 10.00 THEN 'Inexpensive'
ELSE 'Unknown'
END,
FROM titles

SUB QUERIES:
QUERY [IN | NOI IN] (QUERY)

VIEWS:
CREATE VIEW <VIEW NAME> AS (QUERY)

PROCEDURE:
CREATE PROCEDURE <PROCEDURE NAME>
AS
(QUERY)
EXECUTE <PROCEDURE NAME>

FUNCTIONS:
CREATE FUNCTION whichContinent
(@Country nvarchar(15))
RETURNS varchar(30)
AS BEGIN
declare @Return varchar(30)
  select @return = case @Country
when 'Argentina' then 'South America‘
when 'Belgium' then 'Europe'
when 'Brazil' then 'South America‘
else 'Unknown'
End
return @return
end

TRIGGERS:
CREATE TRIGGER trigAddStudents
ON Students
FOR INSERT
AS
DECLARE @Newname VARCHAR(100)
SELECT @Newname =(SELECT Name FROM INSERTED)
PRINT 'THE STUDENT ' + @Newname + ' IS ADDED.';

Friday, 22 July 2016

Rotator Cuff exercises

Doorway stretch

doorway stretch
  1. Warm up your muscles by standing in an open doorway and spreading your arms out to the side.
  2. Grip the sides of the doorway with each hand at or below shoulder height, and lean forward through the doorway until you feel a light stretch.
  3. Keep a straight back as you lean and shift your weight onto your toes. You should feel a stretch in the front of your shoulder. Do not overstretch.

Scapular Stabilization Exercises

The scapula, the largest bone of your shoulder girdle, connects the humerus to the clavicle. The serratus anterior and rhomboid muscles hold this bone flat against the rib cage. Damage to these muscles can lift your scapula, a condition referred to as ‘winging’. Winging can occur on one or both of your shoulders where the winged scapula protrudes outwards. Proper Scapular stabilization exercises can help strengthen your serratus anterior and rhomboid muscles, which in turn will protect your scapula from long term damage.

Scapular Stabilization Exercises

Swimmers are often susceptible to scapular injuries due to their requirement of performing powerful swimming strokes. Overhead arm movements during swimming results in scapular injuries, leading to a condition called swimmer's shoulders. The common people too are very susceptible to this problem, so here is a list of exercises that can be performed to stabilize the scapula:

Tuesday, 7 June 2016

The seven most nutrient-dense foods in the world

Laura Holland identifies the seven most nutrient-dense foods in the world
Time is of the essence, in every aspect of life, including our health. Anything that takes too much time is either removed or rescheduled, and eating nutritiously has a tendency to fall off the to-do list more often than any of us would prefer.
For time-strapped health conscious types, the key is to eat foods that offer the most amount of nutrients in the smallest package; preferably items that do not require too much effort to find and prepare. Discovering what has the most nutrition, then concentrating our efforts on including these foods in our daily diets, is a time-efficient way of tending to the nutritional requirements of our body.
Dr Joel Fuhrman, a specialist in nutrition and best-selling author, has created something called the Andi score – Aggregate Nutrient Density Index. This is a scale from 1 to 1,000 based on the nutrition content of a food calculated by micronutrients per calorie.
Kale, collard greens, mustard greens and watercress all receive the highest score of 1,000, followed by other leafy greens and vegetables. The first fruit featured is the tomato, coming in at 186, followed by the strawberry at 182 and then the blueberry at 132. Pasta, french fries and corn chips score a very low 16, 12 and 7 points, ­respectively.
You can see there is a huge drop in nutrition from vegetables to fruit. Incidentally, vegetables tend to be the most undereaten of all food categories. Therefore, increasing our intake of leafy greens would prove incredibly effective.
While the Andi score provides great insights into what we should eat, critics point out that no superfoods are covered in the analysis and there is also no appreciation for the benefits of some nutrients compared to others.
To find the best of the best, we need to combine Fuhrman’s Andi scale with the latest nutrition research, as documented in Natural News. So here is the Top 7 and how to eat them, quickly!