0% found this document useful (0 votes)
13 views2 pages

Prog Reviewer

Bubble sort, insertion sort, selection sort, quick sort, and merge sort are algorithms that sort elements in an array or list. Bubble sort repeatedly compares adjacent elements and swaps them if they are in the wrong order. Insertion sort inserts each element into the sorted position. Selection sort selects the smallest element and swaps it into the first position. Quick sort uses a pivot element to partition the array into sub-arrays. Merge sort divides the array into halves and then merges the sorted halves. Variables in Python can contain letters, numbers, and underscores but not spaces and certain characters. Math operators in Python include +, -, *, /, //, %, and **. For loops iterate over a range of numbers.

Uploaded by

Irish Mae
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Prog Reviewer

Bubble sort, insertion sort, selection sort, quick sort, and merge sort are algorithms that sort elements in an array or list. Bubble sort repeatedly compares adjacent elements and swaps them if they are in the wrong order. Insertion sort inserts each element into the sorted position. Selection sort selects the smallest element and swaps it into the first position. Quick sort uses a pivot element to partition the array into sub-arrays. Merge sort divides the array into halves and then merges the sorted halves. Variables in Python can contain letters, numbers, and underscores but not spaces and certain characters. Math operators in Python include +, -, *, /, //, %, and **. For loops iterate over a range of numbers.

Uploaded by

Irish Mae
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

BUBBLE SORT GETTING INPUT

Bubble sort, also known as sinking sort, is a simple Structure:


algorithm wherein a string of elements is arranged variable name = input ( ‘Enter Number’ )
in correct order by repeatedly stepping through the
Eval Function:
input element by element. Each element is being
num = eval ( input ( ‘Enter Number’ ) )
compared to its adjacent element and switch their
print ( ‘Your number squared is: ’, num*num )
positions if needed.
VARIABLES
INSERTION SORT
• Can contain letters, numbers, and underscores
Insertion sort technique begins with comparing the
• Can’t contain spaces
second element with the first element then switches
their position if necessary. This process is performed • Can’t start with number
for the subsequent elements. This sorting technique • Case matters (a ≠ A)
compares each element with all the previous INTEGERS & DECIMAL NUMBERS
elements and insert it in its right position. • Integers has no restrictions
SELECTION SORT • You can only get about 15 digits of precision
In selection sorting technique, the smallest value in • In decimal numbers, the last digit is slightly off, it
a given list of element or array is selected and is called round off error
swapped with the first element if necessary or if it is Example: 7/3 = 2.3333333333333335
smaller than the first element. After that, the MATH OPERATORS
program proceeds in swapping the second element
OPERATORS DESCRIPTION
of the array with the second smallest element. In + Addition
every pass, the smaller elements in the array are - Subtraction
selected and put in their proper position until the * Multiplication
sorting process is done. / Division
Integer Division
QUICK SORT
(No decimal
Quick Sort is a sorting algorithm that uses a selected //
remainder/decimal
element called “pivot” and partitions the array into
point)
two parts based on the pivot’s value. The elements % Modulo
that are less than the pivot are put to the left, Exponentiation
whereas the elements that are larger or higher than **
(Square)
the pivot are put to the right. The sub-lists that are
created will be sorted as the quicksort calls itself FOR LOOPS
recursively until all the elements are positioned Structure:
properly. for variable name in range (number of loops):
statements
MERGE SORT
Merge sort algorithm is based on the principle of Example:
Divide and Conquer Algorithm. In this algorithm for i in range (3):
strategy, we divide the main problem into print (‘Hello’, end = ‘X’)
subproblems and solve them individually. After print (‘Done’)
solving them, they will be combined to form a Output:
HelloXHelloXHelloXDone
general solution.
Output:
for i in range (101) 1
print (i + 1) 2
3

100

THE RANGE FUNCTION (range (start, end, steps))


STATEMENT VALUES
range (10) 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
range (1, 10) 1, 2, 3, 4, 5, 6, 7, 8, 9
range (2, 15, 3) 2, 5, 8, 11, 14
range (9, 2, -1) 9, 8, 7, 6, 5, 4, 3
IF STATEMENTS
Structure:
if condition:
statements
Example:
IF AND USING
CONDITIONAL ELIF
OPERATORS

x= int(input(‘Enter Number’)) x= input (‘Enter Number’)


if x >= 90 and x <= 100: if x >= 90:
print (‘A’) print (‘A’)
if x >= 80 and x < 90: elif x >= 80:
print (‘B’) print (‘B’)
if x < 80 or x > 100: else:
print (‘Invalid Grade’) print (‘Invalid Grade’)

CONDITIONAL OPERATORS
AND OR
T T =T T T =T
T F =F T F =T
F T =F F T =T
F F =F F F =F

You might also like