Zum Inhalt springen

NZ NCEA Level 3 Digital Technologies

NCEA Level 3 · NZQADigital Technologies41 Notizen in 7 Ordnern, 323 KB

41 Lernnotizen für NZQA NCEA Level 3 Digital Technologies, von cookie erstellt, in 7 Abschnitten, die den Themen des Kurses folgen.

Notes for NZQA NCEA Level 3 Digital Technologies and Hangarau Matihiko, in a folder for each area of computer science the course analyses (complexity and tractability, computer graphics, computer vision, big data, formal languages and network communication protocols), with one note per topic, and a last folder on developing and reflecting on a digital outcome. Follows achievement standard AS91908 as registered for 2027. Delete the folders for the areas you are not studying.

Wenn du sie hinzufügst, wird eine Kopie in deinen Notizen abgelegt – in einem eigenen Ordner mit den unten aufgeführten Unterordnern. Du kannst sie bearbeiten und daraus Lernkarten oder ein Fragendeck erstellen. Beim Herunterladen erhältst du eine ZIP-Datei mit Markdown-Dateien, die sich in jeder Notizen-App öffnen lässt.

Was enthalten ist

  • Complexity and tractability
    • Measuring algorithm efficiency and Big O7 KB
    • Best, worst and average case6 KB
    • Complexity classes: P, NP and intractable problems6 KB
    • Classic hard problems6 KB
    • Algorithm design strategies, heuristics and trade-offs8 KB
  • Computer graphics
    • Raster and vector graphics6 KB
    • Colour models and file formats7 KB
    • Geometric transformations8 KB
    • Rasterising lines6 KB
    • Shading and rendering9 KB
    • Computer graphics in use and effects on people8 KB
  • Computer vision
    • Computer vision: images as data7 KB
    • Edge detection6 KB
    • Stereo vision and depth6 KB
    • Feature detection, classification and segmentation7 KB
    • Machine learning in computer vision7 KB
    • Computer vision: applications, trade-offs and effects on people7 KB
  • Big data
    • Defining big data6 KB
    • Big data: types and formats of data7 KB
    • Big data: storage and processing7 KB
    • Big data: analysis, interpretation and bias8 KB
    • Big data: privacy, ethics and other considerations9 KB
    • Applications of big data8 KB
  • Formal languages
    • Alphabets, strings and languages7 KB
    • Regular expressions8 KB
    • Finite-state automata9 KB
    • Context-free grammars9 KB
    • The Chomsky hierarchy8 KB
    • Formal languages in compilers9 KB
    • Formal languages, decidability and complexity9 KB
  • Network communication protocols
    • The internet protocol suite8 KB
    • The link and internet layers9 KB
    • The transport layer: TCP and UDP10 KB
    • The application layer9 KB
    • Networking for the Internet of Things11 KB
    • Protocols in use: applications and trade-offs9 KB
  • Developing and reflecting on a digital outcome
    • Decisions in developing a digital outcome7 KB
    • Legal, ethical and intellectual property implications10 KB
    • Privacy, accessibility and usability10 KB
    • Sustainability, future-proofing and health and safety9 KB
    • Evaluating a digital outcome8 KB

Die erste Notiz

Complexity and tractability / Measuring algorithm efficiency and Big O

Why running time is not the measure

Timing a program with a stopwatch says as much about the computer as about the algorithm. A slow algorithm on a fast machine can beat a fast algorithm on a slow one, and the result changes with the language, the compiler, what else is running and the particular input. Computer scientists therefore measure an algorithm by how the amount of work it does grows as the input grows. The input size is written nn: the number of items in a list, the number of cities in a route, the number of digits in a number.

Work is counted in basic steps, such as a comparison, an assignment or an arithmetic operation, each treated as taking one unit of time. The count is a function of nn, and what matters is the shape of that function for large nn. This is time complexity. Space complexity is the same idea applied to memory: how much extra storage the algorithm needs as nn grows, not counting the input itself.

Counting steps

Consider a function that finds the largest value in a list of nn numbers.

def largest(items):
    best = items[0]
    for x in items[1:]:
        if x > best:
            best = x
    return best

The loop runs n−1n - 1 times and each pass does one comparison and possibly one assignment. The total is roughly 2n2n steps at most, plus a constant for the set-up. Doubling the list doubles the work. Whether the exact figure is 2n2n or 3n+53n + 5 does not change that, which is why the constants are dropped.

Now a function that checks whether any two numbers in a list are equal by comparing every pair.

def has_duplicate(items):
    n = len(items)
    for i in range(n):
        for j in range(i + 1, n):
            if items[i] == items[j]:
                return True
    return False

The inner loop runs n−1n-1 times for i=0i = 0, then n−2n-2, and so on down to zero. The number of comparisons in the worst case is

(n−1)+(n−2)+⋯+1=n(n−1)2. (n-1) + (n-2) + \dots + 1 = \frac{n(n-1)}{2}.

For n=10n = 10 this is 45 comparisons, for n=100n = 100 it is 4,950 and for n=1,000n = 1{,}000 it is 499,500. Multiplying nn by ten multiplies the work by about a hundred, which is the signature of work proportional to n2n^2.

Big O notation

