How to Install Oracle Java 8 on Ubuntu 12.04 Linux


This blog entry will guide you through the step-by-step installation of Java on Ubuntu. I selected Oracle Java 8 and Ubuntu Linux 12.04 LTS 32 bit for this post.


Installing Java on Linux follows the download-extract-configure pattern. We will begin by downloading Oracle Java from Oracle’s website, extracting the download in the appropriate folder, and finally informing Ubuntu about the newly installed version of Java.

Step 1: Verify that you do not already have the correct version of Java installed.

Open your console window and enter the following command:

java -version

If you get the following result, you already have Java 8 installed and can ignore the rest of the steps:

java version 1.8.0
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) Client VM (build 25-b70, mixed mode)

Step 2: Download Oracle Java.

New release of Java are featured on the main Java download page.
If Java Java 8 is no longer featured, you can find the download by following the Previous Releases link found on the main download page.
Open the Java download page in your browser and download jdk-8-linux-i586.bin.
Make a note of the folder to which you downloaded the file. For further reference in this blog, I will call this folder the “downloads folder”.

Step 3: Create the installation folder.

The /usr/lib/jvm is the default installation location of the Java JDK. Enter the following command in your console to create this folder, if it does not already exist:

sudo mkdir -p /usr/lib/jvm

The –p option ensures that all folders in the mkdir path are created.

Step 4: Navigate to the “downloads folder”.

If you downloaded the file to your Home folder, you can use the following command:

cd ~/

or substitute "~/" with the path to the “downloads folder”.

Step 5: Move the downloaded archive to the installation folder.

sudo mv jdk-8-linux-i586.tar.gz /usr/lib/jvm /usr/lib/jvm

Step 6: Navigate to the “installation folder”.

cd /usr/lib/jvm

Step 7: Unpack the tarball archives.

sudo tar zxvf jdk-8-linux-i586.tar.gz

If you want to conserve space you may delete the tarball archives.

sudo rm jdk-8-linux-i586.tar.gz

Step 8: Display the contents of the installation folder.

ls -l



Make a note of the newly created folder names.

Step 9: Inform Ubuntu where your Java installation is located.

sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.8.0/bin/javac" 1
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0/bin/java" 1

Step 10: Inform Ubuntu that this is your default Java installation.

sudo update-alternatives --set "javac" "/usr/lib/jvm/jdk1.8.0/bin/javac"
sudo update-alternatives --set "java" "/usr/lib/jvm/jdk1.8.0/bin/java"

Step 11: Update your system-wide PATH.

Edit your /etc/profile file using:

sudo nano /etc/profile

Add the following entries to the bottom of your /etc/profile file:

export JAVA_HOME
export PATH

Save your /etc/profile file using CTRL + X.

Step 12: Reload your system-wide PATH.

. /etc/profile

Step 13: Test your new installation.

java -version

Note there is only a single dash before version.

java version 1.8.0
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) Client VM (build 25-b70, mixed mode)
javac -version

Note there is only a single dash before version.

javac 1.8.0

Step 14: Congratulations! You have just installed Oracle Java on Ubuntu Linux!

Leave a comment

Posted by on May 12, 2014 in Install Java 8


Insertion sort

Insertion sort is a simple sorting algorithm that builds the final sorted array (or list) one item at a time. It is much less efficient on large lists than more advanced algorithms such as quicksort, heapsort, or merge sort. However, insertion sort provides several advantages:
  • Simple implementation
  • Efficient for (quite) small data sets
  • Adaptive (i.e., efficient) for data sets that are already substantially sorted: the time complexity is O(n + d), where d is the number of inversions
  • More efficient in practice than most other simple quadratic (i.e., O(n2)) algorithms such as selection sort or bubble sort; the best case (nearly sorted input) is O(n)
  • Stable; i.e., does not change the relative order of elements with equal keys
  • In-place; i.e., only requires a constant amount O(1) of additional memory space
  • Online; i.e., can sort a list as it receives it

When humans manually sort something (for example, a deck of playing cards), most use a method that is similar to insertion sort.[1]


A graphical example of insertion sort.

Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, 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.

Sorting is typically done in-place, by iterating up the array, growing the sorted list behind it. At each array-position, it checks the value there against the largest value in the sorted list (which happens to be next to it, in the previous array-position checked). If larger, it leaves the element in place and moves to the next. If smaller, it finds the correct position within the sorted list, shifts all the larger values up to make a space, and inserts into that correct position.

The resulting array after k iterations has the property where the first k + 1 entries are sorted (“+1” because the first entry is skipped). In each iteration the first remaining entry of the input is removed, and inserted into the result at the correct position, thus extending the result:

Array prior to the insertion of x


Array after the insertion of x

with each element greater than x copied to the right as it is compared against x.

