Computer Science 0478 paper 2 notes, Study notes of Computer science

Computer Science, 2023-2025,Mr Chuma

Typology: Study notes

2023/2024
On special offer
30 Points
Discount

Limited-time offer


Uploaded on 06/25/2024

albert-chuma
albert-chuma 🇧🇼

2 documents

1 / 49

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
COMPUTER SCIENCE PAPER 2 NOTES by Albert T Chuma
Algorithm design and problem solving | Programming | Databases |Boolean logic
Algorithm design and problem solving
The stages in the program development cycle:
analysis
design
coding
testing
computer systems and sub-systems
problem decomposition into component parts
methods used to design and construct solutions to problems
the purpose of an algorithm and the processes involved in it
standard methods of solution:
linear search
bubble sort
totalling
counting
finding average, maximum, minimum
validation checks when data is input
verification checks when data is input
use of different types of test data including:
documentation of a dry run using a trace table
writing, amending, identifying, and correcting errors in:
flowcharts
programs
pseudocode.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
Discount

On special offer

Partial preview of the text

Download Computer Science 0478 paper 2 notes and more Study notes Computer science in PDF only on Docsity!

COMPUTER SCIENCE PAPER 2 NOTES by Albert T Chuma

Algorithm design and problem solving | Programming | Databases |Boolean logic

Algorithm design and problem solving

The stages in the program development cycle:

  • analysis
  • design
  • coding
  • testing ★ computer systems and sub-systems ★ problem decomposition into component parts ★ methods used to design and construct solutions to problems ★ the purpose of an algorithm and the processes involved in it ★ standard methods of solution:
  • linear search
  • bubble sort
  • totalling
  • counting
  • finding average, maximum, minimum ★ validation checks when data is input ★ verification checks when data is input ★ use of different types of test data including:
  • documentation of a dry run using a trace table ★ writing, amending, identifying, and correcting errors in:
  • flowcharts
  • programs
  • pseudocode.

The program development life cycle The program development life cycle is divided into five stages: analysis, design, coding, testing and maintenance. Four stages; » analysis » design » coding » testing Analysis

  • Before solving a problem, it is essential to define and document the problem clearly, known as the "requirements specification" for the program.
  • The analysis stage involves using tools like abstraction and decomposition to identify the specific requirements for the program.
  • Abstraction focuses on the essential elements needed for the solution while eliminating unnecessary details and information.
  • Decomposition involves breaking down complex problems into smaller, more manageable parts that can be solved individually.
  • Daily tasks can be decomposed into their constituent parts for easier understanding and solving. Design
  • The program specification derived from the analysis stage is used as a guide for program development.
  • During the design stage, the programmer should have a clear understanding of the tasks to be completed, the methods for performing each task, and how the tasks will work together.
  • Documentation methods such as structure charts, flowcharts, and pseudocode can be used to formally document the design of the program. Coding and iterative testing
  • The program or set of programs is developed based on the design.
  • Each module of the program is written using a suitable programming language.
  • Testing is conducted to ensure that each module functions correctly.
  • Iterative testing is performed, which involves conducting modular tests, making code amendments if necessary, and repeating tests until the module meets the required functionality. Testing
  • The completed program or set of programs is executed multiple times using various sets of test data.
  • This testing process ensures that all the tasks within the program work together as specified in the program design.
  • By running the program with different test data, potential issues and errors can be identified and addressed.
  • The testing phase aims to verify the overall functionality and performance of the program by evaluating its behavior with a variety of inputs.

Methods used to design and construct a solution to a problem Solutions to problems need to be designed and developed rigorously. The use of formal methods enables the process to be clearly shown for others to understand the proposed solution. The methods are: » structure diagrams » flowcharts » pseudocode Structure diagrams - can be used to show top-down design in a diagrammatic form. Structure diagrams are hierarchical, showing how a computer system solution can be divided into sub-systems with each level giving a more detailed breakdown. If necessary, each sub-system can be further divided. Example: Alarm app for a smart phone Activity; Break down the ‘Check time’ sub-system from the smart phone alarm app into further sub- systems Flowcharts A flowchart shows diagrammatically the steps required to complete a task and the order that they are to be performed. These steps, together with the order, are called an algorithm. Flowcharts are an effective way to communicate how the algorithm that makes up a system or sub-system works. Example; Checking for the alarm time Flowchart for check time sub-system

Pseudocode Pseudocode is a simple method of showing an algorithm. It describes what the algorithm does by using English key words that are very similar to those used in a high-level programming language. Data items to be processed by the algorithm are given meaningful names in the same way that variables and constants are in a high-level programming language. However, pseudocode is not bound by the strict syntax rules of a programming language. It does what its name says, it pretends to be programming code! Pseudocode is used to help you understand algorithms easily;

  • a non-proportional font is used throughout
    • all keywords (words used to describe a specific action e.g. INPUT) are written in capital letters
    • all names given to data items and subroutines start with a capital letter
    • where conditional and loop statements are used, repeated or selected statements are indented by two spaces. Statements The pseudocode for an assignment statement A value is assigned to an item/variable using the ←operator. The variable on the left of the ← is assigned the value of the expression on the right. The expression on the right can be a single value or several values combined with any of the following mathematical operators. Examples of pseudocode assignment statements