Big O notation describes an upper bound on how fast the number of steps grows. Writing f(n)=O(g(n))f(n) = O(g(n)) means that for large enough nn, f(n)f(n) is no bigger than some constant multiple of g(n)g(n). In practice two simplifications give the answer.

  1. Drop constant factors. 3n3n and 50n50n are both O(n)O(n).
  2. Keep only the term that grows fastest. n2+5n+100n^2 + 5n + 100 is O(n2)O(n^2), because for large nn the n2n^2 term swamps the others.

So the duplicate check above is O(n2)O(n^2) and the largest-value function is O(n)O(n). Big O says nothing about small inputs: 100n100n is O(n)O(n) and n2n^2 is O(n2)O(n^2), yet n2n^2 is the smaller of the two until nn passes 100. Big O is a statement about what happens as the input grows without limit.

Base of a logarithm does not matter inside Big O, because changing base multiplies by a constant. O(log⁡2n)O(\log_2 n) and O(log⁡10n)O(\log_{10} n) are the same class and are written O(log⁡n)O(\log n).

Common growth rates

NotationNameTypical sourceExample
O(1)O(1)constantone step regardless of sizereading items[i] from an array
O(log⁡n)O(\log n)logarithmichalving the problem each stepbinary search in a sorted array
O(n)O(n)linearone pass over the datalinear search, finding the maximum
O(nlog⁡n)O(n \log n)linearithmicdivide, then merge linearlymerge sort
O(n2)O(n^2)quadratictwo nested loops over the datacomparing every pair, bubble sort
O(n3)O(n^3)cubicthree nested loopsnaive multiplication of two n×nn \times n matrices
O(2n)O(2^n)exponentialtrying every subsetchecking every subset of nn items
O(n!)O(n!)factorialtrying every orderingchecking every route through nn cities

The table is in order of increasing growth. The jump from polynomial rates (nn, n2n^2, n3n^3) to exponential and factorial rates is the dividing line the rest of this topic is built on.

How fast the rates grow

The table below shows the number of steps for a few sizes, assuming one step per unit.

nnlog⁡2n\log_2 nnnnlog⁡2nn \log_2 nn2n^22n2^n
103.310331001,024
204.320864001,048,576
304.9301479001,073,741,824
1006.610066410,000about 1.3×10301.3 \times 10^{30}

A computer doing a billion steps a second takes about a second for 2302^{30} steps, but 21002^{100} steps would take far longer than the age of the universe. Making the computer a thousand times faster changes that only by three orders of magnitude out of thirty. This is why an exponential algorithm is described as unusable for large inputs whatever hardware it runs on, while a polynomial one can be rescued by faster hardware.

Logarithmic growth is the opposite extreme. Binary search on a sorted list of 1,000,000 items needs at most 20 comparisons, because 220=1,048,5762^{20} = 1{,}048{,}576 is the first power of two above a million. Doubling the list to 2,000,000 items adds one comparison.

Reading complexity from code

A few patterns cover most cases.

  • A single loop from 1 to nn doing constant work inside is O(n)O(n).
  • A loop nested inside another, both running to nn, is O(n2)O(n^2).
  • A loop in which the control variable is halved or doubled each pass (while i < n: i = i * 2) is O(log⁡n)O(\log n).
  • A loop over nn items that calls an O(log⁡n)O(\log n) operation each time, such as a binary search, is O(nlog⁡n)O(n \log n).
  • Steps done one after another add, and the larger term wins: an O(n)O(n) pass followed by an O(n2)O(n^2) pass is O(n2)O(n^2).
  • A loop whose bound does not depend on the input (run exactly 1,000 times) is O(1)O(1).

Recursion is analysed by how many calls are made and how much work each does. A recursive function that calls itself twice on inputs only one smaller, like the naive Fibonacci below, makes a number of calls that roughly doubles with each increase in nn.

def fib(n):
    if n < 2:
        return n
    return fib(n - 1) + fib(n - 2)

The call tree for fib(5) already repeats fib(3) twice and fib(2) three times. The total number of calls grows exponentially, about 1.6n1.6^n, so fib(50) is out of reach this way while a loop that keeps the last two values does the job in O(n)O(n) steps.

Space complexity

Space complexity counts the extra memory used. The largest-value function uses a few variables whatever the size of the list, so it is O(1)O(1) in space. Merge sort needs a second array to merge into, so it uses O(n)O(n) extra space. A recursive function that goes nn calls deep uses O(n)O(n) space for its call stack even if it stores nothing else.

Time and space often trade against each other. Storing results already calculated (memoisation) removes the repeated work in the Fibonacci example, turning exponential time into linear time at the price of O(n)O(n) memory.

Other bounds

Big O is an upper bound, and two companions exist for completeness. Big Omega, Ω(g(n))\Omega(g(n)), is a lower bound: the algorithm takes at least this much. Big Theta, Θ(g(n))\Theta(g(n)), says both hold, so the growth is exactly of that order. Saying a linear search is O(n2)O(n^2) is technically true but uninformative; the useful statement is the tightest bound, and for searching an unsorted list that is Θ(n)\Theta(n) in the worst case.

Und 40 weitere, sobald du sie hinzufügst oder herunterlädst.

Bewertungen

Noch keine schriftlichen Rezensionen. Füge diese Notizen zu deinen hinzu und du kannst die erste Rezension schreiben.