Exam theory Flashcards
Which of the following is not true in case of a Python dictionary?
A. Matches “keys” to “values”
B. We can look up one item by another item
C. Order is guaranteed
D. Key can be any immutable type (dictionary mutable)
C. Order is NOT guaranteed
CLASSES OF TESTS
Unit testing • testing each function separately Regression testing • catch reintroduced errors that were previously fixed Integration testing • does overall program work?
SIMPLIFICATION EXAMPLES
• drop constants and multiplicative factors • focus on dominant terms O(n^2): n^2 + 2n + 2 O(n^2): n^2 + 100000n + 31000 O(n): log(n) + n + 4 O(n*logn) : 0.0001*n*log(n) + 300n O(3^n) : 2n^30 + 3^n
BUBBLE SORT
• compare consecutive pairs of elements
• swap elements in pair such that smaller is first
• largest unsorted element always at end after the pass, so at most n passes
• complexity is O(n^2) where n is len(L)
(swap and for)
SELECTION SORT
- extract minimum element
- swap it with element at index 0 (1,2, … and so on)
- at i’th step, first i elements in list are sorted (all other bigger)
- O(n^2) where n is len(L)
MERGE SORT
- if list is of length 0 or 1, already sorted
- if list has more than one element, split into two lists, and sort each by comparing first elements
- merge sorted sublists (add smaller element to the result list)
• complexity O(n * log(n)) where n is len(L) - Overall complexity of similar Quick sort = O(n*log(n)) - average; O(n^2) - worst case
range() find() list[::] .append(item) .extend(item) round()
range(start, stop, step) - not including stop (spaces in strings also indexed; when numbers wrongly specified, just does not execute (range(10,1,2)); when floats=TypeError )
find(value, start, end) - not including stop; finds first occurrence of specified value
list[ Initial : End : IndexJump ] - not including end
.append(item) - [ , , , [ , , ]]
.extend(item) - [ , , , , , ]
round(number, digits) - number of digits after dot
BLACK BOX TESTING
- It is designed without looking at the code.
- Can be done by someone other than the implementer.
- Testing can be reused if implementation changes.
- Paths through specification (docstring)
GLASS BOX TESTING
- Code is used directly to guide design of the test cases
- Testing cannot be reused if implementation changes
- Explores paths through the code
- It is called path-complete if every potential path through the code is tested at least once
Bisection/binary search
divide and conquer
- list MUST be sorted to give correct answer
- linear search => O(n)
- binary search => O(log n)
(assumes the list is sorted!)
Monkey Sort
aka bogosort - stupid sort - slowsort - permutation sort - shotgun sort
is a random sort, every time through the list get randomly sorted and if lucky it is ordered!
Monkey Sort - complexity
Best case:
O(n) where n is len(L)
Worst case:
O(?) is unbound if really unlucky
LOGIC OPERATORS ON bools (a and b)
not a -> True if a is False
False if a is True
a and b -> True if both are True
a or b -> True if either or both are True
Syntax
arrangement of words and phrases to create will-formed sentences in a language.
Static semantics
whether syntactically valid string has any meaning