HTat Flashcards
-1: Constant time growth
The nomal amount of time an instruction takes under the RAM model
-Log n: logarithmic
Occurs in algos that transform a bigger problem into a smaller problem where the input size is a ration of the origional problem, common in searching and trees
-n: Linear
Algorithms that are forced to pass through all elements of the input(n) a number of times yield linear running times
n^k log n: polylogarithmic
Algorithms that break a problem into smaller parts, solve the ssmaller problems and combine into a solution k>=1
n^2: Quadratic
Subset of polynomial solution. Relatively efficeint to small or medium scale problems. typical of algos that have to analyse all pairs of elements of the input
n^3(+) cubic
Not very efficient but still polynomial. An example of an algorithm in this class is matrix multiplication
2^n: exponential
This is as bad as testing all possible answers to a problem, when algorithms fall into this catagory designers look for aproximation algorithms
Worst case of an algorithm
The worst-case efficiency of an algorithm is its efficiency for the worst-case input of size n, which is an input
(or inputs) of size n for which the algorithm runs the longest among all possible inputs of that size
Advantages of finding the worse case of an algorithm
-Binds runnning time to an upper bound
-ensures no matter the input size it cant be worse that CWorst(n)
Best case of an algorithm
The best-case efficiency of an algorithm is its efficiency for the best-case input of size n, which is an input
(or inputs) of size n for which the algorithm runs the fastest among all the inputs of that size
Advantages of finding best case
If the best case is not good enough the approach may need to be revisited
How can we measure the time efficiency of an algorithm
The standard approach is to identify the basic operation(s) and count how many times it is executed.
As a rule of thumb, it is the most time-consuming operation in the innermost loop of the algorithm
The established framework is:
Count the number of times the algorithm’s basic operation is executed for inputs of size n
Why can’t we use a standard unit of time to measure the efficiency of an algorithm
We can’t have influence from external factors such as:
Dependence on the speed of a particular computer
* Dependence on the quality of the program implementing the algorithm
* Dependence on the quality of the compiler used to generate the executable
* Difficulty of clocking the time precisely
What does RAM stand for in the RAM model of computation
Random access machine
Do we have to take constants into account when talking about growth functions
No, for example in a function that looks like 2x^3 + 10x^2+ 3 the only important term for growth is x^3 according to asymptotic notation
What is Asymptotic notation?
It provides the basic vocabulary for discussing the design and analysis of algorithms
Why is Asymptotic notation used
It’s ubiquitous because it identifies the key point for reasoning about algorithms.
It’s course enough to suppress all the details that should be ignored
precise enough to make useful comparisons between different algorithms
Big O notation
look it up yourself fucking nerd
What is the formula to find average case of an algoritm
(1 x p/n + 2 x p/n + .. + i x p/n) + n x (1-p)
Where to p is the probability of the first match occuring in the ith position for every i
Did you look over week 4 again?
Do it
look over lecture 3
<
look over all of week 3
<
Data Structues
Data structures are the building blocks of programming
-define how data is organised and allocated
Definition of ADT?
Abstract data types
Do data structures have operations
Yes they have operations to manipulate data
What must be true for a structure to be linear ?
-unique first element
-unique last element
-each component has a unique predecessor(bar first)
-each component has a unique succesor(bar last)
What are the two methods for accessing data in linear data structures
Sequential access - elements must all be accessed sequentially
Direct access - any element can be accessed directly, no prior access required
Give advantages and disadvantages of using arrays
Advantages
-Noramlly pre-defined in most programming language
-Elements in arrays can be directly accessed
Disadvantages
-Fixed size
Give the definition of a bernolli trial
An expermient or random process that has two possible outcomes
What is a Bernolli process?
A series of executions of Bernolli trials
What is a list?
A linear structure that only provides sequential access it has:
-two special elements; head and tail
-a homogenus structure
-easy insertation and deletion of nodes
What are advantages of using lists over arrays
-They don’t have a fixed size
-can be used as the basis of several other structures e.g queues and stacks
-Easier to insert and delete nodes
How does a linked list work?
consists of a collection of records called nodes each containing a member pointing to the next node in the list(implicit)
What is a better alternative to lists and why?
Lists using dynamic allocation(e.g linked lists)
-Because we have a link member we can store data anywhere in the list without worrying
Advantages of linked lists
-Fair use of memory
-Size of list doesn’t need to be declared in advance
-common operations(ins, del eg.g) are cheaper
Disadvantages of linked lists?
-Algorithms are more complex therefore harder to understand and debug
-Allocation and deAllocation of memory space can cause some overhead
What do we have to consider when examining a node in a linkedlist
-The node is the first node
-The node is an interior node(any node not first or last)
-The node is the last node
What is a sentinal node?
-A placeholder node containing no actual data designed to simplify operations on the linked list
-For example if the list is being searched and a trailing sentinal node is reached the algorithm knows it can stop searching
-if a sentinal node is added to the beggining and end then every insertion can be counted as a general insertion as there will never be a need to insert into the first and last node
What are Ciruclar lists
Variation of a singually linked list wherin the last node points to the first node instead of to nothing
When are circular lists useful/used?
-They are useful in problems where we aren’t interested in what node is the first or the last
-Some problems are better described using circular lists e.g. Josephus election
-In this structure the head can point to any node and isn’t used to keep nodes from being list
-Algorithms using circular lists are simper
What is the Josephus algorithm
An algorithm that makes use of circular lists, it will naviagate a circular list eliminating every kth person until only one remains
How can an array be used to implement linked lists?
The standard way to do this involves:
-An array of nodes to simulate the memory
-An array of boolean to keep track of free space in the memory
What is a doubly linked list?
It’s similar to a linked list however in addition to the head a pointer called the tail is also maintained.
That way each node is linked to both the node in front and behind it
One advantage and disadvantage of doubly linked lists
Operations are made easier to understand
More overhead due to increased number of pointers
What is a stack?
A restricted form of list
What are some properties of a stack
-Follows a Last in First out structure (LIFO)
-Can only refer to the top of the stack
-Only has two operations, one to add something to the top of the stack(push) and one to remove from the top of the stack(pull)
Applications of stacks
-Express evaluation
-Runtime memory management
-Search evaluation
What is a queue
A restricted form of a list
What are the properties of a queue?
-Implements a first in first out methodology
-Has a reference at the front and end of the queue
-Most important operations are enqueue and dequeue
What are some application of a queue?
-Job Scheduling
-printer spool
-mutitask operating systems (timesharing)
-Search problems(Knowing what part of memory hasn’t been explored yet)