OCR A Level CS 2.3.4 Searching Algorithms

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/13

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

14 Terms

1
New cards

What is the purpose of a searching algorithm?

To find a specific element in a data structure, such as an array or list.

2
New cards

What are the two standard searching algorithms in OCR A-Level?

Linear Search
Binary Search

3
New cards

How does linear search work?

It checks each element one by one until it finds the target or reaches the end.

4
New cards

What is the time complexity of linear search?

O(n) – Worst case, it checks every element.

5
New cards

What is an advantage of linear search?

Works on unsorted data.

6
New cards

What is a disadvantage of linear search?

Slow for large data sets.

7
New cards

Pseudocode for linear search:

i = 0

while i < A.length:

if A[i] == x:

return i

else:

i = i + 1

return "Not found"

8
New cards

How does binary search work?

It finds the middle element, checks if it's the target, and then eliminates half of the remaining data.

9
New cards

What is the time complexity of binary search?

O(log n) – It halves the data each step, making it much faster than linear search.

10
New cards

What is a key requirement for binary search?

The data must be sorted.

11
New cards

What is an advantage of binary search?

Much faster than linear search for large data sets.

12
New cards

What is a disadvantage of binary search?

Only works on sorted data.

13
New cards

Pseudocode for binary search:

low = 0

high = A.length - 1

while low <= high:

mid = (low + high) / 2

if A[mid] == x:

return mid

else if A[mid] > x:

high = mid - 1

else:

low = mid + 1

return "Not found"

14
New cards

Comparing Linear and Binary Search

Feature

Linear Search

Binary Search

Best for...

Small datasets or unsorted data

Large datasets, sorted data

Time Complexity

O(n) (Slow)

O(log n) (Fast)

Requires Sorting?

No

Yes

Efficiency

Inefficient for large data

Highly efficient