CS 360 Exam 2 Fall 2014 Name

Similar documents
6. Suppose lim = constant> 0. Which of the following does not hold?

CSE 332. Sorting. Data Abstractions. CSE 332: Data Abstractions. QuickSort Cutoff 1. Where We Are 2. Bounding The MAXIMUM Problem 4

Lecture 6: Coding theory

Solutions for HW9. Bipartite: put the red vertices in V 1 and the black in V 2. Not bipartite!

Welcome. Balanced search trees. Balanced Search Trees. Inge Li Gørtz

Algorithms & Data Structures Homework 8 HS 18 Exercise Class (Room & TA): Submitted by: Peer Feedback by: Points:

SIMPLE NONLINEAR GRAPHS

22: Union Find. CS 473u - Algorithms - Spring April 14, We want to maintain a collection of sets, under the operations of:

Counting Paths Between Vertices. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs

18.06 Problem Set 4 Due Wednesday, Oct. 11, 2006 at 4:00 p.m. in 2-106

CIT 596 Theory of Computation 1. Graphs and Digraphs

where the box contains a finite number of gates from the given collection. Examples of gates that are commonly used are the following: a b

NON-DETERMINISTIC FSA

Common intervals of genomes. Mathieu Raffinot CNRS LIAFA

Solutions to Problem Set #1

CS 2204 DIGITAL LOGIC & STATE MACHINE DESIGN SPRING 2014

Implication Graphs and Logic Testing

CS 491G Combinatorial Optimization Lecture Notes

Data Structures (INE2011)

CARLETON UNIVERSITY. 1.0 Problems and Most Solutions, Sect B, 2005

Identifying and Classifying 2-D Shapes

Tutorial Worksheet. 1. Find all solutions to the linear system by following the given steps. x + 2y + 3z = 2 2x + 3y + z = 4.

CS311 Computational Structures Regular Languages and Regular Grammars. Lecture 6

Factorising FACTORISING.

Pre-Lie algebras, rooted trees and related algebraic structures

2.4 Theoretical Foundations

Arrow s Impossibility Theorem

Surds and Indices. Surds and Indices. Curriculum Ready ACMNA: 233,

Automata and Regular Languages

XML and Databases. Exam Preperation Discuss Answers to last year s exam. Sebastian Maneth NICTA and UNSW

Equivalent fractions have the same value but they have different denominators. This means they have been divided into a different number of parts.

The DOACROSS statement

Spacetime and the Quantum World Questions Fall 2010

CS 573 Automata Theory and Formal Languages

1 PYTHAGORAS THEOREM 1. Given a right angled triangle, the square of the hypotenuse is equal to the sum of the squares of the other two sides.

Instructions. An 8.5 x 11 Cheat Sheet may also be used as an aid for this test. MUST be original handwriting.

Chapter 4 State-Space Planning

I 3 2 = I I 4 = 2A

System Validation (IN4387) November 2, 2012, 14:00-17:00

Numbers and indices. 1.1 Fractions. GCSE C Example 1. Handy hint. Key point

Eigenvectors and Eigenvalues

CS 310 (sec 20) - Winter Final Exam (solutions) SOLUTIONS

Necessary and sucient conditions for some two. Abstract. Further we show that the necessary conditions for the existence of an OD(44 s 1 s 2 )

Running an NFA & the subset algorithm (NFA->DFA) CS 350 Fall 2018 gilray.org/classes/fall2018/cs350/

Activities. 4.1 Pythagoras' Theorem 4.2 Spirals 4.3 Clinometers 4.4 Radar 4.5 Posting Parcels 4.6 Interlocking Pipes 4.7 Sine Rule Notes and Solutions

CHEM1611 Answers to Problem Sheet 9

Lecture 8: Abstract Algebra

for all x in [a,b], then the area of the region bounded by the graphs of f and g and the vertical lines x = a and x = b is b [ ( ) ( )] A= f x g x dx

Lesson 2.1 Inductive Reasoning

Graph Theory. Simple Graph G = (V, E). V={a,b,c,d,e,f,g,h,k} E={(a,b),(a,g),( a,h),(a,k),(b,c),(b,k),...,(h,k)}

Connectivity in Graphs. CS311H: Discrete Mathematics. Graph Theory II. Example. Paths. Connectedness. Example

CSC2542 State-Space Planning

Probability The Language of Chance P(A) Mathletics Instant Workbooks. Copyright

Mid-Term Examination - Spring 2014 Mathematical Programming with Applications to Economics Total Score: 45; Time: 3 hours

Nondeterminism and Nodeterministic Automata

Section 6: Area, Volume, and Average Value

Nondeterministic Finite Automata

Let s divide up the interval [ ab, ] into n subintervals with the same length, so we have

CISC 320 Introduction to Algorithms Spring 2014

Project 6: Minigoals Towards Simplifying and Rewriting Expressions

Algorithm Design and Analysis

Solutions to Chapte 7: Channel Coding

Exam Review. John Knight Electronics Department, Carleton University March 2, 2009 ELEC 2607 A MIDTERM

