dsa Flashcards
what is the amortised cost of an algorithm?
the mean complexity of a set of instructions (considering all cases and how often they occur)
what does it mean for two algorithms to be asymptotically equal? ( f(x)~g(x) )
the algorithms tend to the same time i.e.
f(x)/ g(x) = 1 such as if f(x) is x^2 and g(x) is x^2 +3x
what is theta complexity?
if f(n) = ϴg(n):
ag(n) ≥ f(n) ≥ bg(n) ≥ 0 ∀ n≥n₀
has an upper and lower bound so f and g grow at the same rate
what is little o notation?
if f(n) = o(g(n)) then f(n) is ultimately negligible to g(n) or lim n→∞ f(n)/g(n) = 0
what does it mean if an algorithm has Ω(x^2) complexity
the algorithm grows at the same rate or faster than x^2 as n increases
what is implicit and explicit memory management
implicit: doesn’t expose memory locations to programmer and has garbage collection, bounds of data structures are checked, memory allocation and memory freeing is automatic.
explicit: all of these things have to be done automatically
what does it mean if an algorithm has O(x^2) complexity
the algorithm grows at the same rate or slower than x^2 as n increases
what is size, height, depth, order and balance in a tree?
size: number of elements
height: number of levels (empty=-1, height starts from 0)
depth: how far down an element is from the top
order: maximum number of children of a node
balance: difference in height of each subtree of a node
what is special about a quad tree?
each node points to 4 other quad trees but 3 of them has to be a leaf. they are used for representing images
how do you delete an element from a binary search tree assuming the node has 2 children?
delete it and fill its place with the leftmost node on the right subtree. then replace that node with its right subtree if there is one
what is an AVL binary tree?
a binary tree where each node has a balance of either 1, 0 or -1
what is a perfect and minimal AVL tree?
perfect: a full AVL tree
minimal (Fibonacci): an AVL tree where every node has a balance of 1 or -1 (as empty as an AVL tree is allowed)
what are the two formulas to calculate the size of a minimal tree?
|Tₕ₊₂| = 1+|Tₕ|+|Tₕ₊₁|
|Tₕ|= Fₕ₊₃
what is the formula to calculate the size of a full binary tree?
|Tₕ|= 2ʰ⁺¹ -1
balance an LL, RR, RL and LR tree
Check answers online
what are the characteristics of a B+ tree of order m?
- node has 2-m children (unless its a leaf)
- non-node, non-leaf nodes have m/2 -m children
- all leaf nodes are on the same level
- balanced
- operations are O(log n) complexity
- data structure is stored in secondary storage used for databases
what is a block of memory?
a way that disks store data that groups data together usually of size 4-64Kb and they can only operate on whole blocks at the time
what is a discriminator in a B+ tree?
a value used to decide which path to take down the tree in searching for a record