Grade 11 Computer Science: Algorithms Notes (Kenya) | YNetStudyHub

Algorithms

Grade 11 · Computer Science 4 min read

Introduction

In computer science, algorithms are a set of well-defined instructions or rules designed to solve a specific problem. They are essential in programming as they provide a step-by-step guide on how to perform a task efficiently. Understanding algorithms is crucial for developing logical thinking and problem-solving skills in the field of computer science.

Definition of Terms

  1. Algorithm: A finite set of instructions or rules that, when followed, solves a particular problem or performs a specific task.

    Example: A simple algorithm to add two numbers:

    Start
    Input num1, num2
    sum = num1 + num2
    Output sum
    End
    
  2. Pseudocode: A high-level description of an algorithm that uses a mixture of natural language and programming language syntax.

    Example: Pseudocode to find the maximum of two numbers:

    Start
    Input num1, num2
    if num1 > num2 then
         max = num1
    else
         max = num2
    Output max
    End
    
  3. Flowchart: A graphical representation of an algorithm that uses different shapes to represent different operations and connectors to show the flow of control.

    Example: Flowchart to check if a number is even or odd:

    graph LR
        A[Start] --> B(Input number)
        B --> C{Number % 2 == 0?}
        C -->|Yes| D[Output "Even"]
        C -->|No| E[Output "Odd"]
        D --> F[End]
        E --> F
    
  4. Efficiency: Refers to the ability of an algorithm to use the least amount of resources, such as time and memory, to perform a task.

  5. Complexity: The measure of how the time or space requirements of an algorithm grow as the input size increases.

Searching Algorithms

  1. Linear Search: An algorithm that sequentially checks each element in a list until the target element is found or the list is exhausted.

    Example: Find the position of the element 5 in the list [2, 4, 6, 8, 5, 3]:

    Start
    List = [2, 4, 6, 8, 5, 3]
    Target = 5
    for i from 0 to length(List) - 1 do
        if List[i] == Target then
            Output "Element found at position " + i
            Stop
    Output "Element not found"
    End
    
  2. Binary Search: An efficient search algorithm that divides the search interval in half at each step.

    Example: Find the position of the element 7 in the sorted list [2, 4, 6, 7, 8, 10]:

    Start
    List = [2, 4, 6, 7, 8, 10]
    Target = 7
    low = 0
    high = length(List) - 1
    while low <= high do
        mid = (low + high) / 2
        if List[mid] == Target then
            Output "Element found at position " + mid
            Stop
        else if List[mid] < Target then
            low = mid + 1
        else
            high = mid - 1
    Output "Element not found"
    End
    

Sorting Algorithms

  1. Bubble Sort: A simple sorting algorithm that repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order.

    Example: Sort the list [5, 2, 8, 1, 6] in ascending order using Bubble Sort:

    Start
    List = [5, 2, 8, 1, 6]
    n = length(List)
    for i from 0 to n-1 do
        for j from 0 to n-i-1 do
            if List[j] > List[j+1] then
                Swap List[j] and List[j+1]
    Output Sorted List
    End
    
  2. Merge Sort: A divide-and-conquer algorithm that divides the list into smaller sublists, sorts them, and then merges them back together.

    Example: Sort the list [4, 2, 7, 1, 5, 3, 6] in ascending order using Merge Sort:

    Start
    List = [4, 2, 7, 1, 5, 3, 6]
    MergeSort(List)
    Output Sorted List
    End
    

Common Mistakes

  • Not understanding the problem thoroughly before designing the algorithm.
  • Ignoring the efficiency and complexity of algorithms.
  • Incorrectly implementing the logic in the algorithm.
  • Failing to test the algorithm with different inputs.

Key Points

  • Algorithms are essential in problem-solving and programming.
  • Pseudocode and flowcharts help in designing and understanding algorithms.
  • Searching algorithms include linear search and binary search.
  • Sorting algorithms include bubble sort and merge sort.
  • Efficiency and complexity are crucial factors in evaluating algorithms.

Practice Questions

  1. Write a pseudocode for a linear search algorithm to find a specific element in a list.

    Answer:

    Start
    Input List, Target
    for i from 0 to length(List) - 1 do
        if List[i] == Target then
            Output "Element found at position " + i
            Stop
    Output "Element not found"
    End
    
  2. Explain the steps of a binary search algorithm to find an element in a sorted list.

    Answer:

    • Compare the target element with the middle element of the list.
    • If the target is equal to the middle element, the search is successful.
    • If the target is less than the middle element, search the left half of the list.
    • If the target is greater than the middle element, search the right half of the list.
    • Repeat the process until the element is found or the search interval is empty.
  3. Describe the working principle of the Bubble Sort algorithm.

    Answer: Bubble Sort compares adjacent elements and swaps them if they are in the wrong order. It repeatedly passes through the list until no swaps are needed, indicating that the list is sorted.

  4. Compare the efficiency of linear search and binary search algorithms.

    Answer:

    • Linear search has a time complexity of O(n) where n is the number of elements in the list.
    • Binary search has a time complexity of O(log n) as it divides the search interval in half at each step.
  5. Implement a Merge Sort algorithm to sort the list [9, 3, 6, 1, 7, 4] in ascending order.

    Answer:

    Start
    List = [9, 3, 6, 1, 7, 4]
    MergeSort(List)
    Output Sorted List
    End
    

These revision notes provide a comprehensive understanding of algorithms for Grade 11 Computer Science students following the Kenyan CBC curriculum. Understanding these concepts will enhance problem-solving skills and prepare students for the national exams.

Want to save these Algorithms notes?

Create a free account to bookmark notes, download past papers, track your revision and get AI study help - free for Kenyan students.

Save & bookmark notes Download past papers Track revision progress AI study help
Create free account

Already have one? Log in

Frequently Asked Questions

Algorithms is a Grade 11 Computer Science topic. This page gathers clear, exam-focused notes and revision material for it, all free to read online.

Yes - every note on this page is free to read online on YNetStudyHub, with no sign-up required.

Read the notes below, write a short summary of each in your own words, then practise related questions from the Computer Science past papers to check your understanding.

Other Grade 11 Computer Science topics

Get free notes & past papers by email

Join our list and we'll send fresh study notes and past papers straight to your inbox.