0 Up votes0 Down votes

5 views10 pagesalgoritme og datastrukture

Jun 05, 2013

© Attribution Non-Commercial (BY-NC)

PDF, TXT or read online from Scribd

algoritme og datastrukture

Attribution Non-Commercial (BY-NC)

5 views

algoritme og datastrukture

Attribution Non-Commercial (BY-NC)

- Steve Jobs
- Wheel of Time
- NIV, Holy Bible, eBook
- NIV, Holy Bible, eBook, Red Letter Edition
- Cryptonomicon
- The Woman Who Smashed Codes: A True Story of Love, Spies, and the Unlikely Heroine who Outwitted America's Enemies
- Contagious: Why Things Catch On
- Crossing the Chasm: Marketing and Selling Technology Project
- Everybody Lies: Big Data, New Data, and What the Internet Can Tell Us About Who We Really Are
- Zero to One: Notes on Start-ups, or How to Build the Future
- Console Wars: Sega, Nintendo, and the Battle that Defined a Generation
- Dust: Scarpetta (Book 21)
- Hit Refresh: The Quest to Rediscover Microsoft's Soul and Imagine a Better Future for Everyone
- The Innovators: How a Group of Hackers, Geniuses, and Geeks Created the Digital Revolution
- Crushing It!: How Great Entrepreneurs Build Their Business and Influence—and How You Can, Too
- Make Time: How to Focus on What Matters Every Day
- Algorithms to Live By: The Computer Science of Human Decisions
- Wild Cards

You are on page 1of 10

Algorithms and Data Structures 2 Fall 2011 Assignment TEST EXAM - SOLUTIONS

Date: 01. 12. 2011, Due date:

Exercise TEST EXAM - SOLUTIONS.1: Consider the graph in Figure 1. It shows a network with ow at top. Find a maximal ow and a minimum cut. Indicate both in the middle respectively lower part of Figure 1. Solution: A maximum ow.

0/4 6/7

3/3

8/8

s

5/8

3/3

6/8

2/3

3/3

A minimum cut.

4 7

s

8

3

3 8 3

End of Solution. End of Exercise 1 Exercise TEST EXAM - SOLUTIONS.2: Answer the multiple-choice questions in Figure 3. A wrong answers cancels a correct one. Overall you cannot get a negative score. 1

Solution: a. NO, Kirchhos is not obeyed. b. NO. One can easily nd a ow with value 8 (or more) and use min-cut = maxow. c. NO. d. YES. e. NO. CDDAB is a common subsequence of length 5. f. NO. g. MST

End of Solution. End of Exercise 2 Exercise TEST EXAM - SOLUTIONS.3: Consider the following program: i 0; while (rand(1, 10) = 1) do i i + 1; od print(i); What is the probability that the value 3 is printed? What is the expected value of i that is printed? Solution: To print a 3, the while-loop has to be executed exactly 3 times. This means that the random number generator has to return a value from {2, . . . , 10} in the rst 3 calls and returns 1 in the fourth call. The probability for a non-1 is 9/10 that for a 1 is 1/10. The calls are independent, thus the probability for all four outcomes is the product of the four individual probabilities. (9) (9) (9) (1) (729) = = 0.0729. (10) (10) (10) (10) (10000) The possible values are 0, 1, 2, . . .. The probability pn to print n is the probability to execute the while loop exactly n times, which is in turn the probability that the random number generator rst returns n non-1, followed by a 1. Hence (9) n (1) pn = (10) (10) 2

(n p n ) =

n=0 n=0

=9

Note that you do NOT have to evlauate the formula to a number. Thus the following is a correct answer:

n (9) (1) n (10) (10) n=0

