ALGORITHMS
Definition of different search algorithms:
Linear search (works on an unsorted list) - check each item (in a list/array) until value you are looking for is found
Binary search (only works on a sorted list) Step 1) half the list
Step 2) if the value is greater than first half discard the first half
Step 3) if the value is less than first half discard the second half
Step 4) repeat steps until value found
Linear search (works on an unsorted list) - check each item (in a list/array) until value you are looking for is found
Binary search (only works on a sorted list) Step 1) half the list
Step 2) if the value is greater than first half discard the first half
Step 3) if the value is less than first half discard the second half
Step 4) repeat steps until value found
Definition of different sort algorithms:
Merge sort - the divide and conquer!
Bubble sort - go through the unsorted list in pairs, swap if smaller number is on the right, keep going until the end of the list, then do another pass, and then another until all the numbers are sorted. |
There a several algorithms that you need to know for the exam.
Example program for adding to a sum total (using a for loop and an array):
i is integer
total is integer
set total = 0
numbers is integer
numbers[5]
for i = 0 to 4
input numbers[i]
output “Adding ” numbers[i]
total = total + numbers[i]
next
output “Total is ” total
output “Average is” (total/5)
i is integer
total is integer
set total = 0
numbers is integer
numbers[5]
for i = 0 to 4
input numbers[i]
output “Adding ” numbers[i]
total = total + numbers[i]
next
output “Total is ” total
output “Average is” (total/5)
Example program for working out minimum and maximum numbers input:
min is integer
max is integer
set min = 8
set max = 1
numbers is integer
numbers[5]
for i = 0 to 3
input numbers[i]
if min > numbers[i]:
min = numbers[i]
endif
if max < numbers[i]:
max = numbers[i]
endif
next
output “Minimum is ” min
output “Maximum is” max
min is integer
max is integer
set min = 8
set max = 1
numbers is integer
numbers[5]
for i = 0 to 3
input numbers[i]
if min > numbers[i]:
min = numbers[i]
endif
if max < numbers[i]:
max = numbers[i]
endif
next
output “Minimum is ” min
output “Maximum is” max
The 'Serial Search' Algorithm
This algorithm is used to search for a specific value in an array.
This algorithm is used to search for a specific value in an array.
numbers is integer
set numbers = [4,7,5,6,2] num is integer input num # e.g. 5 for i = 0 to 4 if num = numbers[i]: output “Found” endif next |
Example program for searching for the smallest number in an array:
mi is integer # will store the index for the smallest number
set mi = 0
min is integer
numbers is integer
numbers[5]
for i = 0 to 4 # first, a loop to input number into an array
input numbers[i] # e.g. 5 3 8 2 6
next
found
for i = 0 to 4
if numbers[mi] > numbers[i]: # if you are searching for the largest use < instead of >
mi = i
endif
next
min = numbers[mi]
output “Minimum is ” min
mi is integer # will store the index for the smallest number
set mi = 0
min is integer
numbers is integer
numbers[5]
for i = 0 to 4 # first, a loop to input number into an array
input numbers[i] # e.g. 5 3 8 2 6
next
found
for i = 0 to 4
if numbers[mi] > numbers[i]: # if you are searching for the largest use < instead of >
mi = i
endif
next
min = numbers[mi]
output “Minimum is ” min
![](http://www.weebly.com/weebly/images/file_icons/pdf.png)
flash_cards_revision_-_add_move_and_eat.pdf | |
File Size: | 352 kb |
File Type: |
HTML - try creating the webpage below using HTML code.
Using Notepad, insert the HTML tags that would be needed to display the content and formatting shown.
The image file you require is called firewall.jpg
The page title should be set to Cybersecurity Briefing.
Save your new web page as finalAdvert.txt
Make sure you test your solution as an HTML page to ensure it works... remember to use SAVE AS, then change the file type to 'All Files' and put .html at the end of the filename.
The image file you require is called firewall.jpg
The page title should be set to Cybersecurity Briefing.
Save your new web page as finalAdvert.txt
Make sure you test your solution as an HTML page to ensure it works... remember to use SAVE AS, then change the file type to 'All Files' and put .html at the end of the filename.
Get help from the HTML example below - all of the code that you need can be seen in an example of a DIFFERENT webpage seen below. Refer to this when you get stuck!
<blockquote>To be or not to be</blockquote> - this tag would indent "To be or not to be" from the right and left margins.
MORE TO COME SO KEEP CHECKING FOR UPDATES...