The most common variant of insertion sort, which operates on arrays, can be described as follows:

  1. Suppose there exists a function called Insert designed to insert a value into a sorted sequence at the beginning of an array. It operates by beginning at the end of the sequence and shifting each element one place to the right until a suitable position is found for the new element. The function has the side effect of overwriting the value stored immediately after the sorted sequence in the array.
  2. To perform an insertion sort, begin at the left-most element of the array and invoke Insert to insert each element encountered into its correct position. The ordered sequence into which the element is inserted is stored at the beginning of the array in the set of indices already examined. Each insertion overwrites a single value: the value being inserted.

Pseudocode of the complete algorithm follows, where the arrays are zero-based:

for i ← 1 to length(A)
    j ← i
    while j > 0 and A[j-1] > A[j]
        swap A[j] and A[j-1]
        j ← j - 1

The outer loop runs over all the elements except the first one, because the single-element prefix A[0:1] is trivially sorted, so the invariant that the first i+1 entries are sorted is true from the start. The inner loop moves element A[i] to its correct place so that after the loop, the first i+2 elements are sorted.

After expanding the “swap” operation in-place as t ← A[j]; A[j] ← A[j-1]; A[j-1] ← t (where t is a temporary variable), a slightly faster version can be produced that moves A[i] to its position in one go and only performs one assignment in the inner loop body:

for i ← 1 to length(A)
    x ← A[i]
    j ← i
    while j > 0 and A[j-1] > x
        A[j] ← A[j-1]
        j ← j - 1
    A[j] ← x

The new inner loop shifts elements to the right to clear a spot for x = A[i].

Note that although the common practice is to implement in-place, which requires checking the elements in-order, the order of checking (and removing) input elements is actually arbitrary. The choice can be made using almost any pattern, as long as all input elements are eventually checked (and removed from the input).

Best, worst, and average cases

Animation of the insertion sort sorting a 30 element array.

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 quicksortimplementations 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.

Example: The following table shows the steps for sorting the sequence {3, 7, 4, 9, 5, 2, 6, 1}. In each step, the key under consideration is underlined. The key that was moved (or left in place because it was biggest yet considered) in the previous step is shown in bold.

3 7 4 9 5 2 6 1

3 7 4 9 5 2 6 1

7 4 9 5 2 6 1

4 7 9 5 2 6 1

3 4 7 9 5 2 6 1

3 4 5 7 9 2 6 1

2 3 4 5 7 9 6 1

2 3 4 5 6 7 9 1

1 2 3 4 5 6 7 9

Relation to other sorting algorithms

Insertion sort is very similar to selection sort. As in selection sort, after k passes through the array, the first k elements are in sorted order. For selection sort these are the k smallest elements, while in insertion sort they are whatever the first k elements were in the unsorted array. Insertion sort’s advantage is that it only scans as many elements as needed to determine the correct location of the k+1st element, while selection sort must scan all remaining elements to find the absolute smallest element.

Calculations show that insertion sort will usually perform about half as many comparisons as selection sort. Assuming the k+1st element’s rank is random, insertion sort will on average require shifting half of the previous k elements, while selection sort always requires scanning all unplaced elements. If the input array is reverse-sorted, insertion sort performs as many comparisons as selection sort. If the input array is already sorted, insertion sort performs as few as n-1 comparisons, thus making insertion sort more efficient when given sorted or “nearly sorted” arrays.

While insertion sort typically makes fewer comparisons than selection sort, it requires more writes because the inner loop can require shifting large sections of the sorted portion of the array. In general, insertion sort will write to the array O(n2) times, whereas selection sort will write only O(n) times. For this reason selection sort may be preferable in cases where writing to memory is significantly more expensive than reading, such as with EEPROM or flash memory.

Some divide-and-conquer algorithms such as quicksort and mergesort sort by recursively dividing the list into smaller sublists which are then sorted. A useful optimization in practice for these algorithms is to use insertion sort for sorting small sublists, where insertion sort outperforms these more complex algorithms. The size of list for which insertion sort has the advantage varies by environment and implementation, but is typically between eight and twenty elements. A variant of this scheme runs quicksort with a constant cutoff K, then runs a single insertion sort on the final array:

proc quicksort(A, lo, hi)
    if hi - lo < K
    pivot ← partition(A, lo, hi)
    quicksort(A, lo, pivot-1)
    quicksort(A, pivot + 1, hi)
proc sort(A)
    quicksort(A, 0, length(A))

This preserves the O(n lg n) expected time complexity of standard quicksort, because after running the quicksort procedure, the array A will be partially sorted in the sense that each element is at most K positions away from its final, sorted position. On such a partially sorted array, insertion sort will run at most K iterations of its inner loop, which is run n-1 times, so it has linear time complexity.[2]:121


