

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A part of the lecture notes for cse 331, summer 2002, focusing on asymptotic notation, quiz, algorithms and data structures. Topics covered include asymptotically tight bound, recurrence relations, master method/theorem, maximum subsequence sum, binary search, pow, linear data structures, stacks, and queues. Algorithm examples are provided from chapter two, including maximum subsequence sum and binary search.
Typology: Study notes
1 / 2
This page cannot be seen from the preview
Don't miss anything!


(a) * Asymptotically tight bound
(a) * Bounding methods: i. * Master Method/Theorem ( precedence troubles) ii. N (logb^ a)±^ not N logb^ (a±) iii. Doesn’t matter for some cases, does for some
(a) * Maximum Subsequence Sum (pp. 24, 26, 27, 29) Algorithm 1-4 Notes: i. * Algorithm 2 - 3: Recursify. Divide and Conquer! ii. * Algorithm 3: Cute iii. * Algorithm 4: Lean and mean (b) * Binary Search (p. 31) i. * Like guessing numbers ii. * Searching good: O(log N ). Update not so good: O(N ) iii. * We will see better data structures for searching (c) Pow (p. 33) (another cute recursion example)
(a) Abstract Data Type Basics i. Well-defined interface is important ii. Large programs heavily use instantiated ADTs; running time is important iii. Generally will look at the running time of the interfaces (for comparison) (b) List i. Generic interfaces: Insert, Delete, Find* ii. Somewhat malleable (c) List (Contiguous Allocation/Arrays) i. Generally static size can make Insert and Delete expensive (O(N )) ii. Generally not used for more than simple lists (d) List (Pointers/Linked Lists) i. Uses an extra data field to store a pointer to next list element ii. Insert and Delete become O(1) iii. Find* is still O(N ) iv. Doubly-linked lists allow reverse traversal; often fast/convenient. v. Example: Radix Sort A. AKA card sort, generalized bucket sort B. Bucket sort: (1) Read input and, (2) Stuff into individual array locations, (3) Read out array locations in order C. Bucket sort is bad for big numbers (2^32 buckets for most machines?!)
D. Radix sort: Let b be the base/radix of our number system (base 8, 10, 16, etc.) Use b buckets and sort numbers by their digit place. Any two numbers can have same value for any given place, so use a linked list to store repeats. Repeats are inserted in order. E. When done with all b place passes, read out the lists. F. Must be done starting with least significant place/digit. (e) Stacks (Last In First Out) i. Basic Interfaces: Push, Pop ii. Stack is a list with restrictions placed on insertion and deletion: deletion (Pop) must remove last (most recent) element inserted (Pushed). iii. Implementations can use arrays or linked lists. iv. Array implementation is trivial and marginally faster than that using linked lists. v. Implementation using linked lists gives O(1) bound for both interfaces (if malloc, free, new, delete can be considered O(1)). vi. Example: RPN or postfix notation for calculators: 8( (6 + 5) * (3 + 2)) = 6 5 + 3 2 + * 8 * vii. Examples: PostScript: Draw a line between (X, Y ) and (X 2 , Y 2 ): X Y moveto X 2 Y 2 stroke Draw a circle with center at (X, Y ), radius r, delimited by angles a and b: X Y r a b arc stroke (f) Queues (First In First Out) i. Basic Interfaces: Enqueue, Dequeue ii. Queue is a list with restrictions placed on insertion and deletion: deletion (Dequeue) must remove the first (least recent) element inserted. iii. Implementations can use arrays or linked lists. iv. Array implementation is not difficult, requiring use of “circular array” addressing and three placeholders (rear, front and size). v. Both implementations’ interfaces have O(1) running time. vi. Example: any “fair” wait-for-service implementation (e.g., enrollment) vii. Example: print queue (sort of – why sort of?)
(a) Basic assumptions i. For now, we will assume that data to be sorted fits in memory. ii. For convenience we’ll sort an array of values. (b) Bubble Sort i. Likely the simplest of sorting algorithms. ii. Start from array element 0. Each two consecutive elements in the array (or other structure) are checked. If left (element k) side is larger than the left (element k + 1), swap them. iii. Continue with as many passes necessary until sorted.