Last saved 103 days ago

OCR A Level CS - Software development T2 Writing and following algorithms

robot
knowt logo

OCR A Level CS - Software development T2 Writing and following algorithms

OCR Writing and Following Algorithms

A Level Unit 3 Computer Science Software Development

H446 - Paper 1 PG ONLINE

Objectives

  • Understand the term "algorithm"

  • Learn how to write algorithms using pseudocode

  • Learn how to interpret algorithms and determine their purpose

Definition of an Algorithm

An algorithm is a set of instructions to solve a problem or complete a well-defined task in a finite number of steps.Examples:

  • Recipe for chocolate cake

  • Knitting pattern

Computational Algorithms

Examples of computational algorithms are numerous. Algorithms are used to solve various real-world problems, many of which remain unsolved today.

Problems Solved by Algorithms

Routing Problems:

  • Routing packets of data around the Internet by the shortest route

  • Finding the shortest route for a salesman

  • Timetabling for commercial aircraft crews

Other Applications:

  • Searching information on the Internet or a database

  • Encrypting communications

  • Sorting large amounts of data

  • Writing a compiler to translate high-level languages to machine code

Properties of a Good Algorithm

Engage in group discussions to create a list of properties.

Characteristics of a Good Algorithm

  • Clear and precisely stated steps that produce correct output for valid inputs.

  • Should allow for invalid inputs.

  • Must always terminate at some point.

  • Should perform tasks efficiently with minimal steps.

  • Designed to be understandable and modifiable by others.

Using Pseudocode

Pseudocode bridges English statements and program code, and is mostly independent of specific programming languages.

Guidelines for Writing Pseudocode

  • Clarity: Should be clear and easy to read.

  • Consistency: Maintain a consistent style throughout.

  • Simplicity: Avoid overcomplication.

  • No Strict Syntax: Common programming constructs can be used.

  • One Statement per Line: Each line should represent a single action or decision.

  • Use Indentation: Represent structure and hierarchy of the code.

  • Goal: Help understand the algorithm's flow without syntax confusion.

Sorting Algorithms

Vary from simple and slow (e.g., insertion sort) to complex and fast (e.g., merge sort). A fast sort may sort ten million numbers in 20 minutes, while an inefficient one may take over a month.

Bubble Sort

Simple sorting method: compares adjacent items and swaps if larger. On the first pass, the largest item "bubbles" to the end of the list.

Worksheet 2

Try Task 1 on Worksheet 2 PG.ONLINE.

Pseudocode for Bubble Sort

Code example provided:names = ["Jane", "Fred", "Vicky", "Eric", "Bella", "Millie"]Looping mechanism controlling passes and comparisons.

Bubble Sort Example

Given names: ["Henry", "Steve", "Julie", "Ava", "Tom", "Olivia"]. After one pass, determine the order and number of passes needed to sort. Write an algorithm to swap two items.

Searching Algorithms

Common algorithms include linear search (examines every item) and binary search (divides the search area). Binary search requires sorted order, applicable to either alphabetic or numeric items.

Binary Search Algorithm

  • Low and high are indices of first and last items in the list.

  • While loop for finding a value: condition checks and updates.

Interactive Activity

Guess a number between 1 and 100; partner gives feedback on guess. Discuss how many guesses needed and contrast with a sequential search.

Evaluating a Program

Discuss efficiency of algorithms and ways to enhance program quality.

Writing Good Programs

Use comments for documentation. Standard identifiers, proper indentation, and modular structures are recommended.

Following an Algorithm

Following through algorithms can be challenging; use a trace table to track variable changes.

Creating a Trace Table

Example code shown for tracing: starts with values and evaluates conditions. Track changes in the table for each iteration.

Algorithm Calculation

Determine what the traced algorithm calculates based on inputs and changes.

Worksheet 2

Attempt questions in Task 2 of the worksheet.

Plenary

Importance of pseudocode in designing algorithms. Understanding sorting and searching as key operations in data processing. Trace tables are vital for algorithm evaluation.

Copyright Notice

Copyright © 2016 PG Online Limited on unit contents and restrictions on use.