Data Structures and Algorithms Course Introduction. Google Camp Fall 2016 Yanqiao ZHU

Size: px
Start display at page:

Download "Data Structures and Algorithms Course Introduction. Google Camp Fall 2016 Yanqiao ZHU"

Transcription

1 Data Structures and Algorithms Course Introduction Google Camp Fall 2016 Yanqiao ZHU

2 What are Algorithms? An algorithm is a self-contained step-by-step set of operations to be performed. Algorithms perform calculation, data processing, and/or automated reasoning tasks. An algorithm is an effective method that can be expressed within a finite amount of space and time and in a well-defined formal language for calculating a function. DATA STRUCTURES AND ALGORITHMS GOOGLE CAMP FALL 2016 YANQIAO ZHU 9/22/2016 2

3 What are Algorithms? (cont.) Starting from an initial state and initial input (perhaps empty), the instructions describe a computation that, when executed, proceeds through a finite number of well-defined successive states, eventually producing output and terminating at a final ending state. The transition from one state to the next is not necessarily deterministic; some algorithms, known as randomized algorithms, incorporate random input. DATA STRUCTURES AND ALGORITHMS GOOGLE CAMP FALL 2016 YANQIAO ZHU 9/22/2016 3

4 What are Data Structures? A data structure is a particular way of organizing data in a computer so that it can be used efficiently. Data structures can implement one or more particular abstract data types (ADT), which specify the operations that can be performed on a data structure and the computational complexity of those operations. In comparison, a data structure is a concrete implementation of the specification provided by an ADT. DATA STRUCTURES AND ALGORITHMS GOOGLE CAMP FALL 2016 YANQIAO ZHU 9/22/2016 4

5 Importance of Algorithms and Data Structures Computing Curricula 2005: The Overview Report CC 2005 provides undergraduate curriculum guidelines for five defined sub-disciplines of computing: 1. Computer Science (CS) 2. Computer Engineering (CE) 3. Information Systems (IS) 4. Information Technology (IT) 5. Software Engineering (SE) DATA STRUCTURES AND ALGORITHMS GOOGLE CAMP FALL 2016 YANQIAO ZHU 9/22/2016 5

6 Importance of Algorithms and Data Structures (cont.) Table: Comparative weight of computing topics across the five kinds of degree programs DATA STRUCTURES AND ALGORITHMS GOOGLE CAMP FALL 2016 YANQIAO ZHU 9/22/2016 6

7 Common Requirements of Computing Degrees A foundation in the concepts and skills of computer programming. The foundation has five layers: a) an intellectual understanding of, and an appreciation for, the central role of algorithms and data structures; b) an understanding of computer hardware from a software perspective, for example, use of the processor, memory, disk drives, display, etc. c) fundamental programming skills to permit the implementation of algorithms and data structures in software; d) skills that are required to design and implement larger structural units that utilize algorithms and data structures and the interfaces through which these units communicate; e) software engineering principles and technologies to ensure that software implementations are robust, reliable, and appropriate for their intended audience. DATA STRUCTURES AND ALGORITHMS GOOGLE CAMP FALL 2016 YANQIAO ZHU 9/22/2016 7

8 Course Overview Fundamentals Models of Computation Asymptotic Notations Solving Recurrences Divide-and-Conquer Case Studies Introduction to Multi-Thread Algorithms and their Analysis Sorting Quicksort Priority Queue, Heap and Heapsort Linear-Time Sorting Coding and Trees Concepts Huffman Coding Binary Search Trees AVL Trees Red-Black Trees Skip Lists DATA STRUCTURES AND ALGORITHMS GOOGLE CAMP FALL 2016 YANQIAO ZHU 9/22/2016 8

9 Course Overview (cont.) Hashing Hashing with Chaining Open Addressing Amortized Analysis Graphs Breadth-First Search Depth-First Search Priority-First Search Minimal Spanning Trees Shortest Paths Dijkstra Bellman Ford Floyd-Warshall DATA STRUCTURES AND ALGORITHMS GOOGLE CAMP FALL 2016 YANQIAO ZHU 9/22/2016 9

10 Course Overview (cont.) String Matching Knuth-Morris-Pratt Algorithm Boyer-Moore Algorithm Karp-Rabin Algorithm Dynamic Programming Case Studies: Fibonacci, Test Justification, Edit Distance and Knapsack Polynomial Time and Pseudo- Polynomial Time 2 Kinds of Guessing Computational Complexity P, EXP and R NP Reductions DATA STRUCTURES AND ALGORITHMS GOOGLE CAMP FALL 2016 YANQIAO ZHU 9/22/

11 Data Structures and Algorithms Asymptotic Notation Google Camp Fall 2016 Yanqiao ZHU

12 Measuring the Cost of an Algorithm Time consumption: dependent on multiple factors Input scale Machine performance Runtime and environment factors Compiler optimization A key factor: the scale of the problem instance Generally, the time cost increases with the scale of the problem instance 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 2

13 Measuring the Cost of an Algorithm (cont.) For measurement, we take a function denoting the change of a program s execution time against the input scale, which is defined as the time complexity of an algorithm Specifically, with a certain algorithm dealing with a certain problem, T(n) denotes the needed time However, the scale is not always proportional to execution times: Sorting n numbers: sometimes all elements need to be swapped, sometimes none. From all inputs with the size of n, T(n) is chosen to be the longest of the execution time and T(n) denotes the time complexity of the algorithm 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 3

14 Asymptotic Complexity For a problem with two different algorithms A and B, we could evaluate the efficiency through comparing the time complexity T A (n) and T B (n). For some certain problems, one algorithm may be more suitable for smallscale inputs while another for larger-scale ones. Luckily, when evaluating the performance of an algorithm, the differences dealing with small-scale problems are usually ignored while that dealing with large-scale problems are focused on. Asymptotic analysis: taking a long-term perspective and emphasis on strategies and methods of the overall trends and growth rates of the time consumption. 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 4

15 Big-O Notation Express the upper boundary of T(n) f(n) = O(g(n)) means c > 0, n 0 > 0, n n 0, 0 f(n) c g(n) Properties: For any constants c > 0, O(f(n)) = O(c f(n)) For any constants a > b > 0, O(n a + n b ) = O(n a ) 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 5

