CSC 172 - Test 1

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Binary Tree

- Each node stores data has up to 2 children - Left child and right child

Linked List

- Fast insertion of data > array - Avoids shifting problem (array higher index up) - Node created and pointed, instead of shift

Sorting

- Process of converting a list of elements into ascending (or decending) order.

Recursion Trees

- Runtime complexity of any recursive function - split into 2 parts - operations done directly by the function - operations done by the recursive calls made by the function

Space complexity

- S(N) - represents number of fixed-size memory unit used by algorithm for an input of size N - includes input data and additional memory allocated by algorithm - Auxiliary space complexity is not included in the input data

Linear Search Algorithm

- Starts from beginning and checks each element until the search key is found, or the end of the list is reached

Array

- Stores ordered list of item - Item accessible by positional index

Record

- Stores subitems called fields - Name associated with subitem

Hash Table

- Stores unordered items by mapping (hashing) each item to location in array

Runtime complexity

- T(N) - represents number of constant time operations preformed by algorithms on an input size N - best case: minimum operations - worst case: algorithms does the maximum number of operations

Quicksort

- a sorting algorithm that repeatedly partitions the input into low and high parts (each part unsorted), and then recursively sorts each of those parts. To partition the input, quicksort chooses a pivot to divide the data into low and high parts - Rounddown midpoint Midpoint = lowIndex + (highIndex - lowIndex) / 2 - Quicksort Runtime: O(NlogN) - 2 even parts - Low partition: lowest index number - pivot - High partition: pivot - highest index - Runtime: (n+1)*(n/2) = n^2

Binary Search

- faster algorithm for searching a list if a list is sorted and directly accessible - checks the middle of the list * add indexes and divide by two * subtract highest element by 1 efficiency: log(n) + 1

Runtime Analysis Tips

- nested loop: n^2

Computational problem

- specifies input - question about input, that can be answered using a computer - output

Shell sort

- treats the input as a collection of interleaved lists, and sorts each list individually with a variant of the insertion sort algorithm - gap value specifies number of interleaved lists - shell sorts interleaved list in place with a variation of insertion sort algorithm - inital value of loop variable i = startIndex + gap - preform well with gap values in descending order: chooses powers of 2 minus 1 in descending order (array size 100 = 63, 31, 15, 7, 3, and 1) - runtime: n^3/2 - any gap value, positive, works with gap value of 1 included - inner loop called:

Selection sort

- treats the input as two parts, a sorted part, and an unsorted part - selection comes from fact that each iteration of the outer loop is selected for position i - n^2

Graph

A data structure for representing connections among items - vertices connected by edges - a vertex represents item in graph - edge represents connection between 2 vertices

Lower bound

A function f(N) that is ≤ the best case T(N), for all values of N ≥ 1

Upper bound

A function f(N) that is ≥ the worst case T(N), for all values of N ≥ 1

NP-complete

A set a problems which no known efficient algorithms exist 1. no efficient algorithm has been found to solve NP-complete problem 2. no one has proven that an efficient algorithm to solve an NP-complete problem is impossible 3. If an efficient algorithm exists for one NP-complete problem, than all NP-complete problems can be solved efficiently

Computational complexity

Amount of resources used by the algorithm - most common: runtime, memory usage - used to identify and avoid using algorithms with long runtimes or high memory usage

Big O Notation

Big O notation is a mathematical way of describing how a function (running time of an algorithm) generally behaves in relation to the input size. - all functions that have the same growth rate are considered equivalent in Big O notation. - if f(N) is a sum of several terms, the highest order term (the one with the fastest growth rate) is kept and others are discarded - If f(N) has a term that is a product of several factors, all constants (those that are not in terms of N) are omitted. - log2N, N, NlogN, N^2, N^3, 2^N - O(1) - constant - O(logN) - Logarithmic - O(N) - Linear - O(NLogN)- Linearithmic - O(N^2) - quadratic - O(2^N) - exponential

Worst Case Algorithm Analysis

Count iterations and multiple by how many iterations for each operation

ADT - Abstract Data Type

Data type described by predefined user operations, such as "insert data at rear", without indication how each operation is implemented - can be implemented using different data structures - programmer need not to have knowledge of underlying implementation to use ADT

Longest common substring problem

Determines lonest common substring in 2 input strings - ex: DNA analysis

Dijkstra's shortest path

Determines shortest path between 2 vertexes

Binary Search

Efficient algorithm for searching a list - List must be sorted and directly accessible (like array) - ex: search engines

Algorithm Runtime

Is the time the algorithm takes to execute - algorithm uses number of steps proportional to input

Common ADTS

List: holding ordered data - array linked list Dynamic array: holding ordered data and allowing indexed access - array Stack: items are only inserted on or removed from top of stack - linked list Queue: items are inserted at the end and removed from the front of queue - linked list Deque: Items inserted and removed at both front and back - linked list Bag: order does not matter, duplicate items allowed - linked list, array Set: collection of distinct items - binary search tree, hash table Priority queue: each item has priority and items with high priority are closer to the front - heap Dictionary: associates key with values - hash table, binary search tree

Heap

Max heap: tree that maintains property that key is greater or equal to node's children's Min heap: tree that maintains key is less than or equal to node's children's key

Constant Time Operation

Operates the same amount of time, regardless of input values Common operations: addition, subtraction... assignment of a reference point comparison of two fixed size data values read or write an array element at a particular index

Algorithm

Sequence of steps to solve computation problem or calculation

Asymptotic notation

The classification of runtime complexity that uses functions that indicate only the growth rate of a bounding function. Three asymptotic notations are commonly used in complexity analysis: Big oh - upper bound A positive constant c exists such that, for all N ≥ 1, T(N)≤c∗f(N). Omega - lower bound A positive constant c exists such that, for all N ≥ 1, T(N)≤c∗f(N). Theta - upper and lower

Insertion sort

Threats input as two parts, sorted part and unsorted part and repeatedly inserts the next value fromt he unsorted part into the correct location in the sorted part Runtime: N^2 Nearly sorted runtime: N

Abstraction

To have user interact with item at high level, with low level internal details hidden from user - ADTs support abstraction by hiding the underlying implementation details and providing well-defined set of operations for using ADTs - Help improve programmer efficiency

Algorithm efficiency

Typically measured by the algorithms computational complexity

Recurrence Relation

Will have T on both sides of the equation


संबंधित स्टडी सेट्स

Public Health (Milk, Meat, Foodborne Diseases)

View Set