Library › Computer Science 9618 › Computational Thinking and Problem-solving
AS Level · Computer Science 9618

Computational Thinking and Problem-solving

Revise Computational Thinking and Problem-solving for Computer Science 9618 (AS Level) — revision notes and instant AI marking.

📖 Revision notes · preview
  Cambridge International AS & A Level Computer Science (9618)

Computational Thinking and Problem-solving

The big idea: A Level algorithms are about choosing well: which search, which sort, which data structure, and how their cost grows as the data grows. Recursion adds a new way to think: solve a problem by solving a smaller copy of it.

Summary — What This Chapter Covers
  • Linear search checks every item in turn: O(n). Binary search halves a sorted list each step: O(log n).
  • Bubble sort and insertion sort are both O(n2) in the worst case; on nearly sorted data they approach O(n).
  • ADTs: stack (LIFO), queue (FIFO), linked list, binary tree, dictionary, graph. They are built from arrays, records and pointers, or from other ADTs.
  • Write algorithms to find, insert and delete items in these structures.
  • Big O describes how time or memory grows with the number of items.
  • Recursion: a subroutine that calls itself, with a base case and a general case that moves towards it.
  • Each recursive call is pushed on the call stack (parameters, local variables, return address) and the stack unwinds as calls return.
1. Searching
19.1

Linear and binary search

A linear search checks each element from the start until the item is found or the list ends. It works on any list, sorted or not.

FUNCTION LinearSearch(SearchItem : INTEGER) RETURNS INTEGER
   DECLARE Index : INTEGER
   Index ← 1
   WHILE Index <= 15
      IF Data[Index] = SearchItem THEN
         RETURN Index
      ENDIF
      Index ← Index + 1
   ENDWHILE
   RETURN -1
ENDFUNCTION

A binary search needs the data to be sorted. It looks at the middle item: if that is the item, stop; if the item is bigger, discard the lower half; if smaller, discard the upper half. Repeat on the half that is left until the item is found or no items remain.

FUNCTION BinarySearch(SearchItem : INTEGER) RETURNS INTEGER
   DECLARE Lower : INTEGER
   DECLARE Upper : INTEGER
   DECLARE Middle : INTEGER
   Lower ← 1
   Upper ← 15
   WHILE Lower <= Upper
      Middle ← (Lower + Upper) DIV 2
      IF Data[Middle] = SearchItem THEN
         RETURN Middle
      ELSE
         IF Data[Middle] < SearchItem THEN
            Lower ← Middle + 1
         ELSE
            Upper ← Middle - 1
         ENDIF
      ENDIF
   ENDWHILE
   RETURN -1
ENDFUNCTION

Performance: every comparison halves the items left, so the maximum number of comparisons for n items is about log2 n + 1: 4 for 15 items, 10 for 1000, 20 for 1 000 000. A linear search may need n comparisons. Doubling the data adds only one comparison to a binary search but doubles the worst case of a linear search.

Worked Example
Data[1:15] = 3, 8, 12, 17, 21, 25, 30, 34, 41, 46, 52, 58, 63, 70, 77. Trace BinarySearch for 58 and for 20.
2. Sorting
19.1

Bubble sort and insertion sort

Bubble sort compares each pair of neighbours and swaps them if they are in the wrong order. After each pass the largest remaining item has "bubbled" to the end, so each pass can stop one place earlier. A flag records whether any swap happened; a pass with no swaps means the data is sorted.

3. Abstract Data Types
19.1

Stack, queue, linked list, binary tree, graph, dictionary

abstract data type (ADT) implemented from built-in types other ADTs

Stack (last in, first out)
4. Comparing Algorithms: Big O
19.1

Time and space complexity

time memory

2
n
🔓 Read the full Computational Thinking and Problem-solving note → You're seeing the preview · sign in to read it all
Also in the full note
  • Base case, general case, unwinding
What's inside
📖 Revision notes 🎯 Learn mode ✦ AI flashcards ✓ Instant AI marking 🧊 3D explorers 🧪 Experiments & simulations 📈 Progress tracking
📄 Practise Computational Thinking and Problem-solving with Computer Science 9618 past papers Every paper with its mark scheme — answer online, marked instantly. Open →

Read the full Computational Thinking and Problem-solving notes free

That's the preview — create a free account to read the rest, plus flashcards and practice questions with instant AI marking. No credit card.

Unlock the full notes free →

More Computer Science topics