16 Random Access Machine (RAM) Random Access Memory (RAM) modeled by a big array Θ(1) registers (each 1 word) In Θ(1) time, can load r i into register r j compute (+,,, /, &,, ˆ) on registers store register r j into r i What s a word? w lg(memory size) bits assume basic objects (e.g., int) fit in word unit 4 in the course deals with big numbers realistic and powerful implement abstractions 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 6

17 Pointer Machine An atomistic abstract computational machine model akin to the Random access machine. From its read-only tape (or equivalent) a pointer machine receives input bounded symbol-sequences ( words ) made of at least two symbols e.g. { 0, 1 } -- and it writes output symbol-sequences on an output write-only tape (or equivalent). To transform a symbol-sequence (input word) to an output symbol-sequence the machine is equipped with a program a finite-state machine (memory and list of instructions). Via its state machine the program reads the input symbols, operates on its storage structure a collection of nodes (registers) interconnected by edges (pointers labelled with the symbols e.g. { 0, 1 }), and writes symbols on the output tape. 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 7

18 Pointer Machine (cont.) Cannot do arithmetic. Computation proceeds only by reading input symbols, modifying and doing various tests on its storage structure the pattern of nodes and pointers, and outputting symbols based on the tests. 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 8

19 Basic Operations Instruction statements: Arithmetic operations Comparisons Branches Calling and returning from sub-functions etc. T(n) denotes the total number of basic operations to perform in an algorithm. T(n) is determined by the number of: Statements to execute Basic operations included to perform 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 9

20 Constant O(1) OrdinaryElement(S, n) // select an ordinary element which is neither the maximum nor the minimum of n different numbers 1. select x, y, z S at random // x, y, z are different from each other 2. compare and sort them // assume after sorting a < b < c 3. print b 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 10

21 Constant O(1) (cont.) Since set S is limited, there are exact one maximum and one minimum element in S. Hence, no matter how large S is, there will be at least one ordinary element in any three elements. Step 1 needs O(3) time to take three different elements from S. (Take x = S[0], y = S[1], z = S[2]) Then, to determine the relationship among x, y and z, at most three comparisons have to be done. Thus step 2 takes O(3) time. Finally, printing the ordinary element takes O(1) time. In summary, T(n) = O(3) + O(3) + O(1) = O(7) = O(1). 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 11

22 Constant O(1) (cont.) Algorithms whose T(n) O(1), are called constant-time algorithm. These algorithms are ideal. Plus, there aren t better algorithms, because it s impossible reaping without sowing. Generally, algorithms containing one or a constant number of basic operations are constant-time algorithm. 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 12

23 c 2 g(n) f(n) Asymptotic Notations c 1 g(n) Big-O notation: expressing upper boundary Ex: 2n 2 = O(n 3 ) n 0 f(n) = Θ(g(n)) (a) n Big-Ω notation: expressing lower boundary Ex: n = Ω(lgn) c g(n) f(n) Big-Θ notation: expressing asymptotically tight boundary Θ(g(n)) = O(g(n)) Ω(g(n)) define Θ(g(n)) = {f(n): c 1 > 0, c 2 >0, n 0 > 0, n n 0, c 1 g(n) f(n) c 2 g(n)} n 0 f(n) = O(g(n)) (b) f(n) n c g(n) n 0 n 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU f(n) = Ω(g(n)) 13 (c)

24 Strict Notations: Little-o and Little-ω f(n) = o(g(n)) means c > 0, n 0 > 0, n n 0, 0 f(n) < c g(n) in o-notation, the function f(n) becomes insignificant relative to g(n) as n approaches infinity Ex: 2n 2 = o(n 3 ) f(n) = ω(g(n)) means c > 0, n 0 > 0, n n 0, 0 c g(n) < f(n) Ex: 0.5n 2 = Θ(n 2 ), 0.5n 2 o(n 2 ) 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 14

25 Space Complexity Asymptotic notations are suitable for measuring space complexity. Unless otherwise stated, space complexity usually excludes raw inputs but includes space of: Dumping Transiting Indexing Mapping Buffering etc. Algorithms need constant-scale additional space are called in-place algorithms. 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 15

26 Worst, Best and Average Case Big-O notation: a conservative estimate Any case: Actual time consumption f(n) Worst case: Actual time consumption = f(n) A conservative estimate does not exclude the best case or a better case. Average case: the expectation of time complexity. 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 16

27 Data Structures and Algorithms Linear-Time Sorting Google Camp Fall 2016 Yanqiao ZHU

28 Lower Bounds The following will be claimed in the comparison model: searching among n preprocessed items requires Ω(lgn) time binary search, AVL tree search optimal sorting n items requires Ω(nlgn) merge sort, heap sort, AVL sort optimal 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 2

29 Comparison Model of Computation Input items are black boxes (ADTs) Only support comparisons (<; >; ; ; =) Time cost is the number of comparisons 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 3

30 Decision Trees Any comparison algorithm can be viewed/specified as a tree of all possible comparison outcomes & resulting output, for a particular n: Decision Trees Algorithms Internal node Leaf Root-to-leaf path Path length (depth) Height of Tree Binary decision (comparisons) Found answer Algorithm execution Running time Worst-case running time 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 4

31 Decision Trees (cont.) Example: binary search for n = 3: Index A[0] A[1] A[2] Value a b c No A[1] < x Yes A[0] < x A[2] < x No Yes No Yes x A[0] A[0]<x A[1] A[1]<x A[2] A[2] < x 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 5

32 Search Lower Bound Suppose we have n preprocessed items. Finding a given item among all items in comparison model requires Ω(lgn) comparisons in worst case. Proof: Decision tree is binary and the number of leaves number of possible answers n (at least 1 per A[i]) height lgθ(n) = lgn±θ(1) 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 6

33 Sorting Lower Bound Leaf species answer as permutation: All n! are possible answers Proof: number of leaves n! height lg(n!) = lg(1 2 (n 1) n) = lg1 + lg2 + + lg(n 1) + lgn n/2 lgn n/2 = Ω(nlgn) 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 7

34 Linear-Time Sorting If n keys are integers (fitting in a word) {0, 1,, k 1}, we can do more than compare them. If k = n O(1), can sort in O(n) time. One conjecture is that for all k, can sort in linear time (not solved yet) Best algorithm: O((lglgn) 1/2 ) 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 8

35 Counting Sort L = array of k empty lists linked list or Python lists for j in range n: L[key(A[j])].append(A[j]) O(1) random access using integer key output = [] for i in range k: output.extend(l[i]) O(k) O(n) O(Σ(1 + L[i] )) = O(k + n) Time and space complexity: Θ(n + k) Intuition: Count key occurrences using RAM output (count) copies of each key in order, but item is more than just a key 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 9

