Algorithms
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) :
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
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)
Python Insertion Sort Example 2
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.
Binary Sort Algorithm
Binary Sort (aka half-interval search/logarithmic search) is a search algorithm that finds a target value within a sorted array by comparing the target to the middle element, if unequal, the half of integers where the target cannot lie is unlimited. This process is continued unless target is identified.
EX: 1, 7, 27, 33, 45, 57 , 66, 77, 89, 99, 101, 129, 156, 234
Find: Number 77 a. Identify the middle value of the sorted array : 66 b. Eliminate the lower half of the array integers [>66] since the integer we are looking for is 77. c. Continue this median allocation and deletion until correct integer in the array is isolated and selected.
Example Python Code
Python Binary Sort Example 1
<syntaxhighlight lang="cpp"> def binarySearch(alist, item):
first = 0 last = len(alist)- 1 found = False
while first <=last and not found: midpoint = (first + last)// 2 if alist[midpoint] == item found = True
else: if item < alist[midpoint]: last = midpoint - 1 else: first = midpoint + 1
return found
Heap Sort Algorithm