Back to 课程

Computer Science GCES AQA

0% Complete
0/0 Steps
  1. Representing Algorithms Aqa
    4 主题
  2. Efficiency Of Algorithms Aqa
    1 主题
  3. Searching Algorithms Aqa
    3 主题
  4. Sorting Algorithms Aqa
    3 主题
  5. Data Types Aqa
    1 主题
  6. Programming Concepts Aqa
    5 主题
  7. Arithmetic Relational And Boolean Operations Aqa
    1 主题
  8. Data Structures Aqa
    3 主题
  9. String Manipulation Aqa
    1 主题
  10. Random Number Generation Aqa
    1 主题
  11. Structured Programming Aqa
    2 主题
  12. Robust And Secure Programming Aqa
    4 主题
  13. Number Bases Aqa
    2 主题
  14. Converting Between Number Bases Aqa
    3 主题
  15. Units Of Information Aqa
    9 主题
  16. Hardware And Software Aqa
    4 主题
  17. Boolean Logic Aqa
    3 主题
  18. Programming Languages And Translators Aqa
    2 主题
  19. Cpu Architecture Performance And Embedded Systems Aqa
    4 主题
  20. Memory Aqa
    2 主题
  21. Secondary Storage Aqa
    3 主题
  22. Fundamentals Of Computer Networks Aqa
    8 主题
  23. Fundamentals Of Cyber Security Aqa
    1 主题
  24. Methods Of Preventing Cyber Security Threats Aqa
    1 主题
  25. Relational Databases Aqa
    2 主题
  26. Ethical Legal And Environmental Impacts Aqa
    2 主题
课 Progress
0% Complete

Exam code:8525

Algorithm Efficiency

What is algorithm efficiency?

  • Algorithm efficiency is how much time it takes to complete an algorithm

  • In programming, there is often more than one algorithm which can solve a problem

  • An example of this is a linear search and binary search as both find a value in a list, however, depending on the circumstances, one may be much faster than the other

Efficiency in action

  • If we took the numbers 1-20 jumbled up in a list

  • How efficient an algorithm is would be determined by how quickly it could sort the numbers into ascending order

Sort 1 (Bubble sort)

Sort 2 (Insertion sort)

DEFINE listToSort AS a list of integers containing the numbers 1 to 20

SET lengthOfList TO the length of listToSort

FOR currentIndex FROM 0 TO lengthOfList - 1 DO

FOR innerIndex FROM 0 TO lengthOfList - 1 - currentIndex DO

IF listToSort[innerIndex] > listToSort[innerIndex + 1] THEN

TEMP ← listToSort[innerIndex]

listToSort[innerIndex] ← listToSort[innerIndex + 1]

listToSort[innerIndex + 1] ← TEMP

END IF

END FOR

END FOR

DEFINE listToSort AS a list of integers containing the numbers 1 to 20

SET lengthOfList TO the length of listToSort

FOR currentIndex FROM 1 TO lengthOfList - 1 DO

SET currentValue TO listToSort[currentIndex]

SET innerIndex TO currentIndex - 1

WHILE innerIndex >= 0 AND listToSort[innerIndex] > currentValue DO

listToSort[innerIndex + 1] ← listToSort[innerIndex]

SET innerIndex TO innerIndex - 1

END WHILE

listToSort[innerIndex + 1] ← currentValue

END FOR

  • In the algorithms above, the worst case of a bubble sort is that it would take 361 comparisons to sort 20 items of data

  • The worst case of an insertion sort with 20 items is that it would perform 190 comparisons

  • This means that in this instance, although both algorithms perform the same job and achieve the same result, an insertion sort would be significantly faster because it is much more efficient in how it uses the computer’s processing power and memory

Responses

您的邮箱地址不会被公开。 必填项已用 * 标注