36 Radix Sort Imagine each integer in base b d = log b k digits {0, 1,, b 1} Sort (all n items) by least significant digit [can extract in O(1) time] Sort by most significant digit [can extract in O(1) time] 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 10

37 Radix Sort (cont.) Analysis: use counting sort for digit sort: Θ(n + b) per digit Θ[(n + b)d] = Θ[(n + b) log b k] total time minimized when b = n Θ(nlog n k) = O(nc) if k n c sort sorted sorted sorted 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 11

38 Google Camp Fall 2016 Yanqiao ZHU

39 Cryptographic Hashing A cryptographic hash function is a deterministic procedure that takes an arbitrary block of data and returns a fixed-size bit string, the (cryptographic) hash value, such that an accidental or intentional change to the data will change the hash value. The data to be encoded is often called the message, and the hash value is sometimes called the message digest or simply digest. The ideal cryptographic hash function has the properties listed below. d is the number of bits in the output of the hash function. You can think of m as being 2 d. d is typically 160 or more. These hash functions can be used to index hash tables, but they are typically used in computer security applications. 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 2

40 Desirable Properties One-Way (OW): Infeasible, given y R {0, 1} d to find any x s.t. h(x) = y. This means that if you choose a random d-bit vector, it is hard to find an input to the hash that produces that vector. This involves inverting the hash function. Collision-resistance (CR): Infeasible to find x, x, s.t. x x and h(x) = h(x ). This is a collision: two input values have the same hash. Target collision-resistance (TCR): Infeasible given x to find x = x s.t. h(x) = h(x ) TCR is weaker than CR. If a hash function satisfies CR, it automatically satisfies TCR. There is no implication relationship between OW and CR/TCR. 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 3

41 Applications Password storage: Store h(pw), not PW on computer. When user inputs PW, compute h(pw ) and compare against h(pw). The property required of the hash function is OW. The adversary does not know PW or PW so TCR or CR is not really required. Of course, if many, many passwords have the same hash, it is a problem, but a small number of collisions doesn t really affect security. 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 4

42 Applications (cont.) File modification detector: For each file F, store h(f) securely. Check if F is modified by recomputing h(f). The property that is required is TCR, since the adversary wins if he/she is able to modify F without changing h(f). 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 5

43 Applications (cont.) Digital signatures: In public-key cryptography, Alice has a public key PK A and a private key SK A. Alice can sign a message M using her private key to produce σ = sign(sk A, M). Anyone who knows Alice s public key PK A and verify Alice s signature by checking that verify(m, σ, PK A ) is true. The adversary wants to forge a signature that verifies. For large M it is easier to sign h(m) rather than M, i.e., σ = sign(sk A, h(m)). The property that we require is CR. We don t want an adversary to ask Alice to sign x and then claim that she signed x, where h(x) = h(x ). 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 6

44 Implementations There have been many proposals for hash functions which are OW, CR and TCR. Some of these have been broken. MD-5, for example, has been shown to not be CR. There is a competition underway to determine SHA-3, which would be a Secure Hash Algorithm certified by NIST. Cryptographic hash functions are significantly more complex than those used in hash tables. You can think of a cryptographic hash as running a regular hash function many, many times with pseudo-random permutations interspersed. 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 7

45 Data Structures and Algorithms String Matching: KMP Google Camp Fall 2016 Yanqiao ZHU

46 Basic Requirements Given two strings s and t, does s occur as a substring of t? (and if so, where and how many times?) e.g. s = and t = your entire INBOX (grep on UNIX) 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 2

47 Simple Algorithm 1. any(s == t[i : i + len(s)]) 2. for i in range(len(t) len(s))) Analysis: O( s ) time for each substring comparison O( s ( t s )) time = O( s t ) potentially quadratic t s s 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 3

48 Knuth-Morris-Pratt Algorithm In the Brute-Force algorithm, if a mismatch occurs at pattern s[j] (j > 1), it only slides s to right by 1 step. It throws away one piece of information that we ve already known. Let u be the current shift value. Since it is a mismatch at s[j], we know s[u u + j 1] = s[1.. j 1] How can we make use of this information to make the next shift? In general, s should slide by u > u such that s[1.. k] = t[u u + k]. We then compare s[k + 1] with t[u + k + 1]. u + 1 u + j 1 t s u 1 j 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 4

49 Knuth-Morris-Pratt Algorithm (cont.) When we slide s to right, it should be a place where s could possibly occur in t t b a c b a b a b a a b c b a b s u a b a b a c a 1 q 1 q a b a b a s[1.. q] t b a c b a b a b a a b c b a b a b a s[1.. k] is a suffix of s[1.. q] 1 k s u a b a b a c a 1 k 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 5

50 The next Function Given s[1.. q] match text characters t[u u + q], what is the least shift u > u such that s[1.. k] = t[u u + k], where u + k = u + q? In practice, the shift u can be precomputed by comparing s against itself. Observe that t[u u + k] is a known text, and it is a suffix of s[1.. q]. To find the least shift u > u, it is the same as finding the largest k < q, s.t., s[1.. k] is a suffix of s[1.. q]. 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 6

51 Computing next Function Given next[1], next[2],, next[q], how can we compute next[q + 1]? 1. If s[q + 1] == s[next[q] + 1], then next[q + 1] = next[q] + 1. s s 1 q next[q] + 1 q 1 next[q] 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 7

52 Computing next Function (cont.) 2. If s[q + 1]!= s[next[q] + 1], then do what? s should slide to a place such that the prefix of [1.. next[q]] occurs as a suffix of [q next[q + 1].. q]; this information is stored in next[next[q]]. s s 1 q next[q] + 1 q 1 next[q] observe that s[1.. next[q]] = s[q next[q] q] s s 1 q next[q] + 1 q 1 next[next[q]] 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 8

53 Computing next Function (cont.) 3. We first set next[1] = 0, then compute next[q] with q = 2, 3,, m, one by one in m 1 iterations. 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 9

54 Computing next Function (cont.) Compute_Next(s) 1. m = s.length 2. next[1] = 0 // initialization 3. k = 0 // number of characters matched so far 4. for q = 2 to m do 5. while k > 0 and s[k + 1]!= s[q] do 6. k = next[k] 7. if s[k + 1] = s[q] then k = k next[q] = k 9. return next 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 10

