ECE250: Algorithms and Data Structures Midterm Review

Similar documents
University of Waterloo Department of Electrical and Computer Engineering ECE250 Algorithms and Data Structures Fall 2014

University of Waterloo Department of Electrical and Computer Engineering ECE250 Algorithms and Data Structures Fall 2017

ECE250: Algorithms and Data Structures Final Review Course

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

Course Review for. Cpt S 223 Fall Cpt S 223. School of EECS, WSU

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

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

Course Review. Cpt S 223 Fall 2009

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

CS301 - Data Structures Glossary By

Cpt S 223 Fall Cpt S 223. School of EECS, WSU

Course Review for Finals. Cpt S 223 Fall 2008

INSTITUTE OF AERONAUTICAL ENGINEERING

Introduction to Data Structure

ECE250: Algorithms and Data Structures AVL Trees (Part A)

1. Attempt any three of the following: 15

CPSC 331 Term Test #2 March 26, 2007

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))

Midterm solutions. n f 3 (n) = 3

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

ECE250: Algorithms and Data Structures Binary Search Trees (Part A)

Data Structures Question Bank Multiple Choice

Course Review. Cpt S 223 Fall 2010

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)

Course goals. exposure to another language. knowledge of specific data structures. impact of DS design & implementation on program performance

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

APJ ABDUL KALAM TECHNOLOGICAL UNIVERSITY THIRD SEMESTER B.TECH DEGREE EXAMINATION, JULY 2017 CS205: DATA STRUCTURES (CS, IT)

CSE 373 Autumn 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING ECE ALGORITHMS AND DATA STRUCTURES Total:

ECE242 Data Structures and Algorithms Fall 2008

CS171 Midterm Exam. October 29, Name:

CS61B Spring 2016 Guerrilla Section 3 Worksheet. 12 March 2016

Basic Data Structures (Version 7) Name:

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1

UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING E&CE 250 ALGORITHMS AND DATA STRUCTURES

Section 05: Solutions

CSE 373 Winter 2009: Midterm #1 (closed book, closed notes, NO calculators allowed)

Section 05: Midterm Review

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

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

MLR Institute of Technology

CSE 373 Spring Midterm. Friday April 21st

UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING ECE 250 ALGORITHMS AND DATA STRUCTURES

CSE 373 APRIL 17 TH TREE BALANCE AND AVL

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

DDS Dynamic Search Trees

Name CPTR246 Spring '17 (100 total points) Exam 3

UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING ECE 250 ALGORITHMS AND DATA STRUCTURES

Assume you are given a Simple Linked List (i.e. not a doubly linked list) containing an even number of elements. For example L = [A B C D E F].

Practice Midterm Exam Solutions

Module 2: Classical Algorithm Design Techniques

CSE 332, Spring 2010, Midterm Examination 30 April 2010

Revision Statement while return growth rate asymptotic notation complexity Compare algorithms Linear search Binary search Preconditions: sorted,

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

COMP 250 Midterm #2 March 11 th 2013

CS251-SE1. Midterm 2. Tuesday 11/1 8:00pm 9:00pm. There are 16 multiple-choice questions and 6 essay questions.

Summer Final Exam Review Session August 5, 2009

Friday Four Square! 4:15PM, Outside Gates

BRONX COMMUNITY COLLEGE of the City University of New York DEPARTMENT OF MATHEMATICS AND COMPUTER SCIENCE. Sample Final Exam

CS61BL. Lecture 3: Asymptotic Analysis Trees & Tree Traversals Stacks and Queues Binary Search Trees (and other trees)

12 Abstract Data Types

Section 05: Solutions

Matriculation number:

CSE wi: Practice Midterm

Data Structures and Algorithms

Theory and Algorithms Introduction: insertion sort, merge sort

CLO Assessment CLO1 Q1(10) CLO2 Q2 (10) CLO3 Q4 (10) CLO4 Q3a (4)

CMSC351 - Fall 2014, Homework #2

UNIVERSITY REGULATIONS

We don t have much time, so we don t teach them [students]; we acquaint them with things that they can learn. Charles E. Leiserson

CS 216 Exam 1 Fall SOLUTION

(D) There is a constant value n 0 1 such that B is faster than A for every input of size. n n 0.

CS134 Spring 2005 Final Exam Mon. June. 20, 2005 Signature: Question # Out Of Marks Marker Total

CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

Data Structure and Algorithm, Spring 2013 Midterm Examination 120 points Time: 2:20pm-5:20pm (180 minutes), Tuesday, April 16, 2013

CSE373 Fall 2013, Midterm Examination October 18, 2013

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

UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING E&CE 250 ALGORITHMS AND DATA STRUCTURES

End-Term Examination Second Semester [MCA] MAY-JUNE 2006

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

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

COMP Analysis of Algorithms & Data Structures

The questions will be short answer, similar to the problems you have done on the homework

CSL 201 Data Structures Mid-Semester Exam minutes

