CSC316-Test1

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Describe how backtracking works in a list data structure

It allows for reverse traversal of a linked list as well as a runtime of O(1) for removal at the end of the list.

Define: Problem

A general question to be answered. Has unspecified parameters.

Describe how to improve average case running time for dictionaries by using the move-to-front heuristic

Lookup -> Find something -> Move it to the front of the list. This will increase average runtime for frequent searching.

Describe how to improve average case running time for dictionaries by using the transpose heuristic

Lookup -> Find something -> move it one place up the list.

State the running time of the following search table operations: lookUp(), insert(), delete()

Lookup = Log(n) insert =O(n) delete = O(n)

Define the following property of an algorithm: Efficiency

Low utilization of computational resources

Rank the complexity classes in increasing order of growth rate

O(1) < O(n) < O(n^2) < O(n^3) < O(2^n) < O(n!)

Define the following property of an algorithm: Termination

no infinite loops

Describe how to implement a skip list using a linked memory implementation

A series of linked lists S0, S1, S2, ... , Sh such that - Each list Si contains the special keys -∞, +∞ - List S0 contains all keys in dictionary in increasing order - Each list is a subsequence of the previous one S0 ∋ S1 ∋ S2 ∋ ... ∋ Sh - List Sh contains only the two special keys, -∞, +∞

Define: Pseudocode

High-level descriptions of algorithms; Combines natural language and structures from programming languages;

Describe the advantages of using a dummy head node (and/or tail node) for a linked list

Improves efficiency for certain implementations of Abstract data types such as a queue.

Define: Heuristic

• A problem solving approach that uses a method not guaranteed to be optimal or perfect, but is sufficient for the immediate goals • Rule of thumb • Results in good performance (but not necessarily optimal performance)

Describe how interpolation search works and give an example