55 The KMP Algorithm Given s[1.. m], let next be a function {1, 2,, m} {0, 1,, m 1} such that next(q) = max{k : k < q and s[1.. k] is a suffix of s[1.. q]} Given next(q) for all 1 q m, we can use the KMP algorithm. 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 11

56 The KMP Algorithm (cont.) KMP_StringMatcher(t, s) 1. n = t.length 2. m = s.length 3. next = Compute_Next(p) 4. q = 0 // number of characters matched 5. for i = 1 to n do // scan t from left to right 6. while q > 0 and s[q + 1]!= t[i] do 7. q = next[q] // next character does not match 8. if s[q + 1] = t[i] then 9. q = q + 1 // next character matches 10. if q = m then // is all of s matched? 11. print Pattern occurs with shift, i m 12. q = next[q] // look for the next match 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 12

57 The KMP Algorithm (cont.) q s[q] a b a b a b c next(q) t i = 3, q = 0 a b a b a k s a b a b a b c 1 5 q + 1 s a b a b a b c 1 3 q + 1 s a b a b a 1 q + 1 s a b a b q + 1 i = 8, q = 5; s[q + 1]!= t[i] (enters the while loop) q assigns to next[5] (=3) i = 8, q = 3; s[q + 1]!= t[i] (in the while loop) q assigns to next[3] (=1) i = 8, q = 1; s[q + 1]!= t[i] (in the while loop) q assigns to next[1] (=0) i = 8, q = 0 (exits the while loop) 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 13

58 Running Time The Compute_Next function: The for loop from line 4 to line 8 runs m times. Line 1 to line 3 take constant time. Hence the running time of compute next function is Θ(m). The KMP_StringMatcher function: The for loop beginning in line 5 runs n times, i.e., as long as the length of the string t. Since line 1 to line 4 take constant time, the running time is dominated by this for loop. Thus running time of matching function is Θ(n). 9/22/2016 Data Structures and Algorithms Google Camp Fall 2016 Yanqiao ZHU 14

END-TERM EXAMINATION

END-TERM EXAMINATION (Please Write your Exam Roll No. immediately) Exam. Roll No... END-TERM EXAMINATION Paper Code : MCA-205 DECEMBER 2006 Subject: Design and analysis of algorithm Time: 3 Hours Maximum Marks: 60 Note: Attempt

More information

Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest. Introduction to Algorithms

Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest. Introduction to Algorithms Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest Introduction to Algorithms Preface xiii 1 Introduction 1 1.1 Algorithms 1 1.2 Analyzing algorithms 6 1.3 Designing algorithms 1 1 1.4 Summary 1 6

More information

Department of Computer Applications. MCA 312: Design and Analysis of Algorithms. [Part I : Medium Answer Type Questions] UNIT I

Department of Computer Applications. MCA 312: Design and Analysis of Algorithms. [Part I : Medium Answer Type Questions] UNIT I MCA 312: Design and Analysis of Algorithms [Part I : Medium Answer Type Questions] UNIT I 1) What is an Algorithm? What is the need to study Algorithms? 2) Define: a) Time Efficiency b) Space Efficiency

More information

CS:3330 (22c:31) Algorithms

CS: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 information

Algorithms and Data Structures

Algorithms and Data Structures Algorithm Analysis Page 1 - Algorithm Analysis Dr. Fall 2008 Algorithm Analysis Page 2 Outline Textbook Overview Analysis of Algorithm Pseudo-Code and Primitive Operations Growth Rate and Big-Oh Notation

More information

PROGRAM EFFICIENCY & COMPLEXITY ANALYSIS

PROGRAM 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 information

Introduction to Algorithms Third Edition

Introduction to Algorithms Third Edition Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest Clifford Stein Introduction to Algorithms Third Edition The MIT Press Cambridge, Massachusetts London, England Preface xiü I Foundations Introduction

More information

Data Structures and Algorithms

Data Structures and Algorithms Berner Fachhochschule - Technik und Informatik Data Structures and Algorithms Topic 1: Algorithm Analysis Philipp Locher FS 2018 Outline Course and Textbook Overview Analysis of Algorithm Pseudo-Code and

More information

Virtual University of Pakistan

Virtual University of Pakistan Virtual University of Pakistan Department of Computer Science Course Outline Course Instructor Dr. Sohail Aslam E mail Course Code Course Title Credit Hours 3 Prerequisites Objectives Learning Outcomes

More information

CS 303 Design and Analysis of Algorithms

CS 303 Design and Analysis of Algorithms Mid-term CS 303 Design and Analysis of Algorithms Review For Midterm Dong Xu (Based on class note of David Luebke) 12:55-1:55pm, Friday, March 19 Close book Bring your calculator 30% of your final score

More information

DESIGN AND ANALYSIS OF ALGORITHMS

DESIGN AND ANALYSIS OF ALGORITHMS DESIGN AND ANALYSIS OF ALGORITHMS QUESTION BANK Module 1 OBJECTIVE: Algorithms play the central role in both the science and the practice of computing. There are compelling reasons to study algorithms.

More information

CSE 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 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 information

Data Structures and Algorithms. Course slides: String Matching, Algorithms growth evaluation

Data Structures and Algorithms. Course slides: String Matching, Algorithms growth evaluation Data Structures and Algorithms Course slides: String Matching, Algorithms growth evaluation String Matching Basic Idea: Given a pattern string P, of length M Given a text string, A, of length N Do all

More information

Table of Contents. Chapter 1: Introduction to Data Structures... 1

Table of Contents. Chapter 1: Introduction to Data Structures... 1 Table of Contents Chapter 1: Introduction to Data Structures... 1 1.1 Data Types in C++... 2 Integer Types... 2 Character Types... 3 Floating-point Types... 3 Variables Names... 4 1.2 Arrays... 4 Extraction

More information

University of Waterloo CS240R Fall 2017 Review Problems

University of Waterloo CS240R Fall 2017 Review Problems University of Waterloo CS240R Fall 2017 Review Problems Reminder: Final on Tuesday, December 12 2017 Note: This is a sample of problems designed to help prepare for the final exam. These problems do not

More information

Introduction to Data Structure

Introduction 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 information

Algorithm Analysis. (Algorithm Analysis ) Data Structures and Programming Spring / 48

Algorithm 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 information

