cs exam 2 review slides

¡Supera tus tareas y exámenes ahora con Quizwiz!

what is the basic process of quicksort

- pick pivot - move all numbers less than pivot to beginning - move all numbers greater or equal to pivot to end - quicksort the numbers less than - quicksort the numbers greater than

why is hash collision a problem

- put keys in slots determined by hash function - collision means natural choice slot is taken - cannot replace k1 with k2 because the jeys are differeny - so where do we put k2

best and average case time complexity of quicksort

O n log n

what is the time complexity for mergesort

O n log n

what is the time complexity of recursion

O(2^n)

a tree of function calls is a single chain of length at most what time

O(log n)

what is the timing of insertion sort if the array is sorted or exactly one item is out of place

O(n)

best-case performance of bubble sort

O(n) comparisons, O(1) swaps

what does memoization do to time complexity

O(n) memoization

worst case performance of bubble sort

O(n2) comparisons and swaps

worst case time complexity of quick sort

O(n2) when list is sorted or reverse sorted order

best case performance of insertion sort

On comparisons , O1 swaps

what is the timing for merging

On time because we only need to do a comparison and some assignment for each item that gets added to the final list

average performance of bubble sort

On2 comparisons and swaps

average performance of insertion sort

On2 comparisons and swaps

worst case performance of insertion sort

On2 comparisons and swaps

best case performance of selection sort

On2 comparisons, O1 swaps

average performance of selection sort

On2 comparisons, On swaps

worst case performance of selection sort

On2 comparisons, On swaps

what does having a greedy algorithm mean

algorithm picls the best solution at the moment without regard for consequences - picls the best immediate output, but does not consider the big picture

what is a greedy algorithm

algorithmic strategy makes the best optimal choice at each small stage with goal of eventually leading to a globally optimum solution

what is mapping

association between two sets of things - key value pairs

running time for quick select

average - On worst - On2 but by random pivot, worst case can be avoided in most cases

what is one the most important things to have in recursive function

base case - where recursion stops

what are hashable objects

bool , int, long, float, string, tuple

how to use recursion in a function

call function inside of function

what is a hash collision

case when two different keys have the same hash value

what is memoization recursion

collapse repeated nodes and don't do the same work twice - but otherwise treat it like the same recursive algorithm

what is separate chaining

collisions are resolved by storing all colliding keys in the same slot (using list or some other data structure)

what is one of several powerful techniques for algorithm design

divide and conquer

divide and conquer paradigm includes three steps

divide the problem into subproblems til a base base conquer the subproblems by solving recursively combine subproblem solutions

the mapping between a key and bucket is alled

hash function

the information to be retrieved in stored in a ________ which is best thought of as an array of m locations called ______

hash table buckets

python hash()

hash(object) - only takes one parameter - object whose hash value is to be returned - only immutable objects can be hashed

what is rehashing

increase the number of buckets - not just by appending more, but have to reinsert all the items in mapping so that they can be found when we next get them

what is different about quickselect

instead of recursive into both sides, quickselect only recurses into one side - the side with the element it is searching for

what is insertion sort

iterates over a progressively growing sorted section of the list - bubbles the next unsorted item into place - like deck of cards

what is the basic definition of what bubble sort does

iterates over every pair in collection, swaps out of order pairs

what is the basic definition of selection sort

iterates over every unsorted item in collection, selects the next biggest(or smallest)

what is the first step of merge sort

keep tract of smallest element in each sorted half - insert smallest of two elements into temporary array - repeat until done

how long would the time be if we used slicing

linear time

what are non hashable objects

lists, sets, dictionary

what does the load factor do

measure that decides when to increase the hashmap capacity to maintain the get() and put() operation complexity of O1

does a greedy strategy produce an optimal solution in many problems?

no

why is binary search time O(log n)

number of times you can cut n in half before it gets down to 1

what is recursion

problem solving technique that involves breaking up a problem into smaller instances of the same problem (also called subproblems) until we get a small enough subproblem having a trivial solution

what is the time to store and retrive data

proportional to the time to compute the hash function

what is load factor

ratio of number of entries in the table to the table size

what is better about timing of selection sort than bubble sort

selection sort is always performed at most On swaps no matter how the input list is arranged

what is a strategy to handle hash collision

separate chaining(open hashing)

what is the main idea of insertion sort

sort as you go

what is tabulation (iterative)

step 1: identify solution to problem with respect to smaller subproblems step 2: bottom up - start with solutions to smallest problems and build solutions to the larger problems

what x calls, what items have been sorted using bubble sort

the last x items

after x calls, how many items have been sorted using selection sort

the last x items are sorted and in their final position

after x calls what items are sorted for insertion sort

the last x items are sorted relative to each other

what is the best case scenario for using bubble sort

the list is already sorted

what is the most direct application of the divide and conquer paradigm to the sorting problem

the mergesort algorithm

what does it mean that keys must be unique

there can only be one value associated with a given key

what is quickselect

uses the same overall approach as quicksort - select one element as pivot - partition data in two based on pivot

what is the main idea of the selection. sort

with every inner loop, select the next highest item and move it to the end


Conjuntos de estudio relacionados

Properties Used in Algebra and Geometry/Complex Number System

View Set

Chapter 52 Case Study and Questions

View Set

Individual, Family and Community Health Promotion Ch 6, 7, 8, 9

View Set

Dia de los muertos True or False

View Set