CSE 373 Spring Midterm. Friday April 21st

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

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

CSE 373 APRIL 17 TH TREE BALANCE AND AVL

Part 1: Multiple Choice Circle only ONE answer. Each multiple choice question is worth 3.5 marks.

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

Cpt S 122 Data Structures. Course Review Midterm Exam # 1

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

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

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

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

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours

Sample Exam 1 Questions

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

Computer Science Foundation Exam. Dec. 19, 2003 COMPUTER SCIENCE I. Section I A. No Calculators! KEY

Abstract Data Structures IB Computer Science. Content developed by Dartford Grammar School Computer Science Department

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

CS301 - Data Structures Glossary By

CSE373 Midterm I Fall 2009 (Closed book, closed notes)

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

Trees. (Trees) Data Structures and Programming Spring / 28

ECE250: Algorithms and Data Structures Midterm Review

Lec 17 April 8. Topics: binary Trees expression trees. (Chapter 5 of text)

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

Data Structures Question Bank Multiple Choice

* Due 11:59pm on Sunday 10/4 for Monday lab and Tuesday 10/6 Wednesday Lab

Binary Trees, Binary Search Trees

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

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

INF2220: algorithms and data structures Series 1

Computer Science 302 Spring 2007 Practice Final Examination: Part I

EE 368. Week 6 (Notes)

This is a set of practice questions for the final for CS16. The actual exam will consist of problems that are quite similar to those you have

Chapter 20: Binary Trees

Computer Science 302 Spring 2018 Practice Examination for the Second Examination,

CSL 201 Data Structures Mid-Semester Exam minutes

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

Cpt S 122 Data Structures. Data Structures Trees

Prelim 2 Solution. CS 2110, November 19, 2015, 5:30 PM Total. Sorting Invariants Max Score Grader

CPSC 331 Term Test #2 March 26, 2007

1. Attempt any three of the following: 15

TREES. Trees - Introduction

Section 1: True / False (2 points each, 30 pts total)

Prepared By: Ms. Nidhi Solanki (Assist. Prof.) Page 1

Faculty of Science FINAL EXAMINATION COMP-250 A Introduction to Computer Science School of Computer Science, McGill University

R10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May

In addition to the correct answer, you MUST show all your work in order to receive full credit.

CSE wi: Practice Midterm

Test 1 SOLUTIONS. June 10, Answer each question in the space provided or on the back of a page with an indication of where to find the answer.

Programming II (CS300)

Prelim 2, CS2110. SOLUTION

Prelim 2 SOLUTION. 5:30 PM, 25 April Total Question Name Short Search/ Collections Trees Graphs

Binary Trees. BSTs. For example: Jargon: Data Structures & Algorithms. root node. level: internal node. edge.

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

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305

Computing Science 115 Final Examination April 23, 2002 Section: B2 BASU. Please put student id on last page. Instructions:

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Summer I Instructions:

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

Data Structure Advanced

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

Section 05: Midterm Review

DATA STRUCTURES AND ALGORITHMS

Binary Search Trees Treesort

Abstract Data Structures IB Computer Science. Content developed by Dartford Grammar School Computer Science Department

Computer Science E-22 Practice Final Exam

CSE 373 OCTOBER 11 TH TRAVERSALS AND AVL

Name: UTLN: CS login: Comp 15 Data Structures Midterm 2018 Summer

CS350: Data Structures Tree Traversal

Prelim 2 Solution. CS 2110, November 19, 2015, 7:30 PM Total. Sorting Invariants Max Score Grader

CSE 332, Spring 2010, Midterm Examination 30 April 2010

MLR Institute of Technology

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

Tree: non-recursive definition. Trees, Binary Search Trees, and Heaps. Tree: recursive definition. Tree: example.

CSE 143 Final Exam Part 1 - August 18, 2011, 9:40 am

INF2220: algorithms and data structures Series 1

Course Review for Finals. Cpt S 223 Fall 2008

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

Summer Final Exam Review Session August 5, 2009

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

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

Friday Four Square! 4:15PM, Outside Gates

Total Score /1 /20 /41 /15 /23 Grader

R13. II B. Tech I Semester Supplementary Examinations, May/June DATA STRUCTURES (Com. to ECE, CSE, EIE, IT, ECC)

CMSC 341 Lecture 10 Binary Search Trees

Sample Question Paper

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

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Spring Instructions:

1. Stack overflow & underflow 2. Implementation: partially filled array & linked list 3. Applications: reverse string, backtracking

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

CS 61BL Midterm 2 Review Session. Chris Gioia, Patrick Lutz, Ralph Arroyo, Sarah Kim

Data Structures. Outline. Introduction Linked Lists Stacks Queues Trees Deitel & Associates, Inc. All rights reserved.

Department of Computer Science and Engineering. CSE 2011: Fundamentals of Data Structures Winter 2009, Section Z

Course Review. Cpt S 223 Fall 2009

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

Department of Computer Science and Technology

Why Do We Need Trees?

Objective Questions for Online Practical Exams under CBCS Scheme Subject: Data Structure-I (CS-113)

Algorithm Efficiency & Sorting. Algorithm efficiency Big-O notation Searching algorithms Sorting algorithms

DYNAMIC MEMORY ALLOCATION AND DEALLOCATION

CSE 373 APRIL 3 RD ALGORITHM ANALYSIS

Draw a diagram of an empty circular queue and describe it to the reader.

Transcription:

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. This exam is worth 50 points. After each question, you will find the number of points it is worth. You should spend approximately x minutes on a question worth x points. 1. 10 points 2. 15 points 3. 5 points 4. 14 points 5. 6 points 1