Module 1: Asymptotic Time Complexity and Intro to Abstract Data Types

Module 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 information

Algorithm Analysis. Part I. Tyler Moore. Lecture 3. CSE 3353, SMU, Dallas, TX

Algorithm Analysis. Part I. Tyler Moore. Lecture 3. CSE 3353, SMU, Dallas, TX Algorithm Analysis Part I Tyler Moore CSE 5, SMU, Dallas, TX Lecture how many times do you have to turn the crank? Some slides created by or adapted from Dr. Kevin Wayne. For more information see http://www.cs.princeton.edu/~wayne/kleinberg-tardos.

More information

Algorithms: Design & Practice

Algorithms: Design & Practice Algorithms: Design & Practice Deepak Kumar Bryn Mawr College Spring 2018 Course Essentials Algorithms Design & Practice How to design Learn some good ones How to implement practical considerations How

More information

String Matching. Pedro Ribeiro 2016/2017 DCC/FCUP. Pedro Ribeiro (DCC/FCUP) String Matching 2016/ / 42

String Matching. Pedro Ribeiro 2016/2017 DCC/FCUP. Pedro Ribeiro (DCC/FCUP) String Matching 2016/ / 42 String Matching Pedro Ribeiro DCC/FCUP 2016/2017 Pedro Ribeiro (DCC/FCUP) String Matching 2016/2017 1 / 42 On this lecture The String Matching Problem Naive Algorithm Deterministic Finite Automata Knuth-Morris-Pratt

More information

ASSIGNMENTS. Progra m Outcom e. Chapter Q. No. Outcom e (CO) I 1 If f(n) = Θ(g(n)) and g(n)= Θ(h(n)), then proof that h(n) = Θ(f(n))

ASSIGNMENTS. Progra m Outcom e. Chapter Q. No. Outcom e (CO) I 1 If f(n) = Θ(g(n)) and g(n)= Θ(h(n)), then proof that h(n) = Θ(f(n)) ASSIGNMENTS Chapter Q. No. Questions Course Outcom e (CO) Progra m Outcom e I 1 If f(n) = Θ(g(n)) and g(n)= Θ(h(n)), then proof that h(n) = Θ(f(n)) 2 3. What is the time complexity of the algorithm? 4

More information

Quiz 1 Solutions. Asymptotic growth [10 points] For each pair of functions f(n) and g(n) given below:

Quiz 1 Solutions. Asymptotic growth [10 points] For each pair of functions f(n) and g(n) given below: Introduction to Algorithms October 15, 2008 Massachusetts Institute of Technology 6.006 Fall 2008 Professors Ronald L. Rivest and Sivan Toledo Quiz 1 Solutions Problem 1. Asymptotic growth [10 points]

More information

9. Which situation is true regarding a cascading cut that produces c trees for a Fibonacci heap?

9. Which situation is true regarding a cascading cut that produces c trees for a Fibonacci heap? 1 1 Name Test 1 - Closed Book Student ID # Multiple Choice. Write your answer to the LEFT of each problem. points each 1. During which operation on a leftist heap may subtree swaps be needed? A. DECREASE-KEY

More information

Sankalchand Patel College of Engineering - Visnagar Department of Computer Engineering and Information Technology. Assignment

Sankalchand Patel College of Engineering - Visnagar Department of Computer Engineering and Information Technology. Assignment Class: V - CE Sankalchand Patel College of Engineering - Visnagar Department of Computer Engineering and Information Technology Sub: Design and Analysis of Algorithms Analysis of Algorithm: Assignment

More information

( ) + n. ( ) = n "1) + n. ( ) = T n 2. ( ) = 2T n 2. ( ) = T( n 2 ) +1

( ) + n. ( ) = n 1) + n. ( ) = T n 2. ( ) = 2T n 2. ( ) = T( n 2 ) +1 CSE 0 Name Test Summer 00 Last Digits of Student ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. Suppose you are sorting millions of keys that consist of three decimal

More information

Practice Midterm Exam Solutions

Practice Midterm Exam Solutions CSE 332: Data Abstractions Autumn 2015 Practice Midterm Exam Solutions Name: Sample Solutions ID #: 1234567 TA: The Best Section: A9 INSTRUCTIONS: You have 50 minutes to complete the exam. The exam is

More information

CS161 - Final Exam Computer Science Department, Stanford University August 16, 2008

CS161 - Final Exam Computer Science Department, Stanford University August 16, 2008 CS161 - Final Exam Computer Science Department, Stanford University August 16, 2008 Name: Honor Code 1. The Honor Code is an undertaking of the students, individually and collectively: a) that they will

More information

SORTING. Practical applications in computing require things to be in order. To consider: Runtime. Memory Space. Stability. In-place algorithms???

SORTING. Practical applications in computing require things to be in order. To consider: Runtime. Memory Space. Stability. In-place algorithms??? SORTING + STRING COMP 321 McGill University These slides are mainly compiled from the following resources. - Professor Jaehyun Park slides CS 97SI - Top-coder tutorials. - Programming Challenges book.

More information

[ 11.2, 11.3, 11.4] Analysis of Algorithms. Complexity of Algorithms. 400 lecture note # Overview