Quiz 1 Practice Problems

Introduction to Algorithms 6.046J/18.401J/SMA5503

INF2220: algorithms and data structures Series 1

CS 303 Design and Analysis of Algorithms

CSE373: Data Structures & Algorithms Lecture 5: Dictionary ADTs; Binary Trees. Linda Shapiro Spring 2016

D. Θ nlogn ( ) D. Ο. ). Which of the following is not necessarily true? . Which of the following cannot be shown as an improvement? D.

CSE373: Data Structures & Algorithms Lecture 28: Final review and class wrap-up. Nicki Dell Spring 2014

17 February Given an algorithm, compute its running time in terms of O, Ω, and Θ (if any). Usually the big-oh running time is enough.

University of Toronto Department of Electrical and Computer Engineering. Midterm Examination. ECE 345 Algorithms and Data Structures Fall 2012

CS 251, LE 2 Fall MIDTERM 2 Tuesday, November 1, 2016 Version 00 - KEY

Recitation 9. Prelim Review

Lecture 6: Analysis of Algorithms (CS )

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge

21# 33# 90# 91# 34# # 39# # # 31# 98# 0# 1# 2# 3# 4# 5# 6# 7# 8# 9# 10# #

CS 61B Spring 2017 Guerrilla Section 4 Worksheet. 11 March 2017

CS 3114 Data Structures and Algorithms READ THIS NOW!

Transcription:

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

Materials from CLRS/Weiss Chapter CLRS 2 CLRS 3, A.1 CLRS 4 CLRS 10 CLRS 11 CLRS 12, B.5 CLRS 18.1, 18.2 Weiss 4 Topics Algorithmic problems, insertion sort, merge sort Asymptotic notation, useful math Recurrences Arrays, lists, stacks, queues Hashing Binary Search Trees (BST) B-Trees (Search and Insertion) AVL Trees Lecture 16 ECE250 2

Running Time - Kinds of Analyses v Worst-case: (usually) Ø T(n): maximum time of algorithm on any input of size n. v Average-case: (sometimes) Ø T(n): expected time of algorithm over all inputs of size n. Need assumption of statistical distribution of inputs. v Best-case: (NEVER) Ø Cheat with a slow algorithm that works fast on some input. Lecture 16 ECE250 3

Ο Notation Ο(g(n)) = { f (n) : there exist positive constants c and n 0 such that 0 f (n) cg(n) for all n n 0 } Example: 2n 2 = Ο( n with c 3 ) = 1, n 0 = 2 g(n) is an asymptotic upper bound for f(n) Lecture 16 ECE250 4

Ω Notation Ω (g(n)) = { f (n) : there exist positive constants c and n 0 such that 0 cg(n) f (n) for all n n 0 } Example: n = Ω(log n) with c = 1, n 0 = 16 Lecture 16 ECE250 5

Θ Notation Θ(g(n)) = { f (n) : there exist positive constants c 1, c 2, and n 0 such that 0 c 1 g(n) f (n) c 2 g(n) for all n n 0 } Example: 1 2 n 3n 2 with = Θ( n Lecture 16 ECE250 6 c 1 = 1 14, c 2 2 ) = 1 2, n g(n) is an asymptotic tight bound for f(n) 0 = 7

Methods for Solving Recurrences v Master Method Ø Running time dominated by cost at leaves Ø Running time evenly distributed throughout the tree Ø Running time dominated by cost at the root In each case compare f( n) with v Repeated Substitution v Recursion-Tree Method On logb a ( ) Lecture 16 ECE250 7

Elementary Data Structures v A stack is a container of objects that are inserted and removed according to the last-in-first-out (LIFO) principle. Ø Push (S:Stack, x:element) - Inserts o onto top of S Ø Pop (S:Stack) - Removes the top object of stack S v A queue differs from a stack in that its insertion and removal routines follows the first-in-first-out (FIFO) principle. Ø Elements are inserted at the rear (Enqueued) Ø Elements are removed from the front (Dequeued) Lecture 16 ECE250 8

Hashing v Collision Resolution Ø Chaining Ø Open Addressing Linear Probing Double Hashing v Hash Functions Ø Division Method: h(k) = k mod m Ø Multiplication Method: h(k) = m (k A mod 1) Lecture 16 ECE250 9

Trees v Binary Search Trees (BST) Ø Tree Walks: Preorder, Inorder, Postorder Ø Search, Insert, Delete (three cases) Ø Min, Max, Successor, Predecessor v AVL Trees Ø Single/Double Rotations and their effects Ø Insertion (four cases), Deletion (three cases) v B-Trees Ø Searching (simple), Creating an empty tree (trivial) Ø Splitting nodes and insertion keys Lecture 16 ECE250 10

Preparation for the Exam v First, concentrate on the lecture notes v Second, studying the CLRS/Weiss books wherever are needed (although you have to know the concepts!) v Third, solving exercises by yourself Ø When solving write your solutions down! Lecture 16 ECE250 11