1. (10 points) Big-Oh and analysis of algorithms (a) (2 points) Let f(n) and g(n) be two functions. Define formally the meaning that f(n) is O(g(n)) Let f(n) and g(n) be functions mapping nonnegative integers to real numbers. We say that f(n) is O(g(n) if there is a real constant c and an integer constant n 0 1 such that: f(n) c g(n) for n n 0 (b) (4 points) Which of the 4 functions below are (is) O(n 2 ) f(n) = n 2 /(6n + 1) g(n) = n 2 (n + 1) h(n) = n 2 logn i(n) = 2 2logn f(n) and i(n) (c) (2 points) Given an array A of n elements, the program (pseudo-code) below returns an array B such that B(i) = i j=0 A(j) integer s; s := 0; for (i:=0, i<n: i++) { s := s + A[i]; B[i] := s; What is the time complexity of this program? O(n) (d) (2 points) If A(i) = i, i = 0, 1,..., n 1 what is the value of B(i)? B(i) = i j = j=0 i (i + 1) 2 2

2. (15 points) Memory allocation (This question continues on the next page) A block of memory of size M is used by a memory allocator. All blocks that are allocated and deallocated are of the same size, that is unit size. In other words a maximum of M blocks can be allocated at any given time. The memory allocator sees the block of memory as an array of M elements, from element 0 to element M 1. (a) (5 points) The allocations/deallocations are only for 2 stacks, Stack1 growing from block 0 up toward block M 1 and Stack2 growing from block M 1 down to block 0. Let T op1 (initialized to -1) and T op2 (initialized to M) be the tops of the stacks. For example, after 2 calls to AllocStack1(Top1,Top2) that allocates elements in Stack1 followed by 1 call to AllocStack2(Top1,Top2) that allocates elements in Stack2, the memory that was initially all free blocks now has 3 allocated blocks as per the figure: Stack1 Stack2 Top1 = 1 (i) Initial Top2 = M Top1 = 1 Top2 = M 1 (ii) After 2 allocations in Stack1 and 1 allocation in Stack2 Give pseudo-code for the 2 methods: AllocStack1(Top1,Top2) and AllocStack2(Top1,Top2) that return the index (a value between 0 and (M 1) of the block that was allocated. Be sure to include a test for overflow. AllocateStack1(integer Top1, integer Top2): integer { Top1++; if (Top1 = Top2) then throw overflow exception else return Top1 AllocateStack2(integer Top1, integer Top2) : integer { Top2--; if (Top1 = Top2) then throw overflow exception else return Top2 3

(b) (5 points) If now Stack1 was replaced by a queue with Front and Rear pointers, what modification would you make to the method to allocate in the stack (i.e., Stack2). (You don t have to write the pseudo-code; just state what would change and how it would change). I would just change the test for overflow to compare Top2 and Rear. (c) (3 points) Could you have a case in part (b) where you cannot allocate for the stack but there are some free blocks in the memory? If your answer is yes what is the worst case, i.e., the minimum number of elements in the queue for which this could happen? Justify your answers in 1 or 2 sentences. Yes. Consider a few allocations in the queue (without overflow) followed by a deallocation. If now an allocation in Stack2 results in an overflow, there is a free block (block at index 0). In fact, the worst case is when the queue has only 1 element. (d) (2 points) In order to remedy the problems you found in part (c), a friend of yours says that you should use a circular queue implementation. Would that help? Justify your answer in 1 or 2 sentences. No. The situation above could still occur 4

3. (5 points) Singly Linked List implementation You are given a singly linked list with a pointer to its first node, called head, a pointer to its last node, called tail, and a pointer to a node in between called p. You can assume that the list has at least 3 nodes. (a) (3 points) Give pseudo-code to transform the above list into a list which is the concatenation of the list starting at p (included) and terminating at tail (included) with the list starting at head (included) and terminating at p (not included). The method can destruct the original list. Only a pointer to the first node of the new list is required. Splitandconcatenate(p,head,tail: pointer): pointer{ curr : pointer; tail.next := head; curr := head; while curr.next!= p { curr := curr.next; curr.next := null return p (b) (1 point) What is the time complexity of your pseudo-code above if you know that the list has n elements and that p is the node directly following the head node. O(1) (c) (1 point) What is the time complexity of your pseudo-code above if you know that the list has n elements and that p is the node directly preceding the tail node. O(n) 5

4. (14 points) Binary Search Trees (This question continues on the next page) (a) (2 points) Which of the following 4 trees are Binary Search Trees (BSTs) 1 6 2 1 2 3 4 7 11 1 3 2 (a) (b) (c) (d) 3 (c) and (d) (b) (3 points) Draw the BST where the following keys are inserted in the order: 10, 6, 14, 17, 15, 8, 2, 7 10 6 14 2 8 17 7 15 (c) (3 points) Given the BST of part (b) draw the BST after the deletion of key 10 followed by the deletion of key 6 14 7 17 2 8 15 6

(d) (3 points) Recall that a traversal in: preorder means traverse root, traverse left subtree, traverse right subtree postorder means traverse left subtree, traverse right subtree, traverse root inorder means traverse left subtree, traverse root, traverse right subtree Given the postorder of a BST: 35, 30, 40, 55, 75, 60, 50 draw the tree 50 40 60 30 55 75 35 (e) (3 points) Give the pseudo-code for a method Findmax() that returns the maximum element in a BST. Findmax(T: tree pointer) : integer { if T = null then throw exception empty tree; while (T.right!= null) { T := T.right; return T.data; 7

5. (6 points) Fill up the table below with the time complexity in Big-Oh notation for the average cases and worst cases of 3 sorting algorithms Sorting Algorithm Average Case Worst Case Insertion Sort O(n 2 ) O(n 2 ) Selection Sort O(n 2 ) O(n 2 ) MergeSort O(nlogn) O(nlogn) 8