D.L. Shell made substantial improvements to the algorithm; the modified version is called Shell sort. The sorting algorithm compares elements separated by a distance that decreases on each pass. Shell sort has distinctly improved running times in practical work, with two simple variants requiring O(n3/2) and O(n4/3) running time.

If the cost of comparisons exceeds the cost of swaps, as is the case for example with string keys stored by reference or with human interaction (such as choosing one of a pair displayed side-by-side), then using binary insertion sort may yield better performance. Binary insertion sort employs a binary search to determine the correct location to insert new elements, and therefore performs ⌈log2(n)⌉ comparisons in the worst case, which is O(n log n). The algorithm as a whole still has a running time of O(n2) on average because of the series of swaps required for each insertion.

The number of swaps can be reduced by calculating the position of multiple elements before moving them. For example, if the target position of two elements is calculated before they are moved into the right position, the number of swaps can be reduced by about 25% for random data. In the extreme case, this variant works similar to merge sort.

To avoid having to make a series of swaps for each insertion, the input could be stored in a linked list, which allows elements to be spliced into or out of the list in constant-time when the position in the list is known. However, searching a linked list requires sequentially following the links to the desired position: a linked list does not have random access, so it cannot use a faster method such as binary search. Therefore, the running time required for searching is O(n) and the time for sorting is O(n2). If a more sophisticated data structure (e.g., heap or binary tree) is used, the time required for searching and insertion can be reduced significantly; this is the essence of heap sort and binary tree sort.

In 2004 Bender, Farach-Colton, and Mosteiro published a new variant of insertion sort called library sort or gapped insertion sort that leaves a small number of unused spaces (i.e., “gaps”) spread throughout the array. The benefit is that insertions need only shift elements over until a gap is reached. The authors show that this sorting algorithm runs with high probability in O(n log n) time.[3]

If a skip list is used, the insertion time is brought down to O(log n), and swaps are not needed because the skip list is implemented on a linked list structure. The final running time for insertion would be O(n log n).

List insertion sort is a variant of insertion sort. It reduces the number of movements.[citation needed]

List insertion sort code in C

If the items are stored in a linked list, then the list can be sorted with O(1) additional space. The algorithm starts with an initially empty (and therefore trivially sorted) list. The input items are taken off the list one at a time, and then inserted in the proper place in the sorted list. When the input list is empty, the sorted list has the desired result.

