Professional Documents
Culture Documents
• A set of instructions used • The priority for an algorithm is to • FIFO (First in first out) • 0(1) - Consistent time complexity - The amount
to solve a set problem. achieve the given task. • Often an array. of time is not affected by the number of inputs.
• Inputs must be clearly • The second priority is to reduce time • The front pointer marks the position of the first • 0(n) - Linear time complexity - The amount of
defined. and space complexity. element. time is directly proportional to the number of
• Must always produce a • There may be a conflict between • The back pointer marks the position of the next inputs.
valid output. space and time complexity and the available space. • 0(nn) - Polynomial time complexity - The
• Must be able to handle requirements and situation for an Queue Functions amount of time is directly proportional to the
invalid inputs. algorithm will dictate which is more • Check size size() number of inputs to the power of n.
• Must always reach a important. • Check if empty isEmpty() • 0(2n) - Exponential time complexity - The
stopping condition. • To reduce space complexity, make • Return top element (but don’t remove) peek() amount of time will double with every additional
• Must be well-documented as many changes on the original data input.
• Add to the queue enqueue(element)
for reference. as possible. Do not create copies. • 0(log n) - Logarithmic time complexity - The
• Remove element at the front of the queue and
• Must be well-commented. • To reduce time complexity, reduce amount of time will increase at a smaller rate as
return it dequeue()
the number of loops. the number of inputs increases.