More Materials (46 Questions) v Study all solved exercises in the tutorials/lectures (11) http://www.stargroup.uwaterloo.ca/~ece250/materials/ v Study solutions for the first assignment (5) http://www.stargroup.uwaterloo.ca/~ece250/assignments/ v ECE250 Previous Midterms (21) http://www.stargroup.uwaterloo.ca/~ece250/exams/ v Study solutions for sample questions (9) http://www.stargroup.uwaterloo.ca/~ece250/materials/lecture17-samplequestions.pdf Lecture 16 ECE250 12

Office Hours (October 16-25; 15 hours) Mon Oct. 16 Tue Oct. 17 Wed Oct. 18 Thu Oct. 19 Mon Oct. 23 Tue Oct. 24 Wed Oct. 25 Mahsa 12:30-1:30 DC-3574 Ladan 12:30-1:30 EIT-4136 Mahsa 5:30-6:30 DC-3574 Jun 12:30-1:30 DC-3574 Mahsa 10-11 DC-3574 Jun 11-12 DC-3574 Ladan 10-11 EIT-4136 Jun 5:30-6:30 DC-3574 Jun 5:30-6:30 DC-3574 Ladan 5:30-6:30 EIT-4136 Mahsa 1-2 DC-3574 Jun 1-2 DC-3574 Ladan 11-12 EIT-4136 Mahsa 2-3 DC-3574 Ladan 3-4 EIT-4136 ECE250 Fall 2017

ECE250 Midterm Exam v Date: Wednesday, October 25, 2017 v Time: 8:45pm-10:00pm v Locations: Ø RCH 301 Student ID from 20446508 to 20660661 Ø RCH 302 Student ID from 20660914 to 20750989 NOTE: Standard calculator allowed but no additional materials allowed. Lecture 16 ECE250 14

Potential Structure for Midterm v Four questions with two/three sub-problems 1. Algorithm Analysis (~30 marks) (CLRS 2, 3, 4, A.1) 2. Linked Lists, Stacks, and Queues ( ~20 marks) (CLRS 10) 3. Trees and Tree Traversals (~30 marks) (CLRS 12, 18.1, 18.2, B.5; Weiss 4) 4. Hashing (~20 marks) (CLRS 11) Lecture 16 ECE250 15

Sample Questions

Question 1 - Algorithm Analysis v Consider the sorting algorithm given below. This algorithm is designed to sort an array of integers, a[ 0], a[1],..., a[ n 1] where n is assumed to be a power of two. 1. void Merge (int a[], int pos1, int pos2, int len); 2. 3. void MSort (int a[], int n) 4. { 5. for (int s = 1; s <= n/2; s = 2*s) 6. for (int i = 0; i < n; i = i + 2*s) 7. Merge (a, i, i + s, s); 8. } Lecture 16 ECE250 17

Question 1 (Continue) v This algorithm makes use of a routine called Merge which merges the two sorted sub-sequences of array a, each of length len, which start at array indices pos1 and pos2 as shown below: len len a pos1 pos2 v Derive a tight, big-oh asymptotic bound on the running time of the MSort routine as a function of n. Assume that the running time of Merge is O ( 2 len). Lecture 16 ECE250 18

Question 2 Stacks and Queues v Propose a data structure that supports Push and Pop operations, and a third operation Find-Max, which returns the largest element in the data structure, all in O(1) worst case time. Lecture 16 ECE250 19

Question 3 Tree Traversals v Consider the binary tree shown below: h c j a e i b d g f Lecture 16 ECE250 20

Question 3 (Continue) v For each of the following traversals, list the order in which the nodes are visited. Pre-order Traversal In-order Traversal Post-order Traversal Lecture 16 ECE250 21

Question 4 Binary Trees v A full node in a binary tree is a node with exactly two children. Give an expression for the number of full nodes in a binary tree as a function of the number of leaf nodes l. Hint: Consider the number of null pointers in a tree with n nodes. Lecture 16 ECE250 22

Question 5 - BST v Show the tree after deleting 50 and 30. Use the successor of a node if it is needed 50 30 90 10 70 95 Lecture 16 ECE250 23 80

Question 6 AVL Trees v What is the minimum number of nodes in an AVL tree of height three? What is the maximum number of nodes in an AVL tree of height three? v Let n be the minimum number of nodes in an AVL tree of height three. Draw the AVL tree of height three that contains the keys. 1, 2,3,..., n Lecture 16 ECE250 24

Question 7 B-Trees v Consider the following B-Tree of order 2, called X. Show the resulting B-tree when the key C is inserted into B-tree called X. Lecture 16 ECE250 25

Question 8 - Recurrences v Give asymptotic upper and lower bounds for the following recurrence. Assume that is constant for sufficiently small n. Make your bounds as tight as possible, and justify your answer. Lecture 16 ECE250 26

Question 9 - Hashing v Give an algorithm that uses hashing to check whether all elements of an array are distinct. Lecture 16 ECE250 27