CSE 373: Asymptotic Analysis, BSTs. Michael Lee Friday, Jan 12, 2018
|
|
- Vincent Sullivan
- 5 years ago
- Views:
Transcription
1 CSE 373: Asymptotic Analysis, BSTs Michael Lee Friday, Jan 12,
2 Warmup questions Warmup: True or false: 5n + 3 O (n) n O (5n + 3) 5n + 3 = O (n) O (5n + 3) = O (n) O ( n 2) = O (n) n 2 O (1) n 2 O (n) n 2 O ( n 2) n 2 O ( n 3) n 2 O ( n 100) 2
3 Warmup questions Warmup: True or false: 5n + 3 O (n) n O (5n + 3) 5n + 3 = O (n) O (5n + 3) = O (n) O ( n 2) = O (n) n 2 O (1) n 2 O (n) n 2 O ( n 2) n 2 O ( n 3) n 2 O ( n 100) True True True (by convention) True False False False True True True 2
4 Definition: Dominated by Definition: Dominated by A function f (n) is dominated by g(n) when... There exists two constants c > 0 and n 0 > 0... Such that for all values of n n 0... f (n) c g(n) is true Definition: Big-O O (f (n)) is the family or set of all functions that are dominated by f (n) 3
5 Definitions: Dominates f (n) O (g(n)) is like saying f (n) is less then or equal to g(n). Is there a way to say greater then or equal to? 4
6 Definitions: Dominates f (n) O (g(n)) is like saying f (n) is less then or equal to g(n). Is there a way to say greater then or equal to? Yes! Definition: Dominates We say f (n) dominates g(n) when: There exists two constants c > 0 and n 0 > 0... Such that for all values of n n 0... f (n) c g(n) is true 4
7 Definitions: Dominates f (n) O (g(n)) is like saying f (n) is less then or equal to g(n). Is there a way to say greater then or equal to? Yes! Definition: Dominates We say f (n) dominates g(n) when: There exists two constants c > 0 and n 0 > 0... Such that for all values of n n 0... f (n) c g(n) is true Definition: Big-Ω Ω (f (n)) is the family of all functions that dominates f (n). 4
8 A few more questions... True or false? 4n 2 Ω (1) 4n 2 Ω (n) 4n 2 Ω ( n 2) 4n 2 Ω ( n 3) 4n 2 Ω ( n 4) 4n 2 O (1) 4n 2 O (n) 4n 2 O ( n 2) 4n 2 O ( n 3) 4n 2 O ( n 4) 5
9 A few more questions... True or false? 4n 2 Ω (1) True 4n 2 O (1) False 4n 2 Ω (n) 4n 2 Ω ( n 2) 4n 2 Ω ( n 3) 4n 2 Ω ( n 4) True True False False 4n 2 O (n) 4n 2 O ( n 2) 4n 2 O ( n 3) 4n 2 O ( n 4) False True True True 5
10 Definition: Big-Θ Definition: Big-Θ We say f (n) Θ (g(n)) when both: f (n) O (g(n)) and... f (n) Ω (g(n))...are true. 6
11 Definition: Big-Θ Definition: Big-Θ We say f (n) Θ (g(n)) when both: f (n) O (g(n)) and... f (n) Ω (g(n))...are true. Note: in industry, it s common for many people to ask for the big-o when they really want the big-θ! 6
12 Modeling complex loops Exercise: construct a mathematical function modeling the worst-case runtime in terms of n. Assume the println takes c time. for (int i = 0; i < n; i++) { for (int j = 0; j < i; j++) { System.out.println("Foo!"); 7
13 Modeling complex loops Exercise: construct a mathematical function modeling the worst-case runtime in terms of n. Assume the println takes c time. for (int i = 0; i < n; i++) { for (int j = 0; j < i; j++) { System.out.println("Foo!"); A handwavy answer: T (n) = 0c + 1c + 2c + 3c (n 1)c 7
14 Modeling complex loops Exercise: construct a mathematical function modeling the worst-case runtime in terms of n. Assume the println takes c time. for (int i = 0; i < n; i++) { for (int j = 0; j < i; j++) { System.out.println("Foo!"); A handwavy answer: T (n) = 0c + 1c + 2c + 3c (n 1)c i 1 A not-handwavy answer: T (n) = c i=0 j=0 7
15 Simplifying summations Strategies: 8
16 Simplifying summations Strategies: Wolfram Alpha 8
17 Simplifying summations Strategies: Wolfram Alpha Apply summation identities 8
18 Simplifying summations Strategies: Wolfram Alpha Apply summation identities i 1 T (n) = c = i=0 j=0 8
19 Simplifying summations Strategies: Wolfram Alpha Apply summation identities i 1 T (n) = c = i=0 j=0 ci i=0 Summation of a constant 8
20 Simplifying summations Strategies: Wolfram Alpha Apply summation identities i 1 T (n) = c = ci i=0 j=0 i=0 = c i i=0 Summation of a constant Factoring out a constant 8
21 Simplifying summations Strategies: Wolfram Alpha Apply summation identities i 1 T (n) = c = ci i=0 j=0 i=0 = c i = c i=0 n(n 1) 2 Summation of a constant Factoring out a constant Gauss s identity 8
22 Simplifying summations Strategies: Wolfram Alpha Apply summation identities i 1 T (n) = c = ci i=0 j=0 i=0 = c i = c i=0 n(n 1) 2 Summation of a constant Factoring out a constant Gauss s identity i 1 So, T (n) = c = c 2 n2 c 2 n i=0 j=0 8
23 Simplifying summations Strategies: Wolfram Alpha Apply summation identities i 1 T (n) = c = ci i=0 j=0 i=0 = c i = c i=0 n(n 1) 2 Summation of a constant Factoring out a constant Gauss s identity i 1 So, T (n) = i=0 j=0 c = c 2 n2 c 2 n {{ closed form 8
24 Simplifying summations Exercise: model the worst-case runtime using summations, find a closed form, find the big-theta bound. public void mystery2(int[] arr) { for (int i = 5; i < arr.length; i++) { int c = 0; for (int j = i; j < arr.length; j++) { c += arr[j]; System.out.println(c); 9
25 Simplifying summations Exercise: model the worst-case runtime using summations, find a closed form, find the big-theta bound. public void mystery2(int[] arr) { for (int i = 5; i < arr.length; i++) { int c = 0; for (int j = i; j < arr.length; j++) { c += arr[j]; System.out.println(c); Model: Let n be the array length. Then, T (n) = 1 i=5 j=i 9
26 Simplifying summations continued 1 = i=5 j=i 10
27 Simplifying summations continued 1 = i=5 j=i i i=5 j=0 j=0 Normalize lower bound 10
28 Simplifying summations continued i 1 1 = 1 1 Normalize lower bound i=5 j=i i=5 j=0 j=0 = (n i) Apply identity i=5 10
29 Simplifying summations continued i 1 1 = 1 1 Normalize lower bound i=5 j=i i=5 j=0 j=0 = (n i) Apply identity i=5 n = (n i) (n i) Normalize lower bound i=0 i=0 10
30 Simplifying summations continued i 1 1 = 1 1 Normalize lower bound i=5 j=i i=5 j=0 j=0 = (n i) Apply identity i=5 n = (n i) (n i) Normalize lower bound i=0 i=0 n 1 n = n i n + i i=0 i=0 i=0 i=0 Split summations 10
31 Simplifying summations continued i 1 1 = 1 1 i=5 j=i i=5 j=0 j=0 Normalize lower bound = (n i) Apply identity i=5 n = (n i) (n i) Normalize lower bound i=0 n 1 i= = n i n + i i=0 = n 2 i=0 n(n 1) 2 i=0 5n + 10 i=0 Split summations Apply identities 10
32 Handling recursive functions Exercise: model the worst-case runtime of this method. public static int sum(int[] arr) { return sumhelper(0, int[] arr); private static int sumhelper(int curr, int[] arr) { if (curr == arr.length) { return 0; else { return arr[curr] + sumhelper(curr + 1); 11
33 Handling recursive functions Exercise: model the worst-case runtime of this method. public static int sum(int[] arr) { return sumhelper(0, int[] arr); private static int sumhelper(int curr, int[] arr) { if (curr == arr.length) { return 0; else { return arr[curr] + sumhelper(curr + 1); Answer: create a recurrence. c 1 when n = 0 T (n) = c 2 + T (n 1) otherwise Note: here, n is the number of items we need to visit, and c 1 and c 2 are some constants. 11
34 Simplifying recurrences How do we find a closed form for: c 1 when n = 0 T (n) = c 2 + T (n 1) otherwise One method: the unfolding method. 12
35 Simplifying recurrences How do we find a closed form for: c 1 when n = 0 T (n) = c 2 + T (n 1) otherwise One method: the unfolding method. Observation: when n = 4, T (n) = c 2 + (c 2 + (c 2 + (c 2 + c 1 ))) 12
36 Simplifying recurrences How do we find a closed form for: c 1 when n = 0 T (n) = c 2 + T (n 1) otherwise One method: the unfolding method. Observation: when n = 4, T (n) = c 2 + (c 2 + (c 2 + (c 2 + c 1 ))) We repeat c 2 four times, so T (4) = 4c 2 + c 1. After generalizing: T (n) = c 1 + c 2 = c 1 + c 2 n. i=0 12
37 The Dictionary ADT A dictionary contains a bunch of key-value pairs. Every key is unique (no duplicate keys allowed); the values can be arbitrary. A client can provide a key to look up the corresponding value. 13
38 The Dictionary ADT A dictionary contains a bunch of key-value pairs. Every key is unique (no duplicate keys allowed); the values can be arbitrary. A client can provide a key to look up the corresponding value. Supported operations: get: Retrieves the value corresponding to the given key put: Updates the value corresponding to the given key remove: Removes the given key (and corresponding value) containskey: Returns whether dictionary contains given key size: Returns the number of key-value pairs 13
39 The Dictionary ADT A dictionary contains a bunch of key-value pairs. Every key is unique (no duplicate keys allowed); the values can be arbitrary. A client can provide a key to look up the corresponding value. Supported operations: get: Retrieves the value corresponding to the given key put: Updates the value corresponding to the given key remove: Removes the given key (and corresponding value) containskey: Returns whether dictionary contains given key size: Returns the number of key-value pairs Alternative names: map, lookup table 13
40 The Set ADT A set is a collection of items. A set cannot contain any duplicate items: each item must be unique. 14
41 The Set ADT A set is a collection of items. A set cannot contain any duplicate items: each item must be unique. Supported operations: add: Adds the given item to the set remove: Removes the given item to the set contains: Returns true if the set contains this item size: Returns the number of items in the set 14
42 The Set ADT A set is a collection of items. A set cannot contain any duplicate items: each item must be unique. Supported operations: add: Adds the given item to the set remove: Removes the given item to the set contains: Returns true if the set contains this item size: Returns the number of items in the set Two questions: 1. Do sets (and dictionaries) need to order items in some way? 2. We can implement a set on top of some dictionary: how? 14
43 Algorithm design practice: ArrayDictionary Ex: consider your ArrayDictionary implementation; fill in table: Operation Description of algorithm Big-Θ bound get put remove containskey 15
44 Algorithm design practice: ArrayDictionary Ex: consider your ArrayDictionary implementation; fill in table: Operation Description of algorithm Big-Θ bound get Scan through the internal array, see if Θ (n) the key exists. Return value if it does. put Scan through the internal array, replace Θ (n) the value if we find the key-value pair. Otherwise, add the new pair at the end. remove Scan through the internal array and find Θ (n) the key-value pair. Remove it, and shift over the remaining elements. containskey Scan through the array... Θ (n) 15
45 Idea: exploit additional property of keys Observation: sometimes, keys are comparable and sortable. 16
46 Idea: exploit additional property of keys Observation: sometimes, keys are comparable and sortable. Idea: Can we exploit the sortability of these keys? 16
47 Design practice: implementing get Suppose we add the following invariant to ArrayDictionary: SortedArrayDictionary invariant The internal array, at all times, must remain sorted. How do you implement get? What s the big-θ bound? 17
48 The binary search algorithm Core algorithm (in pseudocode): public V get(k key): return search(key, 0, this.size) private K search(k key, int lowindex, int highindex): if lowindex > highindex: key not found, throw an exception else: middleindex = average of lowindex and highindex pair = this.array[middleindex] if pair.key == key: return pair.value else if pair.key < key: return search(key, lowindex, middleindex) else if pair.key > key: return search(key, middleindex + 1, highindex) 18
49 The binary search algorithm Core algorithm (in pseudocode): public V get(k key): return search(key, 0, this.size) private K search(k key, int lowindex, int highindex): if lowindex > highindex: key not found, throw an exception else: middleindex = average of lowindex and highindex pair = this.array[middleindex] if pair.key == key: return pair.value else if pair.key < key: return search(key, lowindex, middleindex) else if pair.key > key: return search(key, middleindex + 1, highindex) Ex: model the worst-case runtime. Assume the time needed to compare two keys takes c time. Let n =??? 18
50 The binary search algorithm Core algorithm (in pseudocode): public V get(k key): return search(key, 0, this.size) private K search(k key, int lowindex, int highindex): if lowindex > highindex: key not found, throw an exception else: middleindex = average of lowindex and highindex pair = this.array[middleindex] if pair.key == key: return pair.value else if pair.key < key: return search(key, lowindex, middleindex) else if pair.key > key: return search(key, middleindex + 1, highindex) Ex: model the worst-case runtime. Assume the time needed to compare two keys takes c time. Let n = highindex lowindex. 18
51 The binary search algorithm Core algorithm (in pseudocode): public V get(k key): return search(key, 0, this.size) private K search(k key, int lowindex, int highindex): if lowindex > highindex: key not found, throw an exception else: middleindex = average of lowindex and highindex pair = this.array[middleindex] if pair.key == key: return pair.value else if pair.key < key: return search(key, lowindex, middleindex) else if pair.key > key: return search(key, middleindex + 1, highindex) 1 When n 0 Answer: T (n) c + T ( ) n Otherwise 2 18
52 Finding a closed form 1 When n 0 Our answer: T (n) c + T ( ) n Otherwise Question: how do we find a closed form? 2 19
53 Finding a closed form 1 When n 0 Our answer: T (n) c + T ( ) n Otherwise Question: how do we find a closed form? Try unfolding? 2 19
54 Finding a closed form 1 When n 0 Our answer: T (n) c + T ( ) n Otherwise Question: how do we find a closed form? Try unfolding? 2 T (n) = c + (c + (c (c + 1))) = c + c + {{... + c +1 t=num times 19
55 Finding a closed form 1 When n 0 Our answer: T (n) c + T ( ) n Otherwise Question: how do we find a closed form? Try unfolding? 2 T (n) = c + (c + (c (c + 1))) = c + c + {{... + c +1 t=num times n t
56 Finding a closed form 1 When n 0 Our answer: T (n) c + T ( ) n Otherwise Question: how do we find a closed form? Try unfolding? 2 T (n) = c + (c + (c (c + 1))) = c + c + {{... + c +1 t=num times n t
57 Finding a closed form 1 When n 0 Our answer: T (n) c + T ( ) n Otherwise Question: how do we find a closed form? Try unfolding? 2 T (n) = c + (c + (c (c + 1))) = c + c + {{... + c +1 t=num times n t What s the relationship? 19
58 Finding a closed form 1 When n 0 Our answer: T (n) c + T ( ) n Otherwise Question: how do we find a closed form? Try unfolding? 2 T (n) = c + (c + (c (c + 1))) = c + c + {{... + c +1 t=num times n t What s the relationship? n 2 t+1 19
59 Finding a closed form 1 When n 0 Our answer: T (n) c + T ( ) n Otherwise Question: how do we find a closed form? Try unfolding? 2 T (n) = c + (c + (c (c + 1))) = c + c + {{... + c +1 t=num times n t What s the relationship? n 2 t+1 Solve for t: 19
60 Finding a closed form 1 When n 0 Our answer: T (n) c + T ( ) n Otherwise Question: how do we find a closed form? Try unfolding? 2 T (n) = c + (c + (c (c + 1))) = c + c + {{... + c +1 t=num times n t What s the relationship? n 2 t+1 Solve for t: t log(n) 1 19
61 Finding a closed form 1 When n 0 Our answer: T (n) c + T ( ) n Otherwise Question: how do we find a closed form? Try unfolding? 2 T (n) = c + (c + (c (c + 1))) = c + c + {{... + c +1 t=num times n t What s the relationship? n 2 t+1 Solve for t: t log(n) 1 Final model: T (n) c(log(n) 1)
62 Finding a closed form 1 When n 0 Our answer: T (n) c + T ( ) n Otherwise Question: how do we find a closed form? Try unfolding? 2 T (n) = c + (c + (c (c + 1))) = c + c + {{... + c +1 t=num times n t What s the relationship? n 2 t+1 Solve for t: t log(n) 1 Final model: T (n) c(log(n) 1)
63 Finding a closed form 1 When n 0 Our answer: T (n) c + T ( ) n Otherwise Question: how do we find a closed form? Try unfolding? 2 T (n) = c + (c + (c (c + 1))) = c + c + {{... + c +1 t=num times n t What s the relationship? n 2 t+1 Solve for t: t log(n) 1 Final model: T (n) c(log(n) 1) + 1 So, we conclude: T (n) Θ (log(n)) 19
64 SortedArrayDictionary Fill in the remainder of this table for SortedArrayDictionary: Operation Description of algorithm Big-Θ bound get Use binary search. Θ (log(n)) put remove containskey 20
65 SortedArrayDictionary Fill in the remainder of this table for SortedArrayDictionary: Operation Description of algorithm Big-Θ bound get Use binary search. Θ (log(n)) put Use binary search to find key. Θ (n) If it doesn t exist, insert into array. remove Use binary search to find key. Θ (n) Once found, remove it and shift over remaining elements. containskey Use binary search. Θ (log(n)) 20
66 Idea: Moving away from lists Observation: Changing our array is still difficult 21
67 Idea: Moving away from lists Observation: Changing our array is still difficult Idea: Use a different data structure optimized for both searching and insertion? 21
68 Idea: Moving away from lists Observation: Changing our array is still difficult Idea: Use a different data structure optimized for both searching and insertion? Answer: Use a Binary Search Tree (BST) 21
CSE 373: AVL trees. Michael Lee Friday, Jan 19, 2018
CSE 373: AVL trees Michael Lee Friday, Jan 19, 2018 1 Warmup Warmup: What is an invariant? What are the AVL tree invariants, exactly? Discuss with your neighbor. 2 AVL Trees: Invariants Core idea: add
More informationSection 03: Asymptotic Analysis
Section 03: Asymptotic Analysis Review Problems 1. Code Analysis For each of the following code blocks, what is the worst-case runtime? Give a big-θ bound. (a) public IList repeat(doublelinkedlist
More informationCSE wi: Practice Midterm
CSE 373 18wi: Practice Midterm Name: UW email address: Instructions Do not start the exam until told to do so. You have 80 minutes to complete the exam. This exam is closed book and closed notes. You may
More informationCSE 146. Asymptotic Analysis Interview Question of the Day Homework 1 & Project 1 Work Session
CSE 146 Asymptotic Analysis Interview Question of the Day Homework 1 & Project 1 Work Session Comparing Algorithms Rough Estimate Ignores Details Or really: independent of details What are some details
More informationSection 05: Midterm Review
Section 05: Midterm Review 1. Asymptotic Analysis (a) Applying definitions For each of the following, choose a c and n 0 which show f(n) O(g(n)). Explain why your values of c and n 0 work. (i) f(n) = 5000n
More informationPROGRAM EFFICIENCY & COMPLEXITY ANALYSIS
Lecture 03-04 PROGRAM EFFICIENCY & COMPLEXITY ANALYSIS By: Dr. Zahoor Jan 1 ALGORITHM DEFINITION A finite set of statements that guarantees an optimal solution in finite interval of time 2 GOOD ALGORITHMS?
More information4.1 Real-world Measurement Versus Mathematical Models
Chapter 4 Complexity To analyze the correctness of a computer program, we reasoned about the flow of variable values throughout that program and verified logical properties using this information. In addition
More information10/5/2016. Comparing Algorithms. Analyzing Code ( worst case ) Example. Analyzing Code. Binary Search. Linear Search
10/5/2016 CSE373: Data Structures and Algorithms Asymptotic Analysis (Big O,, and ) Steve Tanimoto Autumn 2016 This lecture material represents the work of multiple instructors at the University of Washington.
More informationCSE373: Data Structures and Algorithms Lecture 4: Asymptotic Analysis. Aaron Bauer Winter 2014
CSE373: Data Structures and Algorithms Lecture 4: Asymptotic Analysis Aaron Bauer Winter 2014 Previously, on CSE 373 We want to analyze algorithms for efficiency (in time and space) And do so generally
More informationCS 234. Module 8. November 15, CS 234 Module 8 ADT Priority Queue 1 / 22
CS 234 Module 8 November 15, 2018 CS 234 Module 8 ADT Priority Queue 1 / 22 ADT Priority Queue Data: (key, element pairs) where keys are orderable but not necessarily distinct, and elements are any data.
More informationCSE 373: Floyd s buildheap algorithm; divide-and-conquer. Michael Lee Wednesday, Feb 7, 2018
CSE : Floyd s buildheap algorithm; divide-and-conquer Michael Lee Wednesday, Feb, 0 Warmup Warmup: Insert the following letters into an empty binary min-heap. Draw the heap s internal state in both tree
More informationCS 506, Sect 002 Homework 5 Dr. David Nassimi Foundations of CS Due: Week 11, Mon. Apr. 7 Spring 2014
CS 506, Sect 002 Homework 5 Dr. David Nassimi Foundations of CS Due: Week 11, Mon. Apr. 7 Spring 2014 Study: Chapter 4 Analysis of Algorithms, Recursive Algorithms, and Recurrence Equations 1. Prove the
More informationCSCI 136 Data Structures & Advanced Programming. Lecture 7 Spring 2018 Bill and Jon
CSCI 136 Data Structures & Advanced Programming Lecture 7 Spring 2018 Bill and Jon Administrative Details Lab 3 Wednesday! You may work with a partner Fill out Lab 3 Partners Google form either way! Come
More informationCSCI 136 Data Structures & Advanced Programming. Lecture 9 Fall 2018 Instructors: Bills
CSCI 136 Data Structures & Advanced Programming Lecture 9 Fall 2018 Instructors: Bills Administrative Details Remember: First Problem Set is online Due at beginning of class on Friday Lab 3 Today! You
More informationCSE 373 MAY 24 TH ANALYSIS AND NON- COMPARISON SORTING
CSE 373 MAY 24 TH ANALYSIS AND NON- COMPARISON SORTING ASSORTED MINUTIAE HW6 Out Due next Wednesday ASSORTED MINUTIAE HW6 Out Due next Wednesday Only two late days allowed ASSORTED MINUTIAE HW6 Out Due
More informationCS:3330 (22c:31) Algorithms
What s an Algorithm? CS:3330 (22c:31) Algorithms Introduction Computer Science is about problem solving using computers. Software is a solution to some problems. Algorithm is a design inside a software.
More informationIntroduction to Data Structure
Introduction to Data Structure CONTENTS 1.1 Basic Terminology 1. Elementary data structure organization 2. Classification of data structure 1.2 Operations on data structures 1.3 Different Approaches to
More informationCSE 373: Data Structures and Algorithms
CSE 373: Data Structures and Algorithms Lecture 4: Asymptotic Analysis part 3 Code Style, Recurrence Relations, Formal Big-O & Cousins Instructor: Lilian de Greef Quarter: Summer 2017 Today: Code Style
More informationSection 05: Solutions
Section 05: Solutions 1. Asymptotic Analysis (a) Applying definitions For each of the following, choose a c and n 0 which show f(n) O(g(n)). Explain why your values of c and n 0 work. (i) f(n) = 5000n
More informationAdam Blank Lecture 2 Winter 2017 CSE 332. Data Structures and Parallelism
Adam Blank Lecture 2 Winter 2017 CSE 332 Data Structures and Parallelism CSE 332: Data Structures and Parallelism Algorithm Analysis 1 Outline 1 Comparing Algorithms 2 Asymptotic Analysis Comparing Programs
More informationCS 206 Introduction to Computer Science II
CS 206 Introduction to Computer Science II 03 / 05 / 2018 Instructor: Michael Eckmann Today s Topics Questions? Comments? binary search trees Finish delete method Discuss run times of various methods Michael
More informationSection 05: Solutions
Section 05: Solutions 1. Memory and B-Tree (a) Based on your understanding of how computers access and store memory, why might it be faster to access all the elements of an array-based queue than to access
More informationSorting. Quicksort analysis Bubble sort. November 20, 2017 Hassan Khosravi / Geoffrey Tien 1
Sorting Quicksort analysis Bubble sort November 20, 2017 Hassan Khosravi / Geoffrey Tien 1 Quicksort analysis How long does Quicksort take to run? Let's consider the best and the worst case These differ
More informationImplementing Hash and AVL
Implementing Hash and AVL Data Structures and Algorithms CSE 373 SP 18 - KASEY CHAMPION 1 Warm Up CSE 373 SP 18 - KASEY CHAMPION 2 Announcements 1. Go look at your HW 1 scores, seems a lot are missing
More informationData Structures and Algorithms Key to Homework 1
Data Structures and Algorithms Key to Homework 1 January 31, 2005 15 Define an ADT for a set of integers (remember that a set may not contain duplicates) Your ADT should consist of the functions that can
More informationAsymptotic Analysis Spring 2018 Discussion 7: February 27, 2018
CS 61B Asymptotic Analysis Spring 2018 Discussion 7: February 27, 2018 1 Asymptotic Notation 1.1 Order the following big-o runtimes from smallest to largest. O(log n), O(1), O(n n ), O(n 3 ), O(n log n),
More informationComplexity of Algorithms
Complexity of Algorithms Time complexity is abstracted to the number of steps or basic operations performed in the worst case during a computation. Now consider the following: 1. How much time does it
More informationLecture 13: AVL Trees and Binary Heaps
Data Structures Brett Bernstein Lecture 13: AVL Trees and Binary Heaps Review Exercises 1. ( ) Interview question: Given an array show how to shue it randomly so that any possible reordering is equally
More informationAdam Blank Lecture 3 Winter 2017 CSE 332. Data Structures and Parallelism
Adam Blank Lecture Winter 2017 CSE 2 Data Structures and Parallelism CSE 2: Data Structures and Parallelism Heaps Outline 1 Reviewing Heap Representation 2 Heap Operations, Again buildheap A New Data Structure:
More informationCSE373 Fall 2013, Midterm Examination October 18, 2013
CSE373 Fall 2013, Midterm Examination October 18, 2013 Please do not turn the page until the bell rings. Rules: The exam is closed-book, closed-note, closed calculator, closed electronics. Please stop
More informationCSE 373 Winter 2009: Midterm #1 (closed book, closed notes, NO calculators allowed)
Name: Email address: CSE 373 Winter 2009: Midterm #1 (closed book, closed notes, NO calculators allowed) Instructions: Read the directions for each question carefully before answering. We may give partial
More informationPlotting run-time graphically. Plotting run-time graphically. CS241 Algorithmics - week 1 review. Prefix Averages - Algorithm #1
CS241 - week 1 review Special classes of algorithms: logarithmic: O(log n) linear: O(n) quadratic: O(n 2 ) polynomial: O(n k ), k 1 exponential: O(a n ), a > 1 Classifying algorithms is generally done
More informationCSE373: Data Structures & Algorithms Lecture 9: Priority Queues and Binary Heaps. Linda Shapiro Spring 2016
CSE373: Data Structures & Algorithms Lecture : Priority Queues and Binary Heaps Linda Shapiro Spring 2016 A new ADT: Priority Queue A priority queue holds compare-able data Like dictionaries, we need to
More informationHash Open Indexing. Data Structures and Algorithms CSE 373 SP 18 - KASEY CHAMPION 1
Hash Open Indexing Data Structures and Algorithms CSE 373 SP 18 - KASEY CHAMPION 1 Warm Up Consider a StringDictionary using separate chaining with an internal capacity of 10. Assume our buckets are implemented
More informationAlgorithm Analysis. Spring Semester 2007 Programming and Data Structure 1
Algorithm Analysis Spring Semester 2007 Programming and Data Structure 1 What is an algorithm? A clearly specifiable set of instructions to solve a problem Given a problem decide that the algorithm is
More information[ 11.2, 11.3, 11.4] Analysis of Algorithms. Complexity of Algorithms. 400 lecture note # Overview
400 lecture note #0 [.2,.3,.4] Analysis of Algorithms Complexity of Algorithms 0. Overview The complexity of an algorithm refers to the amount of time and/or space it requires to execute. The analysis
More informationMultiple-choice (35 pt.)
CS 161 Practice Midterm I Summer 2018 Released: 7/21/18 Multiple-choice (35 pt.) 1. (2 pt.) Which of the following asymptotic bounds describe the function f(n) = n 3? The bounds do not necessarily need
More informationComputer Science 302 Spring 2007 Practice Final Examination: Part I
Computer Science 302 Spring 2007 Practice Final Examination: Part I Name: This practice examination is much longer than the real final examination will be. If you can work all the problems here, you will
More informationToday s Outline. CSE 326: Data Structures Asymptotic Analysis. Analyzing Algorithms. Analyzing Algorithms: Why Bother? Hannah Takes a Break
Today s Outline CSE 326: Data Structures How s the project going? Finish up stacks, queues, lists, and bears, oh my! Math review and runtime analysis Pretty pictures Asymptotic analysis Hannah Tang and
More informationCSE373: Data Structures & Algorithms Lecture 9: Priority Queues and Binary Heaps. Nicki Dell Spring 2014
CSE: Data Structures & Algorithms Lecture : Priority Queues and Binary Heaps Nicki Dell Spring 01 Priority Queue ADT A priority queue holds compare-able items Each item in the priority queue has a priority
More informationMerge Sort. Algorithm Analysis. November 15, 2017 Hassan Khosravi / Geoffrey Tien 1
Merge Sort Algorithm Analysis November 15, 2017 Hassan Khosravi / Geoffrey Tien 1 The story thus far... CPSC 259 topics up to this point Priority queue Abstract data types Stack Queue Dictionary Tools
More informationModule 1: Asymptotic Time Complexity and Intro to Abstract Data Types
Module 1: Asymptotic Time Complexity and Intro to Abstract Data Types Dr. Natarajan Meghanathan Professor of Computer Science Jackson State University Jackson, MS 39217 E-mail: natarajan.meghanathan@jsums.edu
More informationCSE 373 APRIL 3 RD ALGORITHM ANALYSIS
CSE 373 APRIL 3 RD ALGORITHM ANALYSIS ASSORTED MINUTIAE HW1P1 due tonight at midnight HW1P2 due Friday at midnight HW2 out tonight Second Java review session: Friday 10:30 ARC 147 TODAY S SCHEDULE Algorithm
More informationArrays. https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html
1 Arrays Arrays in Java an array is a container object that holds a fixed number of values of a single type the length of an array is established when the array is created 2 https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html
More informationChapter 1 Programming: A General Overview
Chapter 1 Programming: A General Overview 2 Introduction This class is an introduction to the design, implementation, and analysis of algorithms. Examples: sorting large amounts of data organizing information
More informationMeasuring algorithm efficiency
CMPT 225 Measuring algorithm efficiency Timing Counting Cost functions Cases Best case Average case Worst case Searching Sorting O Notation O notation's mathematical basis O notation classes and notations
More informationFundamental problem in computing science. putting a collection of items in order. Often used as part of another algorithm
cmpt-225 Sorting Sorting Fundamental problem in computing science putting a collection of items in order Often used as part of another algorithm e.g. sort a list, then do many binary searches e.g. looking
More informationBig-O-ology. Jim Royer January 16, 2019 CIS 675. CIS 675 Big-O-ology 1/ 19
Big-O-ology Jim Royer January 16, 2019 CIS 675 CIS 675 Big-O-ology 1/ 19 How do you tell how fast a program is? Answer? Run some test cases. Problem You can only run a few test cases. There will be many
More informationTREES AND ORDERS OF GROWTH 7
TREES AND ORDERS OF GROWTH 7 COMPUTER SCIENCE 61A October 17, 2013 1 Trees In computer science, trees are recursive data structures that are widely used in various settings. This is a diagram of a simple
More informationTime Analysis of Sorting and Searching Algorithms
Time Analysis of Sorting and Searching Algorithms CSE21 Winter 2017, Day 5 (B00), Day 3 (A00) January 20, 2017 http://vlsicad.ucsd.edu/courses/cse21-w17 Binary Search: WHEN procedure binary search (x:
More informationCSE373: Data Structure & Algorithms Lecture 18: Comparison Sorting. Dan Grossman Fall 2013
CSE373: Data Structure & Algorithms Lecture 18: Comparison Sorting Dan Grossman Fall 2013 Introduction to Sorting Stacks, queues, priority queues, and dictionaries all focused on providing one element
More information1. Answer the following questions about each code fragment below. [8 points]
CS 360 Exam 1 Fall 2014 Solution 1. Answer the following questions about each code fragment below. [8 points] for (v=1; v
More informationCS 360 Exam 1 Fall 2014 Solution. 1. Answer the following questions about each code fragment below. [8 points]
CS 360 Exam 1 Fall 2014 Solution 1. Answer the following questions about each code fragment below. [8 points] for (v=1; v
More informationAlgorithm Analysis. (Algorithm Analysis ) Data Structures and Programming Spring / 48
Algorithm Analysis (Algorithm Analysis ) Data Structures and Programming Spring 2018 1 / 48 What is an Algorithm? An algorithm is a clearly specified set of instructions to be followed to solve a problem
More informationComplexity, Induction, and Recurrence Relations. CSE 373 Help Session 4/7/2016
Complexity, Induction, and Recurrence Relations CSE 373 Help Session 4/7/2016 Big-O Definition Definition: g(n) is in O( f(n) ) if there exist positive constants c and n0 such that g(n) c f(n) for all
More informationCS 261 Data Structures. Big-Oh Analysis: A Review
CS 261 Data Structures Big-Oh Analysis: A Review Big-Oh: Purpose How can we characterize the runtime or space usage of an algorithm? We want a method that: doesn t depend upon hardware used (e.g., PC,
More informationData Structures and Algorithms CSE 465
Data Structures and Algorithms CSE 465 LECTURE 2 Analysis of Algorithms Insertion Sort Loop invariants Asymptotic analysis Sofya Raskhodnikova and Adam Smith The problem of sorting Input: sequence a 1,
More informationCS 61B Asymptotic Analysis Fall 2018
CS 6B Asymptotic Analysis Fall 08 Disclaimer: This discussion worksheet is fairly long and is not designed to be finished in a single section Some of these questions of the level that you might see on
More informationCSE373 Winter 2014, Midterm Examination January 29, 2014
CSE373 Winter 2014, Midterm Examination January 29, 2014 Please do not turn the page until the bell rings. Rules: The exam is closed-book, closed-note, closed calculator, closed electronics. Please stop
More informationSEARCHING, SORTING, AND ASYMPTOTIC COMPLEXITY. Lecture 11 CS2110 Spring 2016
1 SEARCHING, SORTING, AND ASYMPTOTIC COMPLEXITY Lecture 11 CS2110 Spring 2016 Time spent on A2 2 Histogram: [inclusive:exclusive) [0:1): 0 [1:2): 24 ***** [2:3): 84 ***************** [3:4): 123 *************************
More information1. Answer the following questions about each code fragment below. [8 points]
CS 360 Exam 1 Fall 2014 Solution 1. Answer the following questions about each code fragment below. [8 points] for (r=1; r
More informationAlgorithm. Lecture3: Algorithm Analysis. Empirical Analysis. Algorithm Performance
Algorithm (03F) Lecture3: Algorithm Analysis A step by step procedure to solve a problem Start from an initial state and input Proceed through a finite number of successive states Stop when reaching a
More informationSEARCHING, SORTING, AND ASYMPTOTIC COMPLEXITY
1 A3 and Prelim 2 SEARCHING, SORTING, AND ASYMPTOTIC COMPLEXITY Lecture 11 CS2110 Fall 2016 Deadline for A3: tonight. Only two late days allowed (Wed-Thur) Prelim: Thursday evening. 74 conflicts! If you
More informationTest 1 Review Questions with Solutions
CS3510 Design & Analysis of Algorithms Section A Test 1 Review Questions with Solutions Instructor: Richard Peng Test 1 in class, Wednesday, Sep 13, 2017 Main Topics Asymptotic complexity: O, Ω, and Θ.
More informationCSCI-1200 Data Structures Spring 2018 Lecture 7 Order Notation & Basic Recursion
CSCI-1200 Data Structures Spring 2018 Lecture 7 Order Notation & Basic Recursion Review from Lectures 5 & 6 Arrays and pointers, Pointer arithmetic and dereferencing, Types of memory ( automatic, static,
More informationNotes slides from before lecture. CSE 21, Winter 2017, Section A00. Lecture 3 Notes. Class URL:
Notes slides from before lecture CSE 21, Winter 2017, Section A00 Lecture 3 Notes Class URL: http://vlsicad.ucsd.edu/courses/cse21-w17/ Notes slides from before lecture Notes January 18 (1) HW2 has been
More informationAlgorithms and Data Structures
Algorithms and Data Structures Spring 2019 Alexis Maciel Department of Computer Science Clarkson University Copyright c 2019 Alexis Maciel ii Contents 1 Analysis of Algorithms 1 1.1 Introduction.................................
More informationLecture 2: Getting Started
Lecture 2: Getting Started Insertion Sort Our first algorithm is Insertion Sort Solves the sorting problem Input: A sequence of n numbers a 1, a 2,..., a n. Output: A permutation (reordering) a 1, a 2,...,
More informationCSE 373: Data Structures and Algorithms More Asympto<c Analysis; More Heaps
CSE 373: Data Structures and More Asympto
More informationLecture 10: Introduction to Hash Tables
Lecture 10: Introduction to Hash Tables CSE 373: Data Structures and Algorithms CSE 373 19 WI - KASEY CHAMPION 1 Warm Up CSE 373 SP 18 - KASEY CHAMPION 2 Administrivia HW 2 part 1 grades went out HW 2
More informationAnalysis of Algorithms. CSE Data Structures April 10, 2002
Analysis of Algorithms CSE 373 - Data Structures April 10, 2002 Readings and References Reading Chapter 2, Data Structures and Algorithm Analysis in C, Weiss Other References 10-Apr-02 CSE 373 - Data Structures
More informationCS126 Final Exam Review
CS126 Final Exam Review Fall 2007 1 Asymptotic Analysis (Big-O) Definition. f(n) is O(g(n)) if there exists constants c, n 0 > 0 such that f(n) c g(n) n n 0 We have not formed any theorems dealing with
More informationLecture 2: Algorithm Analysis
ECE4050/CSC5050 Algorithms and Data Structures Lecture 2: Algorithm Analysis 1 Mathematical Background Logarithms Summations Recursion Induction Proofs Recurrence Relations 2 2 Logarithm Definition: 3
More informationCSC236 Week 5. Larry Zhang
CSC236 Week 5 Larry Zhang 1 Logistics Test 1 after lecture Location : IB110 (Last names A-S), IB 150 (Last names T-Z) Length of test: 50 minutes If you do really well... 2 Recap We learned two types of
More informationECE250: Algorithms and Data Structures Midterm Review
ECE250: Algorithms and Data Structures Midterm Review Ladan Tahvildari, PEng, SMIEEE Associate Professor Software Technologies Applied Research (STAR) Group Dept. of Elect. & Comp. Eng. University of Waterloo
More informationCSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators)
Name: Email address: Quiz Section: CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators) Instructions: Read the directions for each question carefully before answering. We will
More informationRecall from Last Time: Big-Oh Notation
CSE 326 Lecture 3: Analysis of Algorithms Today, we will review: Big-Oh, Little-Oh, Omega (Ω), and Theta (Θ): (Fraternities of functions ) Examples of time and space efficiency analysis Covered in Chapter
More informationCSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)
Name: Email address: Quiz Section: CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators) Instructions: Read the directions for each question carefully before answering. We will
More informationCSE 332: Data Structures & Parallelism Lecture 12: Comparison Sorting. Ruth Anderson Winter 2019
CSE 332: Data Structures & Parallelism Lecture 12: Comparison Sorting Ruth Anderson Winter 2019 Today Sorting Comparison sorting 2/08/2019 2 Introduction to sorting Stacks, queues, priority queues, and
More informationCSE 332 Spring 2014: Midterm Exam (closed book, closed notes, no calculators)
Name: Email address: Quiz Section: CSE 332 Spring 2014: Midterm Exam (closed book, closed notes, no calculators) Instructions: Read the directions for each question carefully before answering. We will
More informationASYMPTOTIC COMPLEXITY
Simplicity is a great virtue but it requires hard work to achieve it and education to appreciate it. And to make matters worse: complexity sells better. - Edsger Dijkstra ASYMPTOTIC COMPLEXITY Lecture
More informationSorting. Riley Porter. CSE373: Data Structures & Algorithms 1
Sorting Riley Porter 1 Introduction to Sorting Why study sorting? Good algorithm practice! Different sorting algorithms have different trade-offs No single best sort for all scenarios Knowing one way to
More informationLecture Notes for Chapter 2: Getting Started
Instant download and all chapters Instructor's Manual Introduction To Algorithms 2nd Edition Thomas H. Cormen, Clara Lee, Erica Lin https://testbankdata.com/download/instructors-manual-introduction-algorithms-2ndedition-thomas-h-cormen-clara-lee-erica-lin/
More informationCSE 332: Data Structures & Parallelism Lecture 5: Algorithm Analysis II. Ruth Anderson Winter 2018
CSE 332: Data Structures & Parallelism Lecture 5: Algorithm Analysis II Ruth Anderson Winter 2018 Today Finish up Binary Heaps Analyzing Recursive Code Solving Recurrences 1/12/2018 2 Analyzing code (
More informationCSE373: Data Structure & Algorithms Lecture 21: More Comparison Sorting. Aaron Bauer Winter 2014
CSE373: Data Structure & Algorithms Lecture 21: More Comparison Sorting Aaron Bauer Winter 2014 The main problem, stated carefully For now, assume we have n comparable elements in an array and we want
More informationRandomized Algorithms, Hash Functions
Randomized Algorithms, Hash Functions Lecture A Tiefenbruck MWF 9-9:50am Center 212 Lecture B Jones MWF 2-2:50pm Center 214 Lecture C Tiefenbruck MWF 11-11:50am Center 212 http://cseweb.ucsd.edu/classes/wi16/cse21-abc/
More informationMergesort again. 1. Split the list into two equal parts
Quicksort Mergesort again 1. Split the list into two equal parts 5 3 9 2 8 7 3 2 1 4 5 3 9 2 8 7 3 2 1 4 Mergesort again 2. Recursively mergesort the two parts 5 3 9 2 8 7 3 2 1 4 2 3 5 8 9 1 2 3 4 7 Mergesort
More informationI. Algorithms. examples of cubic, quadratic, NlogN, linear, logarithmic, and constant
I. Algorithms A. Intro to Analysis - Big-Oh Basically, algorithm analysis is the amount of time any program or algorithm should be expected to take for any given size of input. It is based on the number
More informationGo Bears! IE170: Algorithms in Systems Engineering: Lecture 4
Everyone Gets an A! Go Bears! IE170: Algorithms in Systems Engineering: Lecture 4 Jeff Linderoth Department of Industrial and Systems Engineering Lehigh University January 22, 2007 Taking Stock A Canonical
More informationData Structures Brett Bernstein. Lecture 1: Introduction and a Review/Enrichment of CS 101
Data Structures Brett Bernstein Lecture 1: Introduction and a Review/Enrichment of CS 101 Introduction Class Information The title of this course is Data Structures, but in reality the name only tells
More informationName (First and Last): SAMPLE SOLUTIONS
Name (First and Last): SAMPLE SOLUTIONS CS0: Data structures & algorithms Midterm Exam March 1, 017 You may use double-sided sheets of 8.5x11 paper for notes. No electronics. Show your work when appropriate.
More informationASYMPTOTIC COMPLEXITY
Simplicity is a great virtue but it requires hard work to achieve it and education to appreciate it. And to make matters worse: complexity sells better. - Edsger Dijkstra ASYMPTOTIC COMPLEXITY Lecture
More informationCS61B Spring 2016 Guerrilla Section 3 Worksheet. 12 March 2016
Spring 2016 12 March 2016 Directions: In groups of 4-5, work on the following exercises. Do not proceed to the next exercise until everyone in your group has the answer and understands why the answer is
More informationCOMP Data Structures
COMP 2140 - Data Structures Shahin Kamali Topic 5 - Sorting University of Manitoba Based on notes by S. Durocher. COMP 2140 - Data Structures 1 / 55 Overview Review: Insertion Sort Merge Sort Quicksort
More informationUniversity of Toronto Department of Electrical and Computer Engineering. Midterm Examination. ECE 345 Algorithms and Data Structures Fall 2010
University of Toronto Department of Electrical and Computer Engineering Midterm Examination ECE 345 Algorithms and Data Structures Fall 2010 Print your name and ID number neatly in the space provided below;
More informationPseudo code of algorithms are to be read by.
Cs502 Quiz No1 Complete Solved File Pseudo code of algorithms are to be read by. People RAM Computer Compiler Approach of solving geometric problems by sweeping a line across the plane is called sweep.
More informationClassic Data Structures Introduction UNIT I
ALGORITHM SPECIFICATION An algorithm is a finite set of instructions that, if followed, accomplishes a particular task. All algorithms must satisfy the following criteria: Input. An algorithm has zero
More informationRandomized Algorithms: Element Distinctness
Randomized Algorithms: Element Distinctness CSE21 Winter 2017, Day 24 (B00), Day 16-17 (A00) March 13, 2017 http://vlsicad.ucsd.edu/courses/cse21-w17 Element Distinctness: WHAT Given list of positive integers
More informationComputational Complexity: Measuring the Efficiency of Algorithms
Computational Complexity: Measuring the Efficiency of Algorithms Rosen Ch. 3.2: Growth of Functions Rosen Ch. 3.3: Complexity of Algorithms Walls Ch. 10.1: Efficiency of Algorithms Measuring the efficiency
More informationCSE 373 Spring Midterm. Friday April 21st
CSE 373 Spring 2006 Data Structures and Algorithms Midterm Friday April 21st NAME : Do all your work on these pages. Do not add any pages. Use back pages if necessary. Show your work to get partial credit.
More information