End of Solution. End of Exercise 3 Exercise TEST EXAM - SOLUTIONS.4: In the bipartite graph shown in Figure 4 indicate the edges of a maximum matching. Solution: Take edges {1, e}; {2, a}; {3, b}; {4, d}; {6, c}. Which gives size 5. A larger matching is not possible because this graph has 5 nodes at right. End of Solution. End of Exercise 4 Exercise TEST EXAM - SOLUTIONS.5: Consider the graph G = (V, E ) in Figure 5. The thick edges form a non-minimum spanning tree T = (V, F ). Find a tree-edge e F and an non-tree-edge e E \ F such that exchanging them gives a minimum spanning tree. That is, the tree T = (v, F ), where F = (F \ {e}) {e } is a minimum spanning tree. Argue why the tree is minimum. Solution: Use e = {b, c} and e = {b, g }. The tree is minimum because when looking at Kruskals algo it considers edges in increasing order of weight: All edges with weight 1 can be chosen; they do not give a cycle. Of the edges with weight 2 only {f, e} can be chosen. {b, e} would close a cycle. This is independent of the order in which the edges of weight 2 are considered. Both edges with weight 3 can be chosen. This gives a tree (7 edges).

Exercise TEST EXAM - SOLUTIONS.6: Given a sequence x1 , . . . , xn of integers. Find indices 1 i j n such that the sum

j

xk

k=i

is maximum. That is nd a sub-interval with maximum sum. Example for n = 8 and 5,-2,-6,4,-1,6,-3,2. The maximum sum is 9 and dened by i = 4, j = 6. Describe a Dynamic Programming algorithm for solving this problem and analyse its running time. Hint: Traverse the sequence from left to right. At each position i, there are at most two candidates for the maximum sub-interval in x1 , . . . , xi , (which?). Determine the update rule when moving one position to the right. IF YOU CANNOT FIND A DP-SOLUTION then describe the best (fastest) solution you can think of and analyse its running time. Solution: For the solution the indexing starts with 0 and ends with n 1. It is much more detailed than what we expect in the exam. The algorithm runs through the sequence x0 , . . . , xn1 only once. If the current position is k then the algorithm knows the optimal solution (maximum sum) ak1 on the subproblem consisting of x0 , . . . , xk1 . Let [i, j ], 0 i j k 1, be the interval of the maximum sum ak1 , i.e., ak = j t=i xt . The optimal solution for x0 , . . . , xk is either ak1 or it involves xx . Then it is some interval [ , k ] which ends at the current position k . Let bk be the maximum sum of this form, i.e., bk = k t= xk . We start with the subproblem consisting just of the rst integer x0 . Then we have b0 = x0 and we set a0 = x0 . If we are at a position k > 0 then there are two possibilities for bk : Either bk is realized by an interval [ , k ] where < k or by the interval [k, k ] consisting of xk only. In the rst case the maximum sum bk1 is extended by xk . Hence we can compute bk as that possibility which maximizes value: bk = max {bk1 + xk , xk } Similarly the value ak is the larger one of ak1 and bk : ak = max {ak1 , bk } Here is the pseudo-code of the algorithm DynamicProgrammingAlgorithm. We only compute the maximum sum and leave it to the reader to extend the algorithm such that also the corresponding interval is computed. Also we can immediately forget bk1 if bk is computed and similarly for ak1 and ak . Hence it suces to have just two variables a and b. The running time of the DynamicProgrammingAlgorithm in input x0 , . . . , xn1 is O (n) in the uniform cost measure. The FOR-loop in line 1 is executed n 1 times. In each execution one addition and two maxima are computed in lines 1 and 1 which is constant time. Hence the loop takes time 3n = O (n). Outside the loop are only two assignments which are constant time. Hence we end up with a total running time of O (n). 4

There is a divide-and-conquer solution with time O(n log(n)) and straight forward solutions with times O(n2 ) and O(n3 ).

Indicate a minimum cut. The labels at the edges are the capacities.

0/3

a. b. c. d.

Figure 2 shows a ow network and a ow. The ow network in Figure 2 has a minimum cut with value 6. The running time of the Edmonds-Karp algorithm depends on the value of the maximum ow. The residual capacities of a residual network are always less than or equal to the capacities of the corresponding ow network. The longest common subsequence of the strings ACBDDDAB and BBCDADAAB has length 4 The longest common substring of the strings ACBDDDAB and BBCDADAAB has length 3 The union-nd data structure is used in an algorithm for minimum spanning tree (MST) or closest pair (CP)

No No No No

e. f. g.

No No CP

1 2 3 4 5 6 a b c d e

a 5 d 1

1 2

b 3 e

4 c 1 6

2 5

4 3 g h

10

