Showing posts with label sorting. Show all posts
Showing posts with label sorting. Show all posts

Sunday, August 14, 2016

Best Application to learn Difference Programming Languages Fast


App Name: Programming Hub
Package Name: com.freeit.java
Category: Education
Developer : Nexino Labs Pvt Ltd
Version: 3.0.6
Publish Date: July 30, 2016
File Size: Undefined
Installs: 1,000,000 - 5,000,000
Requires Android: 4.1 and up
Content Rating: Everyone
Developer: Visit website Email contactus@prghub.com


This is the best Application for me to Learn 18+ Programming languages such as Python, Assembly, HTML, VB.NET, C, C++, C# (CSharp), JavaScript, PHP, Ruby, R Programming, CSS, Java programming and much more! The new UI is quite interesting with new Material Design include the built-in playground where you can test your code in one app :D

With this app, i think is fastest way to learn any programming language by referring ready made programs and theory created by programming experts. Just download the language you want to learn or just request to the developer on what language you want or solutions.

Have an exam tomorrow?? :D No worries! By this app, forget your 600 page textbooks! Simply read this app essential and very precise reference material to score awesome marks!

Below is the Screenshot of this lastest app





Thursday, September 24, 2015

Merge Sort

The merge sort is a recursive sort of order n*log(n). It is notable for having a worst case and average complexity of O(n*log(n)), and a best case complexity of O(n) (for pre-sorted input). The basic idea is to split the collection into smaller groups by halving it until the groups only have one element or no elements (which are both entirely sorted groups). Then merge the groups back together so that their elements are in order. This is how the algorithm gets its "divide and conquer" description.


Worst case performance : O(n log n)
Best case performance : O(n log n)
Average case performance : O(n log n)

Conceptually, a merge sort works as follows:

  • Divide the unsorted list into n sublists, each containing 1 element (a list of 1 element is considered sorted).
  • Repeatedly merge sublists to produce new sorted sublists until there is only 1 sublist remaining. This will be the sorted list.

This is the pseudocode of merge sort
function mergesort(m)
   var list left, right, result
   if length(m) ≤ 1
       return m
   else
       var middle = length(m) / 2
       for each x in m up to middle - 1
           add x to left
       for each x in m at and after middle
           add x to right
       left = mergesort(left)
       right = mergesort(right)
       if last(left) ≤ first(right) 
          append right to left
          return left
       result = merge(left, right)
       return result

function merge(left,right)
   var list result
   while length(left) > 0 and length(right) > 0
       if first(left) ≤ first(right)
           append first(left) to result
           left = rest(left)
       else
           append first(right) to result
           right = rest(right)
   if length(left) > 0 
       append rest(left) to result
   if length(right) > 0 
       append rest(right) to result
   return result


Quick Sort

Quicksort is an efficient sorting algorithm, serving as a systematic method for placing the elements of an array in order. Quicksort is a comparison sort, meaning that it can sort items of any type for which a "less-than" relation is defined. On average, the algorithm takes O(n log n) comparisons to sort n items. In the worst case, it makes O(n2) comparisons, though this behavior is rare. Quicksort is at one end of the spectrum of divide-and-conquer algorithms, which does most of the work during the partitioning and the recursive calls.

Steps
  1. Choose any element of the array to be the pivot.
  2. Divide all other elements (except the pivot) into two partitions which is all elements less than the pivot must be in the first partition and all elements greater than the pivot must be in the second partition.
  3. Use recursion to sort both partitions.
  4. Join the first sorted partition, the pivot, and the second sorted partition.
The best pivot creates partitions of equal length (or lengths differing by 1). The worst pivot creates an empty partition, for example if the pivot is the first or last element of a sorted array. The runtime of Quicksort ranges from O(n log n) with the best pivots, to O(n2) with the worst pivots, where n is the number of elements in the array.



Monday, June 29, 2015

Bubble Sort

How its work?
An example of bubble sort. Starting from the beginning of the list, compare every adjacent pair, swap their position if they are not in the right order (the latter one is smaller than the former one). After each iteration, one less element (the last one) is needed to be compared until there are no more elements left to be compared.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
public class BubbleSort {
        public static void main(String[] args) {
                int intArray[] = new int[]{51,1,61,7,55,90,25,99,91,15,35};
               
                System.out.println("Array Before Bubble Sort");
                for(int i=0; i < intArray.length; i++){
                        System.out.print(intArray[i] + ", ");
                }
                System.out.println();
                bubbleSort(intArray);
        }
 
        private static void bubbleSort(int[] intArray) {
           int n = intArray.length;
           int temp = 0;
           for(int i=0; i < n; i++){
               for(int j=1; j < (n-i); j++){
                  if(intArray[j-1] > intArray[j]){
                     temp = intArray[j-1];
                     intArray[j-1] = intArray[j];
                     intArray[j] = temp;             
                   }      
                   display(intArray);
                }
           }
        }
        
        private static void display(int[] intArray){
            for(int i=0; i < intArray.length; i++){
                    System.out.print(intArray[i] + ", ");
                }
                System.out.println();
        }
}