[ 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 information

Data Structures Lecture 8

Data Structures Lecture 8 Fall 2017 Fang Yu Software Security Lab. Dept. Management Information Systems, National Chengchi University Data Structures Lecture 8 Recap What should you have learned? Basic java programming skills Object-oriented

More information

Algorithms in Systems Engineering IE172. Midterm Review. Dr. Ted Ralphs

Algorithms in Systems Engineering IE172. Midterm Review. Dr. Ted Ralphs Algorithms in Systems Engineering IE172 Midterm Review Dr. Ted Ralphs IE172 Midterm Review 1 Textbook Sections Covered on Midterm Chapters 1-5 IE172 Review: Algorithms and Programming 2 Introduction to

More information

( ) n 5. Test 1 - Closed Book

( ) n 5. Test 1 - Closed Book Name Test 1 - Closed Book Student ID # Multiple Choice. Write your answer to the LEFT of each problem. points each 1. During which operation on a leftist heap may subtree swaps be needed? A. DECREASE-KEY

More information

DATA STRUCTURES AND ALGORITHMS

DATA STRUCTURES AND ALGORITHMS DATA STRUCTURES AND ALGORITHMS For COMPUTER SCIENCE DATA STRUCTURES &. ALGORITHMS SYLLABUS Programming and Data Structures: Programming in C. Recursion. Arrays, stacks, queues, linked lists, trees, binary

More information

Data Structures Question Bank Multiple Choice

Data Structures Question Bank Multiple Choice Section 1. Fundamentals: Complexity, Algorthm Analysis 1. An algorithm solves A single problem or function Multiple problems or functions Has a single programming language implementation 2. A solution

More information

Quiz 1 Solutions. (a) f(n) = n g(n) = log n Circle all that apply: f = O(g) f = Θ(g) f = Ω(g)

Quiz 1 Solutions. (a) f(n) = n g(n) = log n Circle all that apply: f = O(g) f = Θ(g) f = Ω(g) Introduction to Algorithms March 11, 2009 Massachusetts Institute of Technology 6.006 Spring 2009 Professors Sivan Toledo and Alan Edelman Quiz 1 Solutions Problem 1. Quiz 1 Solutions Asymptotic orders

More information

Indexing and Searching

Indexing and Searching Indexing and Searching Introduction How to retrieval information? A simple alternative is to search the whole text sequentially Another option is to build data structures over the text (called indices)

More information

logn D. Θ C. Θ n 2 ( ) ( ) f n B. nlogn Ο n2 n 2 D. Ο & % ( C. Θ # ( D. Θ n ( ) Ω f ( n)

logn D. Θ C. Θ n 2 ( ) ( ) f n B. nlogn Ο n2 n 2 D. Ο & % ( C. Θ # ( D. Θ n ( ) Ω f ( n) CSE 0 Test Your name as it appears on your UTA ID Card Fall 0 Multiple Choice:. Write the letter of your answer on the line ) to the LEFT of each problem.. CIRCLED ANSWERS DO NOT COUNT.. points each. The

More information

asymptotic growth rate or order compare two functions, but ignore constant factors, small inputs

asymptotic growth rate or order compare two functions, but ignore constant factors, small inputs Big-Oh 1 asymptotic growth rate or order 2 compare two functions, but ignore constant factors, small inputs asymptotic growth rate or order 2 compare two functions, but ignore constant factors, small inputs

More information

ECE250: Algorithms and Data Structures Final Review Course

ECE250: Algorithms and Data Structures Final Review Course ECE250: Algorithms and Data Structures Final Review Course Ladan Tahvildari, PEng, SMIEEE Professor Software Technologies Applied Research (STAR) Group Dept. of Elect. & Comp. Eng. University of Waterloo

More information

Plotting run-time graphically. Plotting run-time graphically. CS241 Algorithmics - week 1 review. Prefix Averages - Algorithm #1

Plotting 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 information

9. The expected time for insertion sort for n keys is in which set? (All n! input permutations are equally likely.)

9. The expected time for insertion sort for n keys is in which set? (All n! input permutations are equally likely.) CSE 0 Name Test Spring 006 Last 4 Digits of Student ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. Suppose f ( x) is a monotonically increasing function. Which of the

More information

Chapter 2: Complexity Analysis

Chapter 2: Complexity Analysis Chapter 2: Complexity Analysis Objectives Looking ahead in this chapter, we ll consider: Computational and Asymptotic Complexity Big-O Notation Properties of the Big-O Notation Ω and Θ Notations Possible

More information

CS521 \ Notes for the Final Exam

CS521 \ Notes for the Final Exam CS521 \ Notes for final exam 1 Ariel Stolerman Asymptotic Notations: CS521 \ Notes for the Final Exam Notation Definition Limit Big-O ( ) Small-o ( ) Big- ( ) Small- ( ) Big- ( ) Notes: ( ) ( ) ( ) ( )

More information

Comparison Based Sorting Algorithms. Algorithms and Data Structures: Lower Bounds for Sorting. Comparison Based Sorting Algorithms

Comparison Based Sorting Algorithms. Algorithms and Data Structures: Lower Bounds for Sorting. Comparison Based Sorting Algorithms Comparison Based Sorting Algorithms Algorithms and Data Structures: Lower Bounds for Sorting Definition 1 A sorting algorithm is comparison based if comparisons A[i] < A[j], A[i] A[j], A[i] = A[j], A[i]

More information

Lecture 7 February 26, 2010

Lecture 7 February 26, 2010 6.85: Advanced Data Structures Spring Prof. Andre Schulz Lecture 7 February 6, Scribe: Mark Chen Overview In this lecture, we consider the string matching problem - finding all places in a text where some

More information

How much space does this routine use in the worst case for a given n? public static void use_space(int n) { int b; int [] A;

How much space does this routine use in the worst case for a given n? public static void use_space(int n) { int b; int [] A; How much space does this routine use in the worst case for a given n? public static void use_space(int n) { int b; int [] A; } if (n

More information

( ) 1 B. 1. Suppose f x

( ) 1 B. 1. Suppose f x CSE Name Test Spring Last Digits of Student ID Multiple Choice. Write your answer to the LEFT of each problem. points each is a monotonically increasing function. Which of the following approximates the

More information

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Sorting lower bound and Linear-time sorting Date: 9/19/17

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Sorting lower bound and Linear-time sorting Date: 9/19/17 601.433/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Sorting lower bound and Linear-time sorting Date: 9/19/17 5.1 Introduction You should all know a few ways of sorting in O(n log n)

More information

Data Structures and Algorithms CSE 465

Data 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 information

( D. Θ n. ( ) f n ( ) D. Ο%

( D. Θ n. ( ) f n ( ) D. Ο% CSE 0 Name Test Spring 0 Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to run the code below is in: for i=n; i>=; i--) for j=; j

More information

( ). Which of ( ) ( ) " #& ( ) " # g( n) ( ) " # f ( n) Test 1

( ). Which of ( ) ( )  #& ( )  # g( n) ( )  # f ( n) Test 1 CSE 0 Name Test Summer 006 Last Digits of Student ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to multiply two n x n matrices is: A. "( n) B. "( nlogn) # C.

More information

CSE 373 APRIL 3 RD ALGORITHM ANALYSIS

CSE 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 information

Algorithms and Data Structures: Lower Bounds for Sorting. ADS: lect 7 slide 1

Algorithms and Data Structures: Lower Bounds for Sorting. ADS: lect 7 slide 1 Algorithms and Data Structures: Lower Bounds for Sorting ADS: lect 7 slide 1 ADS: lect 7 slide 2 Comparison Based Sorting Algorithms Definition 1 A sorting algorithm is comparison based if comparisons

More information

DATA STRUCTURES AND ALGORITHMS

DATA STRUCTURES AND ALGORITHMS DATA STRUCTURES AND ALGORITHMS UNIT 1 - LINEAR DATASTRUCTURES 1. Write down the definition of data structures? A data structure is a mathematical or logical way of organizing data in the memory that consider

More information

Overview of Data. 1. Array 2. Linked List 3. Stack 4. Queue

Overview of Data. 1. Array 2. Linked List 3. Stack 4. Queue Overview of Data A data structure is a particular way of organizing data in a computer so that it can be used effectively. The idea is to reduce the space and time complexities of different tasks. Below

More information

String Matching Algorithms

String Matching Algorithms String Matching Algorithms Georgy Gimel farb (with basic contributions from M. J. Dinneen, Wikipedia, and web materials by Ch. Charras and Thierry Lecroq, Russ Cox, David Eppstein, etc.) COMPSCI 369 Computational

More information

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators)

CSE 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 information

Algorithm. Algorithm Analysis. Algorithm. Algorithm. Analyzing Sorting Algorithms (Insertion Sort) Analyzing Algorithms 8/31/2017

Algorithm. Algorithm Analysis. Algorithm. Algorithm. Analyzing Sorting Algorithms (Insertion Sort) Analyzing Algorithms 8/31/2017 8/3/07 Analysis Introduction to Analysis Model of Analysis Mathematical Preliminaries for Analysis Set Notation Asymptotic Analysis What is an algorithm? An algorithm is any well-defined computational

More information

How many leaves on the decision tree? There are n! leaves, because every permutation appears at least once.

How many leaves on the decision tree? There are n! leaves, because every permutation appears at least once. Chapter 8. Sorting in Linear Time Types of Sort Algorithms The only operation that may be used to gain order information about a sequence is comparison of pairs of elements. Quick Sort -- comparison-based

More information

n 2 C. Θ n ( ) Ο f ( n) B. n 2 Ω( n logn)

n 2 C. Θ n ( ) Ο f ( n) B. n 2 Ω( n logn) CSE 0 Name Test Fall 0 Last Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to find the maximum of the n elements of an integer array is in: A.

More information

L.J. Institute of Engineering & Technology Semester: VIII (2016)

L.J. Institute of Engineering & Technology Semester: VIII (2016) Subject Name: Design & Analysis of Algorithm Subject Code:1810 Faculties: Mitesh Thakkar Sr. UNIT-1 Basics of Algorithms and Mathematics No 1 What is an algorithm? What do you mean by correct algorithm?

More information

n 2 ( ) ( ) + n is in Θ n logn

n 2 ( ) ( ) + n is in Θ n logn CSE Test Spring Name Last Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to multiply an m n matrix and a n p matrix is in: A. Θ( n) B. Θ( max(

More information

CSE 332 Winter 2015: Midterm Exam (closed book, closed notes, no calculators)

CSE 332 Winter 2015: Midterm Exam (closed book, closed notes, no calculators) _ UWNetID: Lecture Section: A CSE 332 Winter 2015: Midterm Exam (closed book, closed notes, no calculators) Instructions: Read the directions for each question carefully before answering. We will give

More information

Another Sorting Algorithm

Another Sorting Algorithm 1 Another Sorting Algorithm What was the running time of insertion sort? Can we do better? 2 Designing Algorithms Many ways to design an algorithm: o Incremental: o Divide and Conquer: 3 Divide and Conquer

More information

Test 1 - Closed Book Last 4 Digits of Student ID # Multiple Choice. Write your answer to the LEFT of each problem. 3 points each

Test 1 - Closed Book Last 4 Digits of Student ID # Multiple Choice. Write your answer to the LEFT of each problem. 3 points each CSE 5311 Test 1 - Closed Book Summer 2009 Name Last 4 Digits of Student ID # Multiple Choice. Write your answer to the LEFT of each problem. 3 points each 1. Which of the following statements is true?

More information

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 The data of the problem is of 2GB and the hard disk is of 1GB capacity, to solve this problem we should Use better data structures

More information

Quiz 1 Practice Problems

Quiz 1 Practice Problems Introduction to Algorithms: 6.006 Massachusetts Institute of Technology March 7, 2008 Professors Srini Devadas and Erik Demaine Handout 6 1 Asymptotic Notation Quiz 1 Practice Problems Decide whether these

More information

Algorithms and Data Structures

Algorithms 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 information

String Matching Algorithms

String Matching Algorithms String Matching Algorithms 1. Naïve String Matching The naïve approach simply test all the possible placement of Pattern P[1.. m] relative to text T[1.. n]. Specifically, we try shift s = 0, 1,..., n -

More information

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi.

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi. Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture 18 Tries Today we are going to be talking about another data

More information

Lecture 5 Sorting Arrays

Lecture 5 Sorting Arrays Lecture 5 Sorting Arrays 15-122: Principles of Imperative Computation (Spring 2018) Frank Pfenning, Rob Simmons We begin this lecture by discussing how to compare running times of functions in an abstract,

More information

Overview. CSE 101: Design and Analysis of Algorithms Lecture 1

Overview. CSE 101: Design and Analysis of Algorithms Lecture 1 Overview CSE 101: Design and Analysis of Algorithms Lecture 1 CSE 101: Design and analysis of algorithms Course overview Logistics CSE 101, Fall 2018 2 First, relevant prerequisites Advanced Data Structures

More information

Final Exam in Algorithms and Data Structures 1 (1DL210)

Final Exam in Algorithms and Data Structures 1 (1DL210) Final Exam in Algorithms and Data Structures 1 (1DL210) Department of Information Technology Uppsala University February 0th, 2012 Lecturers: Parosh Aziz Abdulla, Jonathan Cederberg and Jari Stenman Location:

More information

Midterm solutions. n f 3 (n) = 3

Midterm solutions. n f 3 (n) = 3 Introduction to Computer Science 1, SE361 DGIST April 20, 2016 Professors Min-Soo Kim and Taesup Moon Midterm solutions Midterm solutions The midterm is a 1.5 hour exam (4:30pm 6:00pm). This is a closed

More information

Why study algorithms? CS 561, Lecture 1. Today s Outline. Why study algorithms? (II)

Why study algorithms? CS 561, Lecture 1. Today s Outline. Why study algorithms? (II) Why study algorithms? CS 561, Lecture 1 Jared Saia University of New Mexico Seven years of College down the toilet - John Belushi in Animal House Q: Can I get a programming job without knowing something

More information

) $ f ( n) " %( g( n)

) $ f ( n)  %( g( n) CSE 0 Name Test Spring 008 Last Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to compute the sum of the n elements of an integer array is: # A.

More information

CS302 Topic: Algorithm Analysis. Thursday, Sept. 22, 2005

CS302 Topic: Algorithm Analysis. Thursday, Sept. 22, 2005 CS302 Topic: Algorithm Analysis Thursday, Sept. 22, 2005 Announcements Lab 3 (Stock Charts with graphical objects) is due this Friday, Sept. 23!! Lab 4 now available (Stock Reports); due Friday, Oct. 7

More information

CSE373: 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 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 information

CS 360 Exam 1 Fall 2014 Name. 1. Answer the following questions about each code fragment below. [8 points]

CS 360 Exam 1 Fall 2014 Name. 1. Answer the following questions about each code fragment below. [8 points] CS 360 Exam 1 Fall 2014 Name 1. Answer the following questions about each code fragment below. [8 points] for (v=1; v

More information

Computer Science 210 Data Structures Siena College Fall Topic Notes: Complexity and Asymptotic Analysis

Computer Science 210 Data Structures Siena College Fall Topic Notes: Complexity and Asymptotic Analysis Computer Science 210 Data Structures Siena College Fall 2017 Topic Notes: Complexity and Asymptotic Analysis Consider the abstract data type, the Vector or ArrayList. This structure affords us the opportunity

More information

University of Waterloo CS240R Winter 2018 Help Session Problems

University of Waterloo CS240R Winter 2018 Help Session Problems University of Waterloo CS240R Winter 2018 Help Session Problems Reminder: Final on Monday, April 23 2018 Note: This is a sample of problems designed to help prepare for the final exam. These problems do

More information

Asymptotic Analysis Spring 2018 Discussion 7: February 27, 2018

Asymptotic 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 information

Multiple Choice. Write your answer to the LEFT of each problem. 3 points each

Multiple Choice. Write your answer to the LEFT of each problem. 3 points each CSE 0-00 Test Spring 0 Name Last 4 Digits of Student ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. Suppose f ( x) is a monotonically increasing function. Which of the

More information

COMP Data Structures

COMP 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 information

Theory and Algorithms Introduction: insertion sort, merge sort

Theory and Algorithms Introduction: insertion sort, merge sort Theory and Algorithms Introduction: insertion sort, merge sort Rafael Ramirez rafael@iua.upf.es Analysis of algorithms The theoretical study of computer-program performance and resource usage. What s also

More information

CSci 231 Final Review

CSci 231 Final Review CSci 231 Final Review Here is a list of topics for the final. Generally you are responsible for anything discussed in class (except topics that appear italicized), and anything appearing on the homeworks.

More information

CSE 332 Spring 2014: Midterm Exam (closed book, closed notes, no calculators)

CSE 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 information

Course Review for Finals. Cpt S 223 Fall 2008

Course Review for Finals. Cpt S 223 Fall 2008 Course Review for Finals Cpt S 223 Fall 2008 1 Course Overview Introduction to advanced data structures Algorithmic asymptotic analysis Programming data structures Program design based on performance i.e.,

More information

( ) D. Θ ( ) ( ) Ο f ( n) ( ) Ω. C. T n C. Θ. B. n logn Ο

( ) D. Θ ( ) ( ) Ο f ( n) ( ) Ω. C. T n C. Θ. B. n logn Ο CSE 0 Name Test Fall 0 Multiple Choice. Write your answer to the LEFT of each problem. points each. The expected time for insertion sort for n keys is in which set? (All n! input permutations are equally

More information

CSC263 Week 12. Larry Zhang

CSC263 Week 12. Larry Zhang CSC263 Week 12 Larry Zhang Announcements No tutorial this week PS5-8 being marked Course evaluation: available on Portal http://uoft.me/course-evals Lower Bounds So far, we have mostly talked about upperbounds

More information

Priority Queues. Chapter 9

Priority Queues. Chapter 9 Chapter 9 Priority Queues Sometimes, we need to line up things according to their priorities. Order of deletion from such a structure is determined by the priority of the elements. For example, when assigning

More information

Data structure and algorithm in Python

Data structure and algorithm in Python Data structure and algorithm in Python Algorithm Analysis Xiaoping Zhang School of Mathematics and Statistics, Wuhan University Table of contents 1. Experimental studies 2. The Seven Functions used in

More information

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)

CSE 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 information

Data Structures and Algorithms (DSA) Course 13 Algorithms

Data Structures and Algorithms (DSA) Course 13 Algorithms Data Structures and Algorithms (DSA) Course 13 Algorithms Iulian Năstac Special binary trees (Recapitulation) P: A binary tree with the height i could have a maximum number of 2 i+1-1 nodes. Notes: A level

More information

Treaps. 1 Binary Search Trees (BSTs) CSE341T/CSE549T 11/05/2014. Lecture 19

Treaps. 1 Binary Search Trees (BSTs) CSE341T/CSE549T 11/05/2014. Lecture 19 CSE34T/CSE549T /05/04 Lecture 9 Treaps Binary Search Trees (BSTs) Search trees are tree-based data structures that can be used to store and search for items that satisfy a total order. There are many types

More information

Introduction to the Analysis of Algorithms. Algorithm

Introduction to the Analysis of Algorithms. Algorithm Introduction to the Analysis of Algorithms Based on the notes from David Fernandez-Baca Bryn Mawr College CS206 Intro to Data Structures Algorithm An algorithm is a strategy (well-defined computational

More information

CSE 100 Advanced Data Structures

CSE 100 Advanced Data Structures CSE 100 Advanced Data Structures Overview of course requirements Outline of CSE 100 topics Review of trees Helpful hints for team programming Information about computer accounts Page 1 of 25 CSE 100 web

More information

CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics

CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics 1 Sorting 1.1 Problem Statement You are given a sequence of n numbers < a 1, a 2,..., a n >. You need to

More information

Module 2: Classical Algorithm Design Techniques

Module 2: Classical Algorithm Design Techniques Module 2: Classical Algorithm Design Techniques Dr. Natarajan Meghanathan Associate Professor of Computer Science Jackson State University Jackson, MS 39217 E-mail: natarajan.meghanathan@jsums.edu Module

More information