• Assumption: we know some information about how far apart two keys are - Do not look up the middle key like binary search - Determine how far apart given key is from key at low position x - Lookup key at position (low + x) • Example: Phonebook • Performance - Worst-case O(n) - Average-case O (log(log(n))

Define: Data Structure

- Systematic way of organizing and accessing data - Logical organization of computer memory

Define: Abstract Data type

-model for behaviors from the point of view of a user of the data -possible operations on data Does not describe HOW the set of operations is implemented! No rule for what operations must be supported, that is a design decision! Ex: Stacks, Queues, etc.

Describe how software, hardware, programmers, and algorithms affect the actual runtime of a program

1. Software: language, compiler 2. Hardware: machine used to run program 3. Programmer: experience, coding details 4. Algorithm: approach to solving the problem

Demonstrate how the growth rate of two functions f(n) and g(n) compare by using the definition of Big-Oh

1. f(n) <= c * g(n) for all n > n0 2. f(n) = n^2 + n + 1; g(n) = n^2

Define the following property of an algorithm: Robustness

Able to handle unexpected inputs

Describe and document the algorithm for binary search

Algorithm binarySearch(A, key, low, high) Input an array A with n elements a key to lookup the low index the high index Output the element with the key if low > high then return "not found" else mid <- (low + high) / 2 //integer division if A[mid] = key then return element(A[mid]) else if A[mid] > key then // key in left half return binarySearch(A, key, low, mid-1) else // key in right half return binarySearch(A, key, mid+1, high)

Be able to document algorithms using psuedocode

Algorithm remove(L, value) Input an array L of n integer values an integer value to remove from the array Output true if the element was removed for i 0 to n-1 do if L[i] = value then for k i to n-1 then L[k] L[k+1] size size - 1 return true return false An algorithm should look something like this

Define the following property of an algorithm: Correctness

Always gives the right answer

Define: Ordered List

An ordered sequence of n elements

Define: Unordered list

An unordered sequence of n elements

State the running time of the following skip list operations: lookUp(), insert(), delete()

Average should be O(log(n))

Define: Big-Oh

Big-Oh • Given functions f(n) and g(n), we say that f(n) is O(g(n)) if there are integer constants 𝑐 > 0 and 𝑛0 ≥ 1 such that 𝑓 𝑛 ≤ 𝑐 ∙ 𝑔(𝑛) ∀ 𝑛 ≥ 𝑛0

Define: Big-Omega

Big-Omega • Given functions f(n) and g(n), we say that f(n) is Ω(g(n)) if there are integer constants 𝑐 > 0 and 𝑛0 ≥ 1 such that 𝑓 𝑛 ≥ 𝑐 ∙ 𝑔(𝑛) ∀ 𝑛 ≥ 𝑛0

Define: Big-Theta

Big-Theta • Given functions f(n) and g(n), we say that f(n) is Θ(g(n)) if there are integer constants 𝑐′ > 0, 𝑐′′ > 0, and 𝑛0 ≥ 1 such that 𝑐′𝑔 𝑛 ≤ 𝑓 𝑛 ≤ 𝑐′′𝑔(𝑛) ∀ 𝑛 ≥ 𝑛0

Explain the difference between contiguous and linked memory implementations; describe the advantages and disadvantages of each; and give examples of each

Contiguous- Array-Based list. Allocate a certain amount of memory that is right next to each other. Linked- Does not need memory to be near each other,

Define: Algorithm

Description of a finite number of steps to solve a problem

Define the following property of an algorithm: Complexity

Easily translates into code

Define the following property of an algorithm: Adaptability

Easy to adapt to small changes in problem specifications

Describe the difference between experimental analysis and theoretical analysis of algorithms

Experimental analysis- Actually implementing the algorithm Theoretical analysis- uses the RAM model and characterizes runtime as a function of input size n thus creating T(n). Allows us to evaluate runtime independent of the environment.

Describe the space efficiency of array-based lists, linked-lists, search tables, and skip lists in terms of Big-Oh

Probably O(n) for everything except maybe skip lists which would be O(nlogn)

Define: Backtracking

Something used in doubly linked lists that allows to to traverse backwards in a doubly linked list.

Describe the difference between static and dynamic data structures and give examples of each

Static data structure - cannot change without recreating it from scratch - Example: array Dynamic data structure - May increase/decrease at will - Example: linked list

determine the effect of hardware improvements on an input size, N

Temperature and power consumption influence processor speed.

Describe the difference between an abstract data type and a data structure

The difference between an abstract data type and a data structure is the actual implementation. An ADT is a Stack, or a Queue A Data structure is the actual implementation of a Stack or a Queue. i.e. Array-based list, Linked list, etc.

Demonstrate how the growth rate of two functions f(n) and g(n) compare by using the limit test

lim f(n)/g(n) -----> 0 = f(n) is O(g(n)), INF = g(n) is O(f(n)), other == both

Describe the limitations of experimental studies of algorithms

• Necessary to implement the algorithm, which may be difficult • Results may not be indicative of the running time on other inputs not included in the experiment • To compare two algorithms, the same hardware and software environments must be used - Elapsed time may vary even on the same machine - Example: temperature variation and power consumption influence processor speed

Describe how to implement a search table using a contiguous memory implementation

• Search Table: dictionary implemented by means of a sorted array • Performance - lookUp -> binary search = - insert -> shift entries = - remove -> shift entries = • Applications: - Dictionaries of small size - Credit card authorizations • Lookups are very frequent • Insertions and removals rarely performed

Tail Recursion

• Tail Recursion - no code to execute after the recursive call - Recursive call is the last operation performed

Describe the assumptions of the Random Access Machine (RAM) model for algorithm analysis

• Very simple model of how a computer performs • A computer consists of: - A CPU - A bank with an unlimited number of memory cells • Assumptions - Accessing any cell in memory takes constant time - Each "simple" operation takes 1 time step • Simple operation examples: +, -, *, /, comparison, variable assignment, method call, accessing an array index - Loops and subroutines are not simple • depend on number of loop iterations or complexity of subroutine

Define: Dictionary

•Models a searchable collection of key-value entries • Main operations: - lookUp - insert - delete • Multiple entries with the same key may be allowed, depending on the context of the problem

Perform asymptotic analysis of recursive algorithm running time by estimating T(n) and stating the Big-Oh complexity class

𝑻 𝒏 = 𝒈(𝒏) 𝒊𝒇 𝒏 = 𝒅 𝒂𝑻(𝒃) + 𝒇(𝒏) 𝒊𝒇 𝒏 > d • Let d = the input size at the base case • Let g(n) = the running time of operations performed in the base case • Let a = the number of recursive calls executed in one pass of the algorithm • Let b = the expression of how the input size changes on each recursive call • Let f(n) = the running time of the remaining operations in the recursive case


Set pelajaran terkait

OB/GYN Steven Penny Review Questions: 1st Trimester Ch 23

View Set

Six Essential Nutrients and Digestion

View Set

Chapter 9: Lumbar Spine, Sacrum, and Coccyx

View Set

Chapter 8_NEW! Mini Sim_Service Marketing MARK3300

View Set