# Difference between revisions of "Algorithms"

Line 17: | Line 17: | ||

Sample Input : [ 8, 3, 9, 0, 2, 7, 4, 5 ] | Sample Input : [ 8, 3, 9, 0, 2, 7, 4, 5 ] | ||

+ | |||

Sample Output : [ 0, 2, 3, 4, 5, 7, 8, 9 ] | Sample Output : [ 0, 2, 3, 4, 5, 7, 8, 9 ] | ||

Line 61: | Line 62: | ||

###from previous number in array, print in natural order. | ###from previous number in array, print in natural order. | ||

</syntaxhighlight> | </syntaxhighlight> | ||

+ | |||

+ | |||

+ | '''HeapSort Algorithm''' | ||

+ | ---- | ||

=== Which Algorithms Are Best Suited for Which Tasks === | === Which Algorithms Are Best Suited for Which Tasks === |

## Revision as of 14:38, 13 December 2016

**Algorithms** are a type of technology used in multiple fields of study that dictate or alter streams of information (in this case we will most be referring to computer science). The code/pseuocode presented on here will be written in Python (### syntax in the code represents comments made in Python code).

Case Uses For Implementing Algorithms (Engineering and Computer Science) :

## Contents

### Common Computer Science Algorithms

Algorithms used in Computer Science are developed and implemented to alter the way data moves in network somehow ( the network representing the collection of data used to create a program/system )

The most common present:

**Insertion Sort**

**Insertion Sort** (sorting algorithm for small number of elements): This Algorithm rearranges a disordered list of integers and rearranges them in natural order.
This algorithm is typically used for small array of elements.

Sample Input : [ 8, 3, 9, 0, 2, 7, 4, 5 ]

Sample Output : [ 0, 2, 3, 4, 5, 7, 8, 9 ]

**Example Python Code**

Python Insertion Sort Example 1

<syntaxhighlight lang="cpp"> def insertionSort(alist):

for index in range(1,len(alist)):

currentvalue = alist[index] position = index

while position>0 and alist[position-1]>currentvalue: #print integers in natural order[-1] less than the previous number alist[position]=alist[position-1] position = position-1

alist[position]=currentvalue

alist = [54,26,93,17,77,31,44,55,20] ### this is the array of integers that will be sorted in natural order 0-infinity insertionSort(alist) print(alist) </syntaxhighlight>

Python Insertion Sort Example 2

<syntaxhighlight lang="cpp"> function insertionSort(array A)

for i from 1 to length[A]-1 do value := A[i] j := i-1 while j >= 0 and A[j] > value do A[j+1] := A[j] j := j-1 done A[j+1] = value done

- Syntax states to apply InsertionSort to Array of Integers named A. from 1 to any number -1
- from previous number in array, print in natural order.

</syntaxhighlight>

**HeapSort Algorithm**