For example: » Comparisons made by using comparison operators, where comparisons are made from left to right, for example: A > B means ‘A is greater than B’ Comparisons can be simple or more complicated, for example:

The algorithm below that checks if a percentage mark is valid and whether it is a pass or a fail. This makes use of two IF statements; the second IF statement is part of the first ELSE path. This is called a nested IF. Activity; Re-write the algorithm to check for a mark between 0 and 20 and a pass mark of 10. CASE OF … OTHERWISE … ENDCASE For a CASE statement the value of the variable decides the path to be taken. Several values are usually specified. OTHERWISE is the path taken for all other values. The end of the statement is shown by ENDCASE. Have a look at the algorithm below that specifies what happens if the value of Choice is 1, 2, 3 or 4. The pseudocode for iteration When some actions performed as part of an algorithm need repeating this is called iteration. Loop structures are used to perform the iteration.

REPEAT … UNTIL loop This loop structure is used when the number of repetitions/iterations is not known and the actions are repeated UNTIL a given condition becomes true. The actions in this loop are always completed at least once. This is a post-condition loop as the test for exiting the loop is at the end of the loop. WHILE … DO … ENDWHILE loop This loop structure is used when the number of repetitions/iterations is not known and the actions are only repeated WHILE a given condition is true. If the WHILE condition is untrue then the actions in this loop are never performed. This is a pre-condition loop as the test for exiting the loop is at the beginning of the loop. The pseudocode for input and output statements INPUT and OUTPUT are used for the entry of data and display of information. Sometimes READ can be used instead of INPUT but this is usually used for reading from files. Also, PRINT can be used instead of OUTPUT if a hard copy is required. INPUT is used for data entry; it is usually followed by a variable where the data input is stored, for example: OUTPUT is used to display information either on a screen or printed on paper; it is usually followed by a single value that is a string or a variable, or a list of values separated by commas, for example:

Explaining the purpose of an algorithm An algorithm sets out the steps to complete a given task. This is usually shown as a flowchart or pseudocode, so that the purpose of the task and the processes needed to complete it are clear to those who study it. You will be able to practice this skill as you become more familiar with writing and finding and correcting errors in algorithms. Example; Output an alarm sound The purpose of the following pseudocode is to output the alarm sound at the appropriate time. The processes are: waiting 10 seconds, getting the current time, checking the current time with the alarm time, and outputting the alarm sound when the times match. Standard methods of solution The ability to repeat existing methods is very important in the design of algorithms; when an algorithm is turned into a program the same methods may be repeated many thousands of times. You need to be able to use and understand these standard methods used in algorithms:

  • Totaling
  • Counting
  • Finding maximum, minimum, and average (mean) values
  • Searching using a linear search
  • Sorting using a bubble sort. All the standard methods of solution are shown as pseudocode algorithms and will be used to practice program writing.

Maximum, minimum and average Finding the largest and smallest values in a list are two standard methods that are frequently found in algorithms, for example, finding the highest and lowest mark awarded to a class of students. If the largest and smallest values are not known, an alternative method is to set the maximum and minimum values to the first item in the list. For example, using this method to find the highest and lowest mark awarded to a class of students. Calculating the average (mean) of all the values in a list is an extension of the totalling method, for example, calculating the average mark for a class of students

Linear search A search is used to check if a value is stored in a list, performed by systematically working through the items in the list. This is called a linear search, which inspects each item in a list in turn to see if the item matches the value searched for. For example, searching for a name in a class list of student names, where all the names stored are different: Bubble sort This method of sorting is called a bubble sort. Each element is compared with the next element and swapped if the elements are in the wrong order, starting from the first element and finishing with next-to-last element. Once it reaches the end of the list, we can be sure that the last element is now in the correct place. However, other items in the list may still be out of order. Each element in the list is compared again apart from the last one because we know the final element is in the correct place. This continues to repeat until there is only one element left to check or no swaps are made.

Range check A range check checks that the value of a number is between an upper value and a lower value. For example, checking that percentage marks are between 0 and 100 inclusive: Length check A length check checks either: that data contains an exact number of characters, for example that a password must be exactly eight characters in length so that passwords with seven or fewer characters or nine or more characters would be rejected, for instance or that the data entered is a reasonable number of characters, for example, a family name could be between two and thirty characters inclusive so that names with one character or thirty-one or more characters would be rejected.

Type check A type check checks that the data entered is of a given data type, for example, that the number of brothers or sisters would be an integer (whole number). Presence check A presence check checks to ensure that some data has been entered and the value has not been left blank, for example, an email address for an online transaction must be completed. Format check and check digit Format check A format check checks that the characters entered conform to a pre-defined pattern Check digit

  • A check digit is the final digit included in a code; it is calculated from all the other digits in the code.
  • Check digits are used for barcodes, product codes, International Standard Book Numbers (ISBN) and Vehicle Identification Numbers (VIN).