- a1 SolutionUploaded byGraciela Marques
- FOCS11Uploaded byManoj
- 12cmuUploaded byAbhinav Bhardwaj
- Unplugged 09 Minimal Spanning Trees OriginalUploaded by007wasr
- Undergrad Guideto Concentrate in Economics at HarvardUploaded bykhaleddanaf
- Data CompressionUploaded byHafidz Jazuli Luthfi
- The Ford-Fulkerson MethodUploaded byArdhiansyah Baskara
- MIT Thesis JsotoUploaded byAmador Perez Lopez
- syllibus565_w02.pdfUploaded byMohammedDow
- edexcel gsce mark scheme 06/2007maths BUploaded byArun Nandha
- p221-gabowUploaded byWisllay Vitrio
- VRP_lingoUploaded byEmrahend
- L011 Newton's MethodUploaded byJulián Kaihara
- EdgesUploaded bybbcjohnjohn
- Easy Mod Probs-solUploaded byYonatan Ysrael Zurita
- s1mu7c5m2i800Uploaded byishir babu sharma
- Dijsktra AlgorithmUploaded byFurqan Ali Khan
- Flash Flood Fill ImpUploaded byRamnaresh Sharma
- BwtSort.cUploaded byKasf
- the blue path_ uva 12532 - interval productUploaded bythextroid
- lab2.pdfUploaded byIrina Ungureanu
- Dsa 02 ShankarUploaded byapi-3737469
- 0131194585_pp12Uploaded bySyed Imtiaz Hussain
- AStarV5Uploaded byryan_bohler
- BIT_IT_IV_SP11_NB.pdfUploaded bySanam1378
- Complete PracticalUploaded byshabbirjamali
- Algorithms and data structureUploaded byalin
- Eufit_98.pdfUploaded byMeisha desionasista
- Add and Remove Server CapacityUploaded byJhonn Jairo Bejarano Osorio
- Backhouse ProblemsUploaded byJason Smith

- A Survey on: Enhancement of Minimum Spanning TreeUploaded byAnonymous 7VPPkWS8O
- Graph Theory & Algorithms - M. Ashraf IqbalUploaded byAbdul Rehman Naeem
- January 2017 QP - D1 EdexcelUploaded byBabaJ1
- Operations Research.pdfUploaded bySha Eem
- AkumeUploaded byPiero Conislla Cardenas
- DSA interview questions QuestionUploaded byChirag
- Constructive Heuristic s for the TspUploaded byms6675223
- Syllabus Seventh SemesterUploaded bySingh Ak
- Cs1201 Design and Analysis of AlgorithmUploaded bymaharajaking
- EC2202-qbUploaded byappasami
- A minimal spanning tree algorithm for distribution networks configurationUploaded bypanggah
- Daa Notes FullUploaded byAarif Muhammed
- ds lesson plan.docxUploaded byRamya Rajam
- Cs2201 Data StructuresUploaded byKarthik Sara M
- Analysis and Design of Algorithm Lecture notesUploaded byEfrain Sanjay Adhikary
- Technical Aptitude Questions eBookUploaded bySundaresan Munuswamy
- GraphsUploaded byAnkit Sharma
- Final Algorithm lab manual.docUploaded byMainak De
- A Survey on Traditional and Graph Theoretical Techniques for Image Segmentation _ Basavaprasad B - AcademiaUploaded bymuhamadkamalamin
- Decision Mathematics D1 Jan 2016 Question PaperUploaded byrickymartin23
- CS1201Uploaded byArun Ram Prasath S
- Important Questions in B.tech C- ProgramUploaded byRangothri Sreenivasa Subramanyam
- GraphUploaded byAnjam Chaudhary
- VLSI Cell PlacementUploaded bydharma_panga8217
- Vyom-Freshers-Guide-2007Uploaded byapi-3777212
- Data StructuresUploaded bygrsrik
- AQA testUploaded byVũ Lê
- Algorithms Question BankUploaded byPablo Ahmed
- CS8391_DS_IQ_NOV.DEC 2018_REJINPAUL.pdfUploaded bymoni mary
- 6. Fall 2006 with Solutions.pdfUploaded byfara

## Much more than documents.

Discover everything Scribd has to offer, including books and audiobooks from major publishers.

Cancel anytime.