0% found this document useful (0 votes)
25 views

Computational Thinking, Problem-Solving and Programming:: IB Computer Science

The document discusses standard algorithms for linear arrays including sequential search, binary search, bubble sort, and selection sort. It provides descriptions of each algorithm, examples of their use cases, pseudocode representations, and links to video explanations.

Uploaded by

viggotudo
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)
25 views

Computational Thinking, Problem-Solving and Programming:: IB Computer Science

The document discusses standard algorithms for linear arrays including sequential search, binary search, bubble sort, and selection sort. It provides descriptions of each algorithm, examples of their use cases, pseudocode representations, and links to video explanations.

Uploaded by

viggotudo
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/ 21

Computational thinking,

problem-solving and programming:


Connecting computational thinking and program design
IB Computer Science

Content developed by
Dartford Grammar School
Computer Science Department
HL Topics 1-7, D1-4

1: System design 2: Computer 3: Networks 4: Computational


Organisation thinking

5: Abstract data 6: Resource 7: Control D: OOP


structures management

Content developed by Dartford Grammar School Computer Science Department


1: System design

HL & SL 4.2 Overview 2: Computer


Organisation

4.2.1 Describe the characteristics of standard algorithms on linear arrays


3: Networks
4.2.2 Outline the standard operations of collections

4.2.3 Discuss an algorithm to solve a specific problem


4: Computational
4.2.4 Analyse an algorithm presented as a flow chart thinking
4.2.5 Analyse an algorithm presented as pseudocode

4.2.6 Construct pseudocode to represent an algorithm


5: Abstract data
structures
4.2.7 Suggest suitable algorithms to solve a specific problem

4.2.8 Deduce the efficiency of an algorithm in the context of its use 6: Resource
management
4.2.9 Determine the number of times a step in an algorithm will be performed for given
input data

7: Control

D: OOP

Content developed by Dartford Grammar School Computer Science Department


Topic 4.2.1
Describe the characteristics of
standard algorithms on linear arrays

Content developed by Dartford Grammar School Computer Science Department


The four key standard algorithms:
• Sequential search
• Binary search
• Bubble sort
• Selection sort

Content developed by Dartford Grammar School Computer Science Department


Sequential search
• Linear search or sequential search is an algorithm to find an
item in a list.
• It starts at the first element and compares each element to
the one it’s looking for until it finds it.
• Commonly used with collections (which are unsorted lists of
items) and text/csv file reading.

Content developed by Dartford Grammar School Computer Science Department


Sequential search (video)

https://www.youtube.com/watch?v=CX2CYIJLwfg
Content developed by Dartford Grammar School Computer Science Department
Sequential search (Pseudocode)
NAMES = “Bob”,”Betty”,”Kim”,”Lucy”,”Dave”

output "These names start with D"

loop while NAMES.hasNext()


NAME = NAMES.getNext()
if firstLetter(NAME) = "D" then
output NAME
end if
end loop

Content developed by Dartford Grammar School Computer Science Department


Binary search
• Binary search, also known as half-interval search, is a search
algorithm that finds the position of a target value within a
sorted array.
• It works by comparing the target value to the middle
element of the array;
• If they are unequal, the lower or upper half of the array is
eliminated depending on the result and the search is
repeated in the remaining sub-array until it is successful.
• It only applies to SORTED arrays (where there are usually no
duplicate values, or duplicates do not matter)

Content developed by Dartford Grammar School Computer Science Department


Binary search (video)

https://www.youtube.com/watch?v=D5SrAga1pno
Content developed by Dartford Grammar School Computer Science Department
Binary search

Content developed by Dartford Grammar School Computer Science Department


Binary search

Content developed by Dartford Grammar School Computer Science Department


Binary search (Pseudocode)
ID = [1001,1002,1050,1100,1120,1180,1200,1400]
NAME = ["Apple","Cherry","Peach","Banana","Fig","Grape","Olive","Mango"]

output "Type the ID number that you wish to find"


input TARGET

LOW = 0
HIGH = 7
FOUND = -1

loop while FOUND = -1 AND LOW <= HIGH


MID = LOW + HIGH div 2
if ID[MID] = TARGET then
FOUND = MID
else if TARGET < ID[MID] then
HIGH = MID - 1
else
LOW = MID + 1
end if
end while

if FOUND >= 0 then


output TARGET , ":" , NAME[FOUND]
else
output TARGET , " was not found"
end if

Content developed by Dartford Grammar School Computer Science Department


Bubble sort
• Bubble sort is a simple sorting algorithm that repeatedly
steps through the list to be sorted, compares each pair of
adjacent items and swaps them if they are in the wrong
order.
• The pass through the list is repeated until no swaps are
needed, which indicates that the list is sorted.
• The algorithm, which is a comparison sort, is named for the
way smaller elements "bubble" to the top of the list.
• Although the algorithm is simple, it is too slow and
impractical for most problems

Content developed by Dartford Grammar School Computer Science Department


Bubble sort (video)

https://www.youtube.com/watch?v=8Kp-8OGwphY
Content developed by Dartford Grammar School Computer Science Department
Bubble sort

Content developed by Dartford Grammar School Computer Science Department


Bubble sort (Pseudocode)
NUMS = [15,30,85,25,40,90,50,65,20,60]

output "Before sorting"


loop C from 0 to 9
output NUMS[C]
end loop

loop PASS from 0 to 8


loop CURRENT from 0 to 8
if NUMS[CURRENT] < NUMS[CURRENT + 1] then
TEMP = NUMS[CURRENT]
NUMS[CURRENT] = NUMS[CURRENT+1]
NUMS[CURRENT+1] = TEMP
end if
end loop
end loop

Content developed by Dartford Grammar School Computer Science Department


Selection sort
• Selection sort is a sorting algorithm and it is inefficient on large lists
• Selection sort is noted for its simplicity, and it has performance
advantages over more complicated algorithms in certain situations,
particularly where memory is limited.
• The algorithm divides the input list into two parts: the sublist of items
already sorted, which is built up from left to right at the front (left) of the
list, and the sublist of items remaining to be sorted that occupy the rest
of the list.
• Initially, the sorted sublist is empty and the unsorted sublist is the entire
input list.
• The algorithm proceeds by finding the smallest (or largest, depending on
sorting order) element in the unsorted sublist, exchanging (swapping) it
with the leftmost unsorted element (putting it in sorted order), and
moving the sublist boundaries one element to the right.

Content developed by Dartford Grammar School Computer Science Department


Selection sort (video)

https://www.youtube.com/watch?v=f8hXR_Hvybo
Content developed by Dartford Grammar School Computer Science Department
Content developed by Dartford Grammar School Computer Science Department
Selection sort (Pseudocode)
A - an array containing the list of numbers
numItems - the number of numbers in the list

for i = 0 to numItems - 1
for j = i+1 to numItems
if A[i] > A[j]
// Swap the entries
Temp = A[i]
A[i] = A[j]
A[j] = Temp
end if
end loop
end loop

Content developed by Dartford Grammar School Computer Science Department

You might also like