Flashcards
COSC241
Cards in this deck (55)
- 1Simple Loop from 0 - nO(n)
- 2Nested Loop of the Same typeO(n^2)
- 3Selection SortO(n^2)
- 4Insertion SortO(n^2)
- 5Quick SortO(n^2)
- 6Divide & Conquer AlgosO(nlogn)
- 7Merge SortO(nlogn)
- 8Heap SortO(nlogn)
- 9sqrt(n), logn, 1, n^2, nlogn, n^3, 2^n1, logn, sqrt(n), n, nlogn, n^2, n^3, 2^n
- 10What is an interface?a collection of abstract methods and constants
- 11What is an algorithm?a description of a series of basic steps that achieve some specified result
- 12References as links-a java reference, refers to a memory location in which complete data for an object is stored
-a reference to an object of the same type is often called a link - 13What is a linked list?-a sequence of nodes connected by links
- 14Static data structure?-structure is fixed at the time it is created and cannot be changed
- 15Dynamic data structure?structure can change
- 16True Random numbers?generated by observation of some unpredictable physical process
- 17What is a collection?-an object that gathers and organises other objects
-defines the way in which those elements can be accessed and managed
-specifies the way in which the user may interact with the collection - 18ADT?an abstract data type is a data type whose intended use is specified by its interface
- 19Data structure?the collection of programming structures (methods, data fields) used to implement an ADT
- 20Queue ADTa queue is an abstract data type that represents item processing in a first in first out manner
- 21Divide & Conquer?-Pre: break the problem apart into two or more smaller problems
-Rec: solve the problems recursively
-Post: combine those solutions into a solution of the original problem - 22Heaps?-a heap is a tree where the values stored are comparable which satisfies certain additional restrictions
-the value stored at a node is always greater than or equal to the value stored at any of its children
-each node has at most two children - 23Priority Queue?-each element is added with an associated priority
-when an element is removed it is the highest element with the highest priority - 24What is recursion?the repeated application of a recursive procedure or definition
- 25Formal f(n) = O(g(n))If for some constant A f(n) is less than or equal to Ag(n)
- 26Linear Search of Arrayif nothing is know about the array we have to look at each element until we find the right one
-gives O(n) - 27Binary Search of Array?-Check the midpoint – this either finds the value or gives us a new range to search in which is only half the size.
-Implement recursively. - 28Selection Sort- Find the smallest item in the list. Swap it with the first item.
- Find the smallest item in the remainder of the list, swap it with the first item of the remainder.
- Repeat until finished. - 29Insertion Sort-Process the array one element at a time.
-Insert each new element into its correct position among the previously processed elements. - 30Quick Sort-Choose one of your data items called the pivot.
-Split the remaining data into the items smaller than the pivot and the items larger than (or equal to) the pivot.
-Put all the small items before the pivot and all the large items after the pivot.
- Sort those two groups individually - 31Merge Sort-Split array down to sub-arrays of two
-sort the sub-arrays
-merge the array
- one way to speed up to algo is to delegate to insertion sort when right - left is less than some pre-set threshold - 32Heap Sort-Organize the elements of the array into a heap structure.
- Exchange the first (largest) element, and the last element.
- Restore the heap structure (except for the final element).
- Repeat last two steps until finished. - 33Why are random numbers importantUsed in; game playing; simulation and testing; security; cryptography and communication protocols
- 34Psuedo-Randomnumbers are generated as a sequence
by a specific deterministic mathematical algorithm called a pseudo-random number generator - 35Shuffling an Array- Exchange the last card with some earlier item or itself, then
- exchange the second last card with some earlier card or itself, then
- exchange the third last item with some earlier item or itself
-Keep Going - 36Dealing a handshuffle the array, and then use the first, or last, k (if we do this right, then we don’t need to complete the shuffle - we can stop when the required elements are in place).
- 37Advantages of ADTs?The data structure that implements an ADT can be changed without changing the interface, and therefore in a way that does not affect any client programs
- 38StackA LIFO collection
- 39Queuean abstract data type that represents item
processing in a first in, first out manner - 40Similarities between stack and queue?-Same basic operations
-Stack is LIFO
-Queue is FIFO - 41Significance of Generic Typesuseful, indicating in a class that “you could have objects of any type here” but where that type might be used in e.g., method parameters or returns
- 42Issues with multiple linking?-hard to get to work properly
-difficult to add and remove nodes - 43Divide and Conquer algo complexityTotal work done is (work per layer O(n)) times (number of layers O(logn))
and is O(n log n) - 44Why remove recursion?- When a method call is made, the complete state of the current method must be stored (since it might all be needed) and then restored when the called method exits.
- Insertion sort becomes very quick in small data sets - 45What is a heap?A heap is a tree where the values stored are comparable which satisfies certain additional restrictions
- 46Characteristics of a Heap- value stored at a node is always greater than or equal to the value stored at any of its children
- each node has at most two children
- it is a complete tree - 47Operations a Heap supports- Adding an item,
- Returning the maximum value in the heap,
- Removing the maximum value from the heap - 48Adding an item to a heap- Place the item to be added in the first vacant leaf position.
- Let it float up the branch towards the root so long as it is larger than its parent - 49Removing the maximum- maximum is always at the root of the heap
- Replace the root value with the value of the last leaf
-Then to re-establish the heap property exchange the root and the larger of its children (and do this recursively downwards) - 50Priority Queue- each element is added with an associated priority
-When an element is removed, it is the element with highest priority - 51Double recursion callsThe double recursive call creates an exponential blow up in the number of actual method calls
- 52How to better Insertion Sort◮ When the time comes to insert the element from position i the previous elements are sorted and those greater than a[i] need to be moved forward.
◮ So, read backwards from position i, moving elements forward until the necessary hole is created into which we
can place the value a[i] (which we need to store in advance since it will be written over in the first step). - 53Characteristic that makes divide and conquer litThe sub-problems should be a constant fraction smaller
than the main problem and the work required to create and
combine them should be linear - 54Weakness of Quick Sort- if the data is already sorted the sub-problems are of size 0 and n − 1
- then you have to recurse through those - 55What do generic types allow us to do?define a class so that it stores, operates on, and manages objects whose type is not specified until the class is instantiated
Information
- Description
- Flashcards on COSC241, created by Tom Weatherall on 28/05/2019.
- Created by
- Tom Weatherall
- Views
- 1
- Rating