Technische Universität München Winter term 2009/10 I7 Prof. J. Esparza / J. Křetínský / M. Luttenberger 11. Februar Solution

Laboratory for Foundations of Computer Science. An Unfolding Approach. University of Edinburgh. Model Checking. Javier Esparza

Year 10 Maths. Semester One Revision Booklet.

Polynomials. Polynomials. Curriculum Ready ACMNA:

Lecture 3. XML Into RDBMS. XML and Databases. Memory Representations. Memory Representations. Traversals and Pre/Post-Encoding. Memory Representations

CS 373, Spring Solutions to Mock midterm 1 (Based on first midterm in CS 273, Fall 2008.)

PYTHAGORAS THEOREM WHAT S IN CHAPTER 1? IN THIS CHAPTER YOU WILL:

Lecture 4: Graph Theory and the Four-Color Theorem

Formula for Trapezoid estimate using Left and Right estimates: Trap( n) If the graph of f is decreasing on [a, b], then f ( x ) dx

Total score: /100 points

NFA DFA Example 3 CMSC 330: Organization of Programming Languages. Equivalence of DFAs and NFAs. Equivalence of DFAs and NFAs (cont.

POSITIVE IMPLICATIVE AND ASSOCIATIVE FILTERS OF LATTICE IMPLICATION ALGEBRAS

F / x everywhere in some domain containing R. Then, + ). (10.4.1)

Lecture Notes No. 10

Parse trees, ambiguity, and Chomsky normal form

APPENDIX. Precalculus Review D.1. Real Numbers and the Real Number Line

Global alignment. Genome Rearrangements Finding preserved genes. Lecture 18

Lesson 2.1 Inductive Reasoning

Things to Memorize: A Partial List. January 27, 2017

Trigonometry Revision Sheet Q5 of Paper 2

Algorithm Design and Analysis

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER MACHINES AND THEIR LANGUAGES ANSWERS

Solids of Revolution

Linear Algebra Introduction

Balanced binary search trees

Part 4. Integration (with Proofs)

Lecture 2: Cayley Graphs

SECTION A STUDENT MATERIAL. Part 1. What and Why.?

First Midterm Examination

Unique Solutions R. 4. Probability. C h a p t e r. G l a n c e

Boolean Algebra cont. The digital abstraction

C REVISED PER ECR DEC2015 T.S E.T $ D/C MATING CONNECTOR PART NUMBER WEIGHT. (g)

QUADRATIC EQUATION. Contents

Non Right Angled Triangles

Logic, Set Theory and Computability [M. Coppenbarger]

Arrow s Impossibility Theorem

Intermediate Math Circles Wednesday 17 October 2012 Geometry II: Side Lengths

Transcription:

CS 360 Exm 2 Fll 2014 Nme 1. The lsses shown elow efine singly-linke list n stk. Write three ifferent O(n)-time versions of the reverse_print metho s speifie elow. Eh version of the metho shoul output the t ontine within the noes of the list in reverse orer, tht is, from k to front. Exmple: if the list ontins elements [4, 9, 1, 6] then the output shoul e 6 1 9 4. lss Noe { int t; Noe next; } lss List { Noe he; voi reverse_print( ); } lss Stk { Stk( ); oolen isempty( ); voi push (int x); int pop( ); }. Use stk s n uxiliry t struture. Do not use ny other t struture, o not use reursion, n o not moify the linke list. [5 points]. Use reursion. Do not use n expliit stk or ny other t struture, n o not moify the linke list. Hint: use helper funtion tht is reursive. [5 points]

. Do not use stk or ny other t struture, n o not use reursion. You my use only O(1) extr spe eyon the linke list. Your metho my temporrily moify the linke list, ut when the metho ens, the linke list must e ore extly the sme s it ws efore the metho ws lle. Hint: reverse the list in ple. [10 points] 2. Drw one inry tree tht yiels ll three of the trversls s shown elow. [8 points] Pre-orer: Post-orer: In-orer: L G Z J T X C M P R A N Y E B H V T J M C P X Z G Y B E N V H A R L G T J Z C M X P L Y N B E A H V R

