Binary

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

sorting :

bubble
1 start from the brgining of the list
2 compare position 1 and position 2 and if they are not in an ascending order then
swap them
3 compare position 2 and 3 and swap if needed
4 continue this unitl the end if the list
5 if there is any sawps repeat steps from 1 to 4

searching :

linear
1 Start at the first item in the list.
2 Compare the item with the search item.
3 If they are the same, then stop.
4 If they are not, then move to the next item.
5 Repeat 2 to 4 until the end of the list is reached

1 start at rh first item inthe list


2 compare theitem with the search number
3 if they aare the same then stop
4if they are not hen move to the next item
5repeat 2 to 4 intil the end of the list

binary
Select the median item of the list.
2 If the median item is equal to the search item, then stop.
3 If the median is too high, then repeat 1 and 2 with the sub-list to the left.
4 If the median is too low, then repeat 1 and 2 with the sub-list to the right.
5 Repeat steps 3 and 4 until the item has been found or all of the items
have been checked

1 selct the median item from the list


2 if the median item is equal to the search item then stop
3 if the median is too high then repeat 1 and 2 with the sublist to the lest
4 of the median is too low then repeat 1 and 2 with thw sublist to the right
5 repeat step 3 and 4 until item has been found or all of the items have been
checked

binary
1 select eh median from the lsit
2 if the search equals the median then stop
3 if the median is too high then repeat 1 and 2 to the sublist from the left
4 if the median is too low then repeat 1 and 2 to the sublist to the right
repeat until value found or the until the list ends

median equals the forst vafirst position minus the final divided by 2

You might also like