struct LIST * SortList1(struct LIST * pList) {
    // zero or one element in list
    if(pList == NULL || pList->pNext == NULL)
        return pList;
    // head is the first element of resulting sorted list
    struct LIST * head = NULL;
    while(pList != NULL) {
        struct LIST * current = pList;
        pList = pList->pNext;
        if(head == NULL || current->iValue < head->iValue) {
            // insert into the head of the sorted list
            // or as the first element into an empty sorted list
            current->pNext = head;
            head = current;
        } else {
            // insert current element into proper position in non-empty sorted list
            struct LIST * p = head;
            while(p != NULL) {
                if(p->pNext == NULL || // last element of the sorted list
                   current->iValue < p->pNext->iValue) // middle of the list
                    // insert into middle of the sorted list or as the last element
                    current->pNext = p->pNext;
                    p->pNext = current;
                    break; // done
                p = p->pNext;
    return head;

The algorithm below uses a trailing pointer[4] for the insertion into the sorted list. A simpler recursive method rebuilds the list each time (rather than splicing) and can use O(n) stack space.

struct LIST
  struct LIST * pNext;
  int           iValue;
struct LIST * SortList(struct LIST * pList)
  // zero or one element in list
  if(!pList || !pList->pNext)
      return pList;
  /* build up the sorted array from the empty list */
  struct LIST * pSorted = NULL;
  /* take items off the input list one by one until empty */
  while (pList != NULL)
      /* remember the head */
      struct LIST *   pHead  = pList;
      /* trailing pointer for efficient splice */
      struct LIST ** ppTrail = &pSorted;
      /* pop head off list */
      pList = pList->pNext;
      /* splice head into sorted list at proper place */
      while (!(*ppTrail == NULL || pHead->iValue < (*ppTrail)->iValue)) /* does head belong here? */
          /* no - continue down the list */
          ppTrail = &(*ppTrail)->pNext;
      pHead->pNext = *ppTrail;
      *ppTrail = pHead;
  return pSorted;

Leave a comment

Posted by on May 11, 2014 in Insertion sort


Install Ubuntu 14.04 LTS

  1. Using a DVD?

    It’s easy to install Ubuntu from a DVD. Here’s what you need to do:

    Put the Ubuntu DVD into the DVD-drive

    Restart your computer. You should see a welcome screen prompting you to choose your language and giving you the option to install Ubuntu or try it from the DVD.

    If you don’t get this menu, read the booting from the DVD guide for more information.

    Using a USB drive?

    Most newer computers can boot from USB. You should see a welcome screen prompting you to choose your language and giving you the option to install Ubuntu or try it from the CD.

    If your computer doesn’t automatically do so, you might need to press the F12 key to bring up the boot menu, but be careful not to hold it down – that can cause an error message.

  2. Prepare to install Ubuntu

    • We recommend you plug your computer into a power source
    • You should also make sure you have enough space on your computer to install Ubuntu
    • We advise you to select Download updates while installing and Install this third-party software now
    • You should also stay connected to the internet so you can get the latest updates while you install Ubuntu
    • If you’re not connected to the internet, we’ll help you set up wireless at the next step
  3. Set up wireless

    If you are not connected to the internet, you will be asked to select a wireless network, if available. We advise you to connect during the installation so we can ensure your machine is up to date. So, if you set up your wireless network at this point, it’s worth then clicking the Back button to go back to the last screen (Preparing to install Ubuntu) and ticking the box marked ’Download updates while installing’.

  4. Allocate drive space

    Use the checkboxes to choose whether you’d like to Install Ubuntu alongside another operating system, delete your existing operating system and replace it with Ubuntu, or — if you’re an advanced user — choose the ’Something else’option

  5. Begin the installation

    Depending on your previous selections, you can now verify that you have chosen the way in which you would like to install Ubuntu. The installation process will begin when you click the Install Now button.

    Ubuntu needs about 4.5 GB to install, so add a few extra GB to allow for your files.

  6. Select your location

    If you are connected to the internet, this should be done automatically. Check your location is correct and click’Forward’ to proceed. If you’re unsure of your time zone, type the name of the town you’re in or click on the map and we’ll help you find it.

    TIP: If you’re having problems connecting to the Internet, use the menu in the top-right-hand corner to select a network.

  7. Select your preferred keyboard layout

    Click on the language option you need. If you’re not sure, click the ’Detect Keyboard Layout’ button for help.

  8. Enter your login and password details
  9. Learn more about Ubuntu while the system installs…

    …or make a cup of tea!

  10. That’s it.

    All that’s left is to restart your computer and start enjoying Ubuntu!

Leave a comment

Posted by on May 11, 2014 in Install Ubuntu


Ubuntu Shortcuts

As well as using your mouse to operate software, you can also use your keyboard to perform specific functions. This page provides a list of keyboard shortcuts which you may find useful.

How to use a keyboard shortcut


Traditionally, keyboard shortcuts are written like so: Alt + F1. This means that you should press the Alt and F1 keys simultaneously. This is normally best achieved by holding down the modifier key (such as Ctrl or Alt or the Super(windows logo) key) and then pressing the second key once. You can then release the modifier key.

Finding keyboard shortcuts

Finding system keyboard shortcuts


To find (and change) system-level keyboard shortcuts, one can (at least in later, GNOME-based distros, e.g. ubuntu karmic) run the Keyboard Shortcuts applet, e.g. via System>Preferences>Keyboard Shortcuts on the main menu.

Finding application-specific keyboard shortcuts


While there are many standard keyboard shortcuts (see below), most applications also have keyboard shortcuts which are specific to themselves. These can normally be found in the pull-down menus at the top of the application’s screen. The example below shows a menu in Writer, with the keyboard shortcuts highlighted:


Desktop shortcuts


This section lists common keyboard shortcuts which you can use to operate parts of the desktop (such as windows and the menu bar).

Alt + F1

Open the Applications menu

Alt + F2

Run an application by typing its name in the box which appears

Prt Sc

(Print Screen) Take a screenshot of the whole screen

Alt + Prt Sc

Take a screenshot of the current window

Window shortcuts


Alt + Tab

Switch between currently-open windows. Press Alt + Tab and then release Tab (but continue to hold Alt). Press Tabrepeatedly to cycle through the list of available windows which appears on the screen. Release the Alt key to switch to the selected window.

Ctrl + Alt + Tab

Switch between currently-open windows in all Workspaces. Press Tab repeatedly to cycle through the list of available windows which appears on the screen. Release the Ctrl and Alt keys to switch to the selected window.

Ctrl + Alt + Left/Right Cursor

Lets you quickly switch between your Workspaces.


These might not work on every machine, but are reasonably common:


Moves the current window (can be moved with mouse or keyboard).


Resizes current window (again, can be moved with mouse or keyboard).


Minimises current window.


Maximises current window.


Brings up window menu with with ‘Always on Top’ and ‘Minimise’ and ‘Maximise’ and above commands.


These might change depending on the application you’re using, but work for most common applications:


Returns window to ‘normal’ or previous size.


Closes window.

Desktop Effects enabled shortcuts


All of the shortcuts listed in this section require Desktop Effects to be enabled.

Ctrl + Alt + Left/Right Cursor

Spins the ‘cube’ that your workspaces reside on, allowing you to select the workspace you wish to use.

Ctrl + Alt + Up Cursor

Enables an ‘expose’ like feature that presents you with all the windows you currently have open, allowing you to select the one you wish to give focus to.

Ctrl + Alt + Down Cursor

Unfolds your workspace cube allowing you to see more than one of your workspaces at once, using the left and right cursor keys with this active will allow you to select the workspace you wish to use.

Ctrl + Alt + Tab

Switch between currently-open windows across all workspaces.

Super + W

Enables the ‘scale’ effect, it shows all windows from the current workspace.

Super + A

Enables the ‘scale’ effect, it shows all windows from all workspaces.

Super + N

Invert colours of the focused window.

Super + M

Invert colours for the whole screen.

Super + Mouse Scroll Wheel

Zooms in on the screen.

Super + Middle Mouse Button

Select a region to zoom into, using a rectangle.

Ctrl + Super + D

Toggles ‘Show Desktop’.

Alt + Middle Mouse Button

Resize focused window.

Alt + Left Mouse Button

Move focused window.

Alt + Right Mouse Button

Show window menu.

Super + S

Zoom out, show workspace switcher

Common application shortcuts


These shortcuts do not apply in all applications, but usually perform the functions listed below.

Ctrl + C

Copy the selected text/object

Ctrl + X

Cut the selected text/object

Ctrl + V

Paste/insert the selected text/object

Ctrl + A

Select all text

Ctrl + B

Make the selected text bold

Ctrl + I

Make the selected text italic

Ctrl + U

Underline the selected text

Ctrl + N

Open a new document or window

Ctrl + S

Save the current document

Ctrl + O

Open another document

Ctrl + P

Print the current document

Ctrl + Z

Undo the last change you made

Ctrl + Shift + Z

Redo a change that you just undid

System shortcuts


Some of these shortcuts will restart important parts of your system. Only use them if you have to.

Ctrl + Alt + Delete

Restart the computer immediately, without saving open files

Ctrl + Alt + Plus (numeric keypad)

Rotate through supported screen resolutions

Ctrl + Alt + Minus (numeric keypad)

Rotate backwards through supported screen resolutions

Application-specific shortcuts


This section covers common keyboard shortcuts for some important applications which are installed by default in Ubuntu.

Firefox Web Browser


Ctrl + T

Open a new tab

Ctrl + Tab

Rotate through each tab


Ctrl + Shift + Tab

Rotate backwards through each tab

Ctrl + W

Close the current tab (or browser if on last tab)

Ctrl + L

Enter a new web address

Ctrl + B

Show a list of your bookmarks

Ctrl + H

Show your browsing history

Ctrl + K

Enter a new web search in the search bar

Ctrl + Y

Show a list of downloaded files


Display the current page full-screen


Stop loading the current page

Ctrl + R

Reload the current page


These might not work for everyone, but can help with accessibility issues:

Alt Gr+Space Scrolls current tab/window down.

Alt Gr+Backspace Scrolls current tab/window up. You may find Alt Gr+Shift+Space works if Alt Gr+Backspace does not.

If you don’t have Alt Gr, it might be labelled something else. It’s usually to the right of the space bar.

LibreOffice Writer



Check the spelling of the current document

Ctrl + F

Find and replace words

Ctrl + Z

Undo the last change

Ctrl + Y

Redo a change which you just undid

Ctrl + L

Align the current paragraph/selection to the left

Ctrl + E

Align the current paragraph/selection to the center of the document

Ctrl + R

Align the current paragraph/selection to the right

Ctrl + Shift + J

Show the current document full-screen


Press Tools ▸ Customize… ▸ Keyboard to change keyboard shortcuts in LibreOffice.

Laptop Function Shortcuts


Many laptops have function (Fn) keys which you can hold down to access more functions on the laptop’s keyboard. A list of these functions should be available from the manufacturer of the laptop.

Text Entry Shortcuts


If you want to have quick access to lines of text by using a hotkey, for example to enter your email address in forms, then you can use xbindkeys. Xbindkeys has a GUI utility to allow easy settings of hotkeys, but be aware that it’s a little more complicated than the default Ubuntu Shortcutkeys interface.

Install xbindkeys 

sudo apt-get install xbindkeys


Create the default config file for xbindkeys

xbindkeys --defaults > /home/your-user-name/.xbindkeysrc


When thats done, install xbindkeys-config, the GUI for xbindkeys

sudo apt-get install xbindkeys-config


Now the utility that actually does the “typing”

sudo apt-get install xvkbd


Once each is installed, start both applications by bringing up “Run Application” with ALT -F2.




To keep the xbindkeys hotkeys active when you next start the computer you will have to add a new session, System –> Preferences –> Sessions. Put in the command “xbindkeys” into the command field (without the quotes).

You should be able to see the “Xbindkeys Config” window. Start a new hotkey. Hit “New” on the bottom row of buttons. Then use the edit area at the top right. Give the hotkey a name. Hit the “GetKey” button to set the keypress for a hotkey. Some hotkeys may conflict with other hotkeys on the system (a window will open or a compiz plugin will activate). If this happens then choose another combination like CTRL – ALT – F for example.

Now put the command to activate with that hotkey in the “Action” field. This can be anything, but to allow for the entry of a line of text into part of the GUI enter 

xvkbd -xsendevent -text ""


The example shows an email address but it can be any line of text. Now hit “Apply” and test the hotkey in a Firefox field, text editor, or anywhere that text can be entered. Please note that using “Run Action” will not be able to test the command in xbindkeys-config, you will have to test it somewhere else.

Replacing keys with other keys


If you want to use xbindkeys to override certain keys on your keyboard, you can catch them with xbindkeys, and then emit new keypresses using xmacro. To install xmacro, use:

sudo apt-get install xmacro


After this, you can find out the commands for specific keypresses by starting xmacrorec:

xmacrorec :0.0


First give it the key which will allow you to quit the app, then press the keys you want to know the codes for. After this, you can use those codes in the commands you tell xbindkeys to run, for example:

xmacroplay-keys :0.0 KeyStr Next


will simulate a key press of the PageDown key. Thus, in my .xbindkeysrc the following contents

"xmacroplay-keys :0.0 KeyStr Prior"

"xmacroplay-keys :0.0 KeyStr Next"
Leave a comment

Posted by on May 11, 2014 in Ubuntu Shortcuts, Uncategorized


Accessing the UEFI (BIOS) setup on a Windows 8 system

Accessing the UEFI (BIOS) setup on a Windows 8 system

This article only applies to: systems with Windows 8 pre-installed

On systems with Windows 8 pre-installed, you can access the UEFI (BIOS) setup screens from the Windows 8 boot menu:

  1. Press the Windows key + C, or swipe in from the right edge of the screen to open your Charms.
  2. Click Settings.
  3. Click Change PC Settings.
  4. In PC Settings, select General.
  5. Under Advanced startup, click Restart now. The system will restart and show the Windows 8 boot menu.
  6. In the boot menu, select Troubleshoot.
  7. In the Troubleshoot menu, select Advanced options.
  8. In the Advanced options menu, select UEFI Firmware Settings.
  9. Click Restart to restart the system and enter UEFI (BIOS).

The Windows 8 boot menu will also show automatically after Windows 8 fails to start successfully three times.



If you upgraded your system to Windows 8, the UEFI Firmware Settings option might not be available. If this is the case, proceed as follows: Power on the system. As soon as the first logo screen appears, immediately press the F2 key, or the DEL key if you have a desktop, to enter the BIOS.

Leave a comment

Posted by on May 11, 2014 in BIOS, Uncategorized


Eclipse Shortcuts


Find Java Type
Start typing the name and the list gets smaller. Try typing the capital letters of the class only (e.g. type “CME” to find “ConcurrentModificationException”)

Find Resource
Use this to look for XML files, text files, or files of any other type. which are in your workspace.

Open Editor Drop-Down
Presents a popup window listing currently opened files. Start typing to limit the list or simply use the down arrow key.

Quick Outline
Use this to find a method or a member variable in a class. Start typing to limit the choices. Press Ctrl+O a second time to include inherited methods.

Content Assist
Context sensitive content completion suggestions while editing Java code.

Context Information
If typing a method call with several parameters use this to show the applicable parameter types. The current parameter where the cursor is will be shown in bold.

Organize Imports
After typing a class name use this shortcut to insert an import statement. This works if multiple class names haven’t been imported too.

Open Declaration
Drills down to the declaration of the type, method, or variable the cursor is on. This works much like a browser hyperlink.

Backward History
This works like a browser’s Back button.

Forward History
This works like a browser’s Forward button

Go to Line
Go to a specific line number.

Open Type Hierarchy
Show the type hierarchy (downward tree) or the supertype hierarchy (upward tree).

Open Call Hierarchy
Show where a method is called from. In the Call Hierarchy view keep expanding the tree to continue tracing the call chain.

Open Search Dialog
Opens a search dialog with extensive search options for Java packages, types, methods, and fields.

Rename – Refactoring
Use this to rename type, method, or field. All existing references will be refactored as well.

Extract Local Variable
Use this to create a local variable from the selected expression. This is useful for breaking up larger expressions to avoid long lines.

Extract Method
Use this to extract a new method from existing code. The parameter list and return type will be automatically created.


Select Enclosing Element / Restore Last Selection / Select Previous Element /
Select Next Element

Useful for selecting context-sensitive blocks (e.g. surrounding loop, method, class, etc.)


Scroll Line Up / Scroll Line Down
Very handy if you want to scroll by 1 line without changing your cursor position or using the mouse.


Go to Previous Member / Go to Next Member
Great for stepping down through the methods of a Java source file.


Show Occurrences in File / Remove Occurrences Annotations
Use this to search within the same file – useful for occurrences of private fields and methods.

Go to Matching Bracket
Helps to find the closing bracket of lengthly if-else statements.


Incremental Find / Reverse Incremental Find
The first matching occurrence is shown with each typed letter. Press again and the next matching occurrence is shown.


Insert Line Below / Insert Line Above
Insert a line above or below the current line.


Add Block Comment / Remove Block Comment
Comment in/out blocks of code with a key stroke.

Maximize Active View or Editor
Maximize the current view or editor at the expense of all other currently shown views. Press again to restore to normal view.


Next Editor / Next View / Next Perspective
Learn these to switch among edited files, open views and perspectives.


Duplicate Lines / Copy Lines
Doesn’t seem like it at first but a great shortcut once you learn to use it. Instead of select, copy and paste simply select and duplicate without affecting the clipboard.

Word Completion
This is excellent for code editing or writing plain help files with variables and other words having no English language equivalents. The word completion is based on the set of words already present in the current file.

Correct Indentation
Select a block of Java code or an entire class file and use this shortcut to correct its indentation.

Other Shortcuts

Leave a comment

Posted by on May 11, 2014 in Eclipse Shortcuts


Bubble Sort

Bubble sort, sometimes incorrectly 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 ofO(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.

The only significant advantage that bubble sort has over most other implementations, even quicksort, but not insertion sort, is that the ability to detect that the list is sorted is efficiently built into the algorithm. When the list is already sorted (best-case), the complexity of bubble sort is only O(n). By contrast, most other algorithms, even those with better average-case complexity, perform their entire sorting process on the set and thus are more complex. However, not only does insertion sort have this mechanism too, but it also performs better on a list that is substantially sorted (having a small number of inversions).

Bubble sort should be avoided in case of large collections. It will not be efficient in case of reverse ordered collection.

Rabbits and turtles

The positions of the elements in bubble sort will play a large part in determining its performance. Large elements at the beginning of the list do not pose a problem, as they are quickly swapped. Small elements towards the end, however, move to the beginning extremely slowly. This has led to these types of elements being named rabbits and turtles, respectively.

Various efforts have been made to eliminate turtles to improve upon the speed of bubble sort. Cocktail sort is a bi-directional bubble sort that goes from beginning to end, and then reverses itself, going end to beginning. It can move turtles fairly well, but it retains O(n2) worst-case complexity. Comb sort compares elements separated by large gaps, and can move turtles extremely quickly before proceeding to smaller and smaller gaps to smooth out the list. Its average speed is comparable to faster algorithms like quicksort.

Step-by-step example

Let us take the array of numbers “5 1 4 2 8”, and sort the array from lowest number to greatest number using bubble sort. In each step, elements written in bold are being compared. Three passes will be required.

First Pass:
5 1 4 2 8 ) –>( 1 5 4 2 8 ), Here, algorithm compares the first two elements, and swaps since 5 > 1.
( 1 5 4 2 8 ) –> ( 1 4 5 2 8 ), Swap since 5 > 4
( 1 4 5 2 8 ) –> ( 1 4 2 5 8 ), Swap since 5 > 2
( 1 4 2 5 8 ) –> ( 1 4 2 5 8 ), Now, since these elements are already in order (8 > 5), algorithm does not swap them.
Second Pass:
1 4 2 5 8 ) –> ( 1 4 2 5 8 )
( 1 4 2 5 8 ) –> ( 1 2 4 5 8 ), Swap since 4 > 2
( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
Now, the array is already sorted, but our algorithm does not know if it is completed. The algorithm needs one whole pass without any swap to know it is sorted.
Third Pass:
1 2 4 5 8 ) –> ( 1 2 4 5 8 )
( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )

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.


Pseudocode implementation

The algorithm can be expressed as (0-based array):

procedure bubbleSort( A : list of sortable items )
   n = length(A)
     swapped = false
     for i = 1 to  n-1 inclusive do
       /* if this pair is out of order */
       if A[i-1] > A[i] then
         /* swap them and remember something changed */
         swap( A[i-1], A[i] )
         swapped = true
       end if
     end for
   until not swapped
end procedure

Optimizing bubble sort

The bubble sort algorithm can be easily optimized by observing that the n-th pass finds the n-th largest element and puts it into its final place. So, the inner loop can avoid looking at the last n-1 items when running for the n-th time:

procedure bubbleSort( A : list of sortable items )
    n = length(A)
       swapped = false
       for i = 1 to n-1 inclusive do
          if A[i-1] > A[i] then
             swap(A[i-1], A[i])
             swapped = true
          end if
       end for
       n = n - 1
    until not swapped
end procedure

More generally, it can happen that more than one element is placed in their final position on a single pass. In particular, after every pass, all elements after the last swap are sorted, and do not need to be checked again. This allows us to skip over a lot of the elements, resulting in about a worst case 50% improvement in comparison count (though no improvement in swap counts), and adds very little complexity because the new code subsumes the “swapped” variable:

To accomplish this in pseudocode we write the following:

procedure bubbleSort( A : list of sortable items )
    n = length(A)
       newn = 0
       for i = 1 to n-1 inclusive do
          if A[i-1] > A[i] then
             swap(A[i-1], A[i])
             newn = i
          end if
       end for
       n = newn
    until n = 0
end procedure

Alternate modifications, such as the cocktail shaker sort attempt to improve on the bubble sort performance while keeping the same idea of repeatedly comparing and swapping adjacent items.

In practice

A bubble sort, a sorting algorithm that continuously steps through a list, swapping items until they appear in the correct order. The list was plotted in a Cartesian coordinate system, with each point (x,y) indicating that the value y is stored at index x. Then the list would be sorted by Bubble sort according to every pixel’s value. Note that the largest end gets sorted first, with smaller elements taking longer to move to their correct positions.

Although bubble sort is one of the simplest sorting algorithms to understand and implement, its O(n2) complexity means that its efficiency decreases dramatically on lists of more than a small number of elements. Even among simple O(n2) sorting algorithms, algorithms like insertion sort are usually considerably more efficient.

Due to its simplicity, bubble sort is often used to introduce the concept of an algorithm, or a sorting algorithm, to introductory computer science students. However, some researchers such as Owen Astrachan have gone to great lengths to disparage bubble sort and its continued popularity in computer science education, recommending that it no longer even be taught.

The Jargon file, which famously calls bogosort “the archetypical [sic] perversely awful algorithm”, also calls bubble sort “the generic bad algorithm”. Donald Knuth, in his famous book The Art of Computer Programming, concluded that “the bubble sort seems to have nothing to recommend it, except a catchy name and the fact that it leads to some interesting theoretical problems”, some of which he then discusses.

Bubble sort is asymptotically equivalent in running time to insertion sort in the worst case, but the two algorithms differ greatly in the number of swaps necessary. Experimental results such as those of Astrachan have also shown that insertion sort performs considerably better even on random lists. For these reasons many modern algorithm textbooks avoid using the bubble sort algorithm in favor of insertion sort.

Bubble sort also interacts poorly with modern CPU hardware. It requires at least twice as many writes as insertion sort, twice as many cache misses, and asymptotically more branch mispredictions. Experiments by Astrachan sorting strings in Java show bubble sort to be roughly 5 times slower than insertion sort and 40% slower than selection sort.

In computer graphics it is popular for its capability to detect a very small error (like swap of just two elements) in almost-sorted arrays and fix it with just linear complexity (2n). For example, it is used in a polygon filling algorithm, where bounding lines are sorted by their x coordinate at a specific scan line (a line parallel to x axis) and with incrementing y their order changes (two elements are swapped) only at intersections of two lines.


  • Odd-even sort is a parallel version of bubble sort, for message passing systems.
  • Cocktail sort is another parallel version of the bubble sort
  • In some cases, the sort works from right to left (the opposite direction), which is more appropriate for partially sorted lists, or lists with unsorted items added to the end.

Alone bubble sort

Alone bubble sort is a 1992 modification[citation needed] of the simple bubble sorting algorithm. Unlike the normal bubble sort where the loop resets after every performed swap of elements, in the alone bubble sort, the loop index only returns back by one step thus allowing the swapping to continue until a smaller value element in the array is reached. The following is the alone bubble realization (the algorithm only) in Pascal:

    for x:=1 to max-1 do
        if a[x]>a[x+1] then
                if f=false then d:=x;
                if x>1 then dec(x,2) else x:=0;
            if f=true then


Leave a comment

Posted by on May 10, 2014 in Bubble sort

The Code is True or False

блог за integer-ите и хората

Doncho Minkov

Doncho Minkov Blog

Блогът на Васил Василев

Place for Beginner Tips and Pro Mistakes

Asen's Software Blog

blog for c# & web programing

AniSoft Blog

blog for creative developers

The Daily Post

The Art and Craft of Blogging

The Blog

The latest news on and the WordPress community.