3. A stnr Queue implementtion is provie elow. Complete the lss MultipleQueues, whih represents ritrrily mny queues, y using one instne Q of lss Queue s shown. In lss MultipleQueues, istint queues re hieve y speifying istint qnum vlues. The expete ehvior of methos enqueue n equeue is illustrte in n exmple elow. The enqueue metho must tke O(1) time, ut equeue my tke ω(1) time. [15 points] lss Queue { Queue( ); int size ( ); voi enqueue (int z); int equeue( ); } lss MultipleQueues { Queue Q; MultipleQueues( ) { Q = new Queue( ); } voi enqueue (int qnum, int z); // write this metho int equeue (int qnum); // write this metho } MultipleQueues M = new MultipleQueues( ); M.enqueue (7, 30); M.enqueue (2, 40); M.enqueue (7, 50); M.enqueue (2, 60); print (M.equeue (2)); print (M.equeue (2)); // outputs: 40 60 print (M.equeue (7)); print (M.equeue (7)); // outputs: 30 50

4. Answer the following questions out running times of list opertions. [25 points]. Stte the worst-se θ running time for n effiient implementtion of eh list opertion shown elow, when using eh speifie t struture. (x is vlue, n p is position.) Fin (x) After (p) Before (p) Insert (x) InsertAfter (p,x) InsertBefore (p,x) InsertFirst (x) InsertLst (x) Remove (x) Remove (p) RemoveFirst ( ) RemoveLst ( ) Unsorte singly-linke list, with link to he ut no link to til noe Unsorte ouly-linke list, with links to oth he n til noes Unsorte non-irulr rry, where rry inex k yiels the rnk k element. For whih opertion(s) oes the θ running time hnge if we use singly-linke list with links to oth he n til noes, rther thn singly-linke list with link to only the he noe? Also stte eh suh opertions running time for singly-linke list with links to oth he n til noes.. For whih opertion(s) oes the θ running time hnge if we use irulr rry rther thn non-irulr rry? Also stte eh suh opertions running time for irulr rry.. Whih opertion(s) shoul not e provie if the elements in the t struture must e mintine in sorte orer? e. For whih opertion(s) oes the θ running time hnge if we use sorte rry rther thn n unsorte rry? Also stte eh suh opertions running time for sorte rry.

5. Consier hsh tle with N slots, where N 5. [6 points]. Use liner proing n insert 2 rnom keys. Determine the proility tht these 2 keys will oupy 2 jent slots (possily with wrproun).. Use liner proing n insert 3 rnom keys. Determine the proility tht these 3 keys will oupy 3 jent slots (possily with wrproun).. Use seprte hining n insert 3 rnom keys. Determine the proility tht ll 3 keys re ple in the sme hin.. Use seprte hining n insert 3 rnom keys. Determine the proility tht ll 3 keys re ple in ifferent hins. e. Use seprte hining n insert 3 rnom keys. Determine the proility tht extly 2 of these 3 keys re ple in the sme hin.

6. Strt with the -lk tree shown elow whih hs keys 3, 4, 5. First insert keys 6, 7, 8, 9, 10, 11, 12 (in tht orer) n rw the tree fter eh insert. Next remove keys 3, 4, 5, 6, 7 (in tht orer) n rw the tree fter eh remove. Clerly inite the olor of eh noe (=lk, r=). Mke sure tht eh tree you rw is properly forme -lk tree. If you rw ny intermeite steps, irle the trees tht shoul e gre. [12 points] 4 3 r 5 r

7. Strt with the AVL tree shown elow whih hs keys 5, 10. First insert keys 6, 7, 8, 9, 0, 4, 3, 2, 1 (in tht orer) n rw the tree fter eh insert. Next remove keys 3, 10, 9 (in tht orer) n rw the tree fter eh remove. It is permitte ut not requi to show the height of eh noe. Mke sure tht eh tree you rw is properly forme AVL tree. If you rw ny intermeite steps, irle the trees tht shoul e gre. [12 points] 5 10

8. Strt with the sply tree shown elow whih hs key 5. First insert keys 6, 3, 4, 1, 2, 9, 7, 8 (in tht orer) n rw the tree fter eh insert. Next remove keys 1, 9, 6, 7 (in tht orer) n rw the tree fter eh remove. Mke sure tht eh tree you rw is properly forme sply tree. If you rw ny intermeite steps, irle the trees tht shoul e gre. [12 points] 5

Insertion into -lk tree Getting strte: Rehing the root: 0. x 3. root root lef lef lef Restruturing (single or oule rottion): 1. 1. 1. 1. Reoloring: 2. 2. 2. 2.

Removl from -lk tree Getting strte: 0. x lef 0. x lef efiient lef lef lef lef 0. x w 0. x y w lef lef lef lef y lef lef lef lef lef lef Restruturing (single or oule rottion): 1. ny sme ny 1. sme efiient efiient 1. ny sme 1. ny sme e efiient e e efiient e `

Removl from -lk tree (ontinue) Reoloring: 2. 2. efiient efiient 2. efiient 2. efiient efiient efiient Ajustment (single rottion): 3. 3. efiient efiient efiient efiient [Alwys followe y 1, 1, 1, 1, 2, or 2] Rehing the root: 4. root efiient root

AVL tree: insertion n removl 1. Y, h+3 1. U, h+3 Right rotte t Y U, h+2 Z, h T, h Y, h+2 Left rotte t U T, h+1 W W Z, h+1 2. Y, h+3 Left rotte t U, 2. U, h+3 Right rotte t Y, U, h+2 Z, h h Right rotte t Y T, h Y, h+2 th Left rotte t U T, h W, h+1 W, h+1 Z, h Sply tree: insertion n removl 1. Zig root X P Right rotte t P 1. Zg root P X Left rotte t P 2. G P Right rotte t G, 2. Zigzig Zgzg G P Left rotte t G, then Left rotte t P X Right rotte then t P X 3. P G X Left rotte t P, Right th rotte t G 3. Zigzg Zgzig G X P Right rotte t P, th Left rotte t G