# Register now to access 7 million high quality study materials (What's Course Hero?) Course Hero is the premier provider of high quality online educational resources. With millions of study documents, online tutors, digital flashcards and free courseware, Course Hero is helping students learn more efficiently and effectively. Whether you're interested in exploring new subjects or mastering key topics for your next exam, Course Hero has the tools you need to achieve your goals.

1 Page

### Data Str & Algorithm HW Solutions 10

Course: MAP 2302, Fall 2011
School: UNF
Rating:

Word Count: 130

#### Document Preview

2 10 Chap. Mathematical Preliminaries (c) Induction Step. n i=1 1 2i n1 = i=1 = 1 1 1 +n i 2 2 1 2n1 + 1 2n 1 . 2n Thus, the theorem is proved by mathematical induction. 2.20 Proof: (a) Base case. For n = 0, 20 = 21 1 = 1. Thus, the formula is correct for the base case. (b) Induction Hypothesis. = 1 n1 2i = 2n 1. i=0 (c) Induction Step. n 2i = i=0 n1 2i + 2n i=0 = 2n 1 + 2n = 2n+1 1. Thus,...

Register Now

#### Unformatted Document Excerpt

Coursehero >> Florida >> UNF >> MAP 2302

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
2 10 Chap. Mathematical Preliminaries (c) Induction Step. n i=1 1 2i n1 = i=1 = 1 1 1 +n i 2 2 1 2n1 + 1 2n 1 . 2n Thus, the theorem is proved by mathematical induction. 2.20 Proof: (a) Base case. For n = 0, 20 = 21 1 = 1. Thus, the formula is correct for the base case. (b) Induction Hypothesis. = 1 n1 2i = 2n 1. i=0 (c) Induction Step. n 2i = i=0 n1 2i + 2n i=0 = 2n 1 + 2n = 2n+1 1. Thus, the theorem is proved mathematical by induction. n+1 2.21 The closed form solution is 3 2 3 , which I deduced by noting that 3F (n) F (n) = 2F (n) = 3n+1 3. Now, to verify that this is correct, use mathematical induction as follows. 2 For the base case, F (1) = 3 = 3 2 3 . The induction hypothesis is that n1 = (3n 3)/2. i=1 So, n 3i = i=1 = = n1 3i + 3n i=1 3n 2 3 + 3n 3n+1 3 . 2 Thus, the theorem is proved by mathematical induction.
Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

UNF - MAP - 2302
112.22 Theorem 2.1ni=1 (2i)= n2 + n.(a) Proof: We know from Example 2.3 that the sum of the rst n oddnumbers is n2 . The ith even number is simply one greater than the ithodd number. Since we are adding n such numbers, the sum must be ngreater, or
UNF - MAP - 2302
12Chap. 2 Mathematical Preliminaries8 5 n2()3355&lt; ( )2 ( )n2335n=.3=Thus, the theorem is proved by mathematical induction.2.24 Proof:22(a) Base case. For n = 1, 13 = 1 (1+1) = 1. Thus, the formula is correct4for the base case.(b) Induc
UNF - MAP - 2302
13iii. Induction Step. Consider the case where n + 1 pigeons are in nholes. Eliminate one hole at random. If it contains one pigeon,eliminate it as well, and by the induction hypothesis some otherhole must contain at least two pigeons. If it contains
UNF - MAP - 2302
14Chap. 2 Mathematical PreliminariesInduction hypothesis: T(n 1) = 2n1 1.Induction step:T(n) = 2T(n 1) + 1= 2(2n1 1) + 1= 2n 1.Thus, as proved by mathematical induction, this formula is indeed the correctclosed form solution for the recurrence.2.
UNF - MAP - 2302
152.32 (I saw this problem in John Bentleys Programming Pearls.) Approach 1:The model is Depth X Width X Flow where Depth and Width are in milesand Flow is in miles/day. The Mississippi river at its mouth is about 1/4 milewide and 100 feet (1/50 mile)
UNF - MAP - 2302
16Chap. 2 Mathematical Preliminaries2.37 An hour has 3600 seconds, so one million seconds is a bit less than 300 hours.A good estimater will notice that 3600 is about 10% greater than 3333, so theactual number of hours is about 10% less than 300, or c
UNF - MAP - 2302
3Algorithm Analysis3.1 Note that n is a positive integer.5n log n is most efcient for n = 1.2n is most efcient when 2 n 4.10n is most efcient for all n &gt; 5. 20n and 2n are never moreefcient than the other choices.3.2Both log3 n and log2 n will hav
UNF - MAP - 2302
18Chap. 3 Algorithm Analysis3.8 Other values for n0 and c are possible than what is given here.(a) The upper bound is O(n) for n0 &gt; 0 and c = c1 . The lower bound is(n) for n0 &gt; 0 and c = c1 .(b) The upper bound is O(n3 ) for n0 &gt; c3 and c = c2 + 1.
UNF - MAP - 2302
193.11(a)nnn! = n (n 1) ( 1) 2 122nnn 1 1 1222n n/2=()2Thereforenlg n! lg2(b) This part is easy, since clearlyn21 (n lg n n).21 2 3 n &lt; n n n n,so n! &lt; nn yielding log n! &lt; n log n.3.12 Clearly this recurrence is in O(log n n)
UNF - MAP - 2302
20Chap. 3 Algorithm Analysis3.15 Yes. When we specify an upper or lower bound, that merely states our knowledge of the situation. If they do not meet, that merely means that we dontKNOW more about the problem. When we understand the problem completely,
UNF - MAP - 2302
21binary search of the subarray will nd the position n in an additional log nsearches at most, for a total cost in O(log n) searches.3.19 Here is a description for a simple (n2 ) algorithm.boolean Corner(int n, int m, Piece P1, Piece* array) cfw_for
UNF - MAP - 2302
22Chap. 3 Algorithm AnalysisSWAP(array[i][j], array[tempr][tempc]);Finding the corner takes O(n2 m2 ) time, which is the square of the number ofpieces. Filling in the rest of the pieces also takes O(n2 m2 ) time, the numberof pieces squared. Thus,
UNF - MAP - 2302
4Lists, Stacks, and Queues4.1 Call the list in question L1.L1.setStart();L1.next();L1.next();val = L1.remove();4.2(a) | 10, 20, 15 .(b) 39 | 12, 10, 20, 15 .4.3 list L1(20);L1.append(2);L1.append(23);L1.append(15);L1.append(5);L1.append(9);
UNF - MAP - 2302
24Chap. 4 Lists, Stacks, and Queueslink&lt;Elem&gt;* temp1 = head-&gt;next;link&lt;Elem&gt;* temp2 = temp1-&gt;next;while (temp2 != NULL) cfw_link&lt;Elem&gt;* temp3 = temp2-&gt;next;temp2-&gt;next = temp1;temp1 = temp2;temp2 = temp3;head-&gt;next = temp1;4.6(a) The followin
UNF - MAP - 2302
25/ Move curr to prev positiontemplate &lt;class Elem&gt;void LList&lt;Elem&gt;:prev() cfw_link* temp = curr;while (temp-&gt;next!=curr) temp=temp-&gt;next;curr = temp;(b) The answer is rather similar to that of Part (a).4.7 The space required by the array-based l
UNF - MAP - 2302
26Chap. 4 Lists, Stacks, and Queues4.10 I assume an int requires 4 bytes, a double requires 8 bytes, and a pointerrequires 4 bytes.(a) Since E = 4 and P = 4, the break-even point occurs when1n = 4D/8 = D.2Thus, the linked list is more space efcien
UNF - MAP - 2302
27AStack2() cfw_ delete [] listArray; / Destructorvoid clear(int st) cfw_if (st = 1) top1 = 0;else top2 = size - 1;bool push(int st, const Elem&amp; item) cfw_if (top1+1 &gt;= top2) return false; / Stack is fullif (st = 1) listarray[top1+] = item;else l
UNF - MAP - 2302
28Chap. 4 Lists, Stacks, and QueueslistArray = new Elem[size];isEmpty = true;AQueue() cfw_ delete [] listArray; / Destructorvoid clear() cfw_ front = rear; isEmpty = true; bool enqueue(const Elem&amp; it) cfw_if (isEmpty != true) &amp;(rear+1) % size) =
UC Irvine - BME - 110A
(I) Short problems, warm up1. Consider the following four matrices:1123411 21 32 642 = ; = 7 8 9 ; = 0 5 6 7 ; = 80 45 36 77 ;3809084 6 96 304Calculate the following:i) inner product between a and Aii) inner product
UC Irvine - ECON - 20B
Econ 20B- Additional Problem Set I. MULTIPLE CHOICES. Choose the one alternative that best completes the statement to answer the question. 1According to the theory of liquidity preference, the money supply a. and money demand are positively related to the
UNF - MAP - 2302
294.15 FIBobj stores a value and an operand type. If the operand is IN, then thevalue is a parameter to the Fibonacci function. If the operand is OUT, thenthe value is an intermediate result. When we pop of an IN value, it mustbe evaluated. When we h
UC Irvine - PHYSICS - 7C
Name (print clearly!):Signature:ID Number:Discussion TA:Discussion Day:Hour:Date:Midterm 1Physics 7C Tait (version 1)Closed book; you may use a calculator, but no other electronic devices,including cell phones, iPods, etc. For full credit, you m
UNF - MAP - 2302
30Chap. 4 Lists, Stacks, and Queuesf.val += val;s.push(f);else cfw_ / switch order to evaluate 2nd operandFIBobj temp;temp.val = val; temp.op = OUT;S.push (f);S.push (temp);return val; / Correct result should be in val now4.16 The stack-bas
UNF - MAP - 2302
314.19 Some additional access capability must be added. One approach is to addmore pointers to the linked list structure. By granting direct access half wayin, from there to the quarter lists, etc., it is possible to gain O(log n) insertand search t
UNF - MAP - 2302
5Binary Trees5.1 Consider a non-full binary tree. By denition, this tree must have some internal node X with only one non-empty child. If we modify the tree to removeX , replacing it with its child, the modied tree will have a higher fraction ofnon-em
UNF - MAP - 2302
335.3 Base Case: For the tree of one leaf node, I = 0, E = 0, n = 0, so thetheorem holds.Induction Hypothesis: The theorem holds for the full binary tree containingn internal nodes.Induction Step: Take an arbitrary tree (call it T) of n internal node
UNF - MAP - 2302
34Chap. 5 Binary Trees5.6 The key is to use a queue to store subtrees to be processed.template &lt;class Elem&gt;void level(BinNode&lt;Elem&gt;* subroot) cfw_AQueue&lt;BinNode&lt;Elem&gt;*&gt; Q;Q.enqueue(subroot);while(!Q.isEmpty() cfw_BinNode&lt;Elem&gt;* temp;Q.dequeue(tem
UNF - MAP - 2302
35x leaf nodes:4x= 4/8 = 50%.4x + 4x5.10 If equal valued nodes were allowed to appear in either subtree, then during asearch for all nodes of a given value, whenever we encounter a node of thatvalue the search would be required to search in both di
UNF - MAP - 2302
365.18Chap. 5 Binary Trees(a) The array will take on the following order:653421The value 7 will be at the end of the array.(b) The array will take on the following order:746321The value 5 will be at the end of the array.5.19 / Min-heap
UNF - MAP - 2302
37swap(Heap, pos, j);pos = j;/ Move downtemplate &lt;class Elem, class Comp&gt;bool minheap&lt;Elem, Comp&gt;:insert(const Elem&amp; val) cfw_if (n &gt;= size) return false; / Heap is fullint curr = n+;Heap[curr] = val;/ Start at end of heap/ Now sift up until c
UNF - MAP - 2302
38Chap. 5 Binary Trees/ Remove value at specified positiontemplate &lt;class Elem, class Comp&gt;bool minheap&lt;Elem, Comp&gt;:remove(int pos, Elem&amp; it) cfw_if (pos &lt; 0) | (pos &gt;= n) return false; / Bad posswap(Heap, pos, -n);/ Swap with last valuewhile (pos
UNF - MAP - 2302
39The average code length is 3.234455.22 The set of sixteen characters with equal weight will create a Huffman codingtree that is complete with 16 leaf nodes all at depth 4. Thus, the average codelength will be 4 bits. This is identical to the xed len
UNF - MAP - 2302
6General Trees6.1 The following algorithm is linear on the size of the two trees./ Return TRUE iff t1 and t2 are roots of identical/ general treestemplate &lt;class Elem&gt;bool Compare(GTNode&lt;Elem&gt;* t1, GTNode&lt;Elem&gt;* t2) cfw_GTNode&lt;Elem&gt; *c1, *c2;if (t
UNF - MAP - 2302
41if (t1-&gt;val() != t2-&gt;val() return false;if (Compare2(t1-&gt;leftchild(), t2-&gt;leftchild()if (Compare2(t1-&gt;rightchild(), t2-&gt;rightchild()return true;if (Compare2(t1-&gt;leftchild(), t2-&gt;rightchild()if (Compare2(t1-&gt;rightchild(), t2-&gt;leftchild)return true
UNF - MAP - 2302
42Chap. 6 General TreesNode0Parent 41424344 -1546470809 10 11 12 13 14 154 9 9 9 12 9 -16.8 For eight nodes labeled 0 through 7, use the following series of equivalences:(0, 1) (2, 3) (4, 5) (6, 7) (4 6) (0, 2) (4 0)This requires ch
UNF - MAP - 2302
43GTNode&lt;Elem&gt;* gtemp = genroot-&gt;leftmost_child();btemp = new BinNode(genroot-&gt;val(), convert(gtemp),convert(genroot-&gt;right_sibling();6.116.12(a)Parent(r) = (r 1)/k if 0 &lt; r &lt; n.Ith child(r) = kr + I if kr + I &lt; n.Left sibling(r) = r 1 if r mod
UNF - MAP - 2302
446.16Chap. 6 General Trees(a) / Use a helper function with a pass-by-reference/ variable to indicate current position in the/ node list.template &lt;class Elem&gt;BinNode&lt;Elem&gt;* convert(char* inlist) cfw_int curr = 0;return converthelp(inlist, curr);
UNF - MAP - 2302
45curr+ / Eat the internal node mark.temp-&gt;left = converthelp(inlist, curr);temp-&gt;right = converthelp(inlist, curr);return temp;(c) / Use a helper function with a pass-by-reference/ variable to indicate current position in the/ node list.template
UNF - MAP - 2302
7Internal Sorting7.1 Base Case: For the list of one element, the double loop is not executed andthe list is not processed. Thus, the list of one element remains unaltered andis sorted.Induction Hypothesis: Assume that the list of n elements is sorted
UNF - MAP - 2302
477.3 The revised algorithm will work correctly, and its asymptotic complexity willremain (n2 ). However, it will do about twice as many comparisons, since itwill compare adjacent elements within the portion of the list already knownto be sorted. Thes
UNF - MAP - 2302
48Chap. 7 Internal Sorting Conceptually (in particular, the linked list version) Mergesort is stable.The array implementations are NOT stable, since, given that the sublistsare stable, the merge operation will pick the element from the lower listbefo
UNF - MAP - 2302
49264013577.9(a) Each call to qsort costs (i log i). Thus, the total cost isni log i = (n2 log n).i=17.107.117.127.13(b) Each call to qsort costs (n log n) for length(L) = n, so the totalcost is (n2 log n).All that we need to do is redene the
UNF - MAP - 2302
50Chap. 7 Internal SortingN7 N8 N9B10B11Again, at each line, there is no information available about the relationshipsof those objects.To merge two such lists, we can do a normal merge, until we reach the pointwere we either compare an element (sa
UNF - MAP - 2302
51Best case: 2 compares.Avg case: 16/6 = 2 2/3 compares.Worst case: 3 compares.(b) Doing a similar approach of building a decision tree for 5 numbersis somewhat overwhelming since there are 120 permutations. A prettygood algorithm can be had be buil
UNF - MAP - 2302
52Chap. 7 Internal SortingSort. Thus, the calls to Insertion Sort are equivalent to the leaf nodes of a fullbinary tree. We know from the Full Binary Tree Theorem that the number ofleaf nodes in a full binary tree of n nodes is n/2 . Thus, if there ar
UNF - MAP - 2302
537.19 There are n possible choices for the position of a given element in the array.Any search algorithm based on comparisons can be modeled using a decisiontree. The tree must have at least n leaf nodes, one for each of the possiblechoices for solut
UNF - MAP - 2302
8File Processing and ExternalSorting8.1 Clearly the prices continue to change. But, the principles remain the same.8.2 The rst question is How many tracks are required by the le? A track holds144 .5K = 72K . Thus, the le requires 5 tracks. The time t
UNF - MAP - 2302
55Latency and read time together require 3.5 8.33 ms. Thus, the time toread the rst track is about 88 ms. The time to read the next three tracks is3 + 2100/3 0.08 + 3.5 8.33 32.2 ms. The last track takes just as longto read since it requires three rot
Georgia Tech - ECE - 3025
Georgia Tech - ECE - 3025
UNF - MAP - 2302
56Chap. 8 File Processing and External Sorting1 2n3 + 3n2 + n 3n2 + 3n(+)=n2662n3 + 6n2 + 4n n/3.6n28.7 The batch method is more efcient when enough sectors are visited to makeprocessing the whole le in sequential order more efcient. Since th
UNF - MAP - 2302
57(b) Cutting the disk I/O time will substantially improve the external sortingtime. A reasonable estimate is that cutting disk I/O time in half will cutthe sorting time by around 1/3.(c) Main memory access time will not help a great deal, since disk
UNF - MAP - 2302
9Searching9.1 The graph shows a straight line from (n + 1)/2 when p0 = 0 to n when p0 =1. Thus, the growth rate in the cost for a search is linear as the probability ofan unsuccessful search increases.9.2 int dictsrch(int array[], int K, int left, in
UNF - MAP - 2302
599.3 At each step, the exponent, call it x, is cut in half. This can only happen log xtimes. Of course, x = log n. Thus, the total cost is O(log log n).9.4 The partition and ndpivot functions remain the same.template &lt;class Elem, class Comp&gt;int fin
UNF - MAP - 2302
60Chap. 9 Searchingelse cfw_count[i]+;while (i &gt; 0) &amp; (count[i] &gt; count[i-1]) cfw_swap(A[i], A[i-1]);swap(count[i], count[i-1]);9.9 template &lt;class Elem&gt;void MoveToFront(Elem A[]) cfw_/ Assume that array is empty to begin withint n = 0;whil
UNF - MAP - 2302
61/ the length of the bit vectors are alwasy a number/ of ints.void inter(int* in1, int* in2, int* out, int n) cfw_for (int i=0; i&lt;n; i+)out[i] = in1[i] &amp; in2[i];/ in1 and in2 are input bit vectors, out is output bit/ vector; n is length of bit ve
UNF - MAP - 2302
62Chap. 9 Searching(c) 379.16 Key: 2 8 31 20 19 18 53 27H1: 2 8 5 7 6 5 1 1H2: 3 9 1 1 2 3 1 5Result of inserting:2 2 OK8 8 OK31 5 OK20 7 OK19 6 OK18 5 Collision. So, try 5+3 = 8. Collision.Then 5+6 = 11. OK53 1 OK27 1 Collision. So, try 1+
UNF - MAP - 2302
63/ Insert e into hash table HTtemplate &lt;class Key, class Elem, class KEComp,class EEComp&gt;bool hashdict&lt;Key, Elem, KEComp, EEComp&gt;:hashInsert(const Elem&amp; e) cfw_int home;/ Home position for eint pos = home = h(getkey(e); / Init probe sequencefor
UNF - MAP - 2302
10Indexing10.110.210.310.410.5(a) A record in the linear index refers to a block of sorted data records.Assuming that the linear index stores a key and a 4 byte block number,the index can hold information for 32K blocks, for a total le size of32
UNF - MAP - 2302
6545678DEERDUCKFROGGOATindex0479111171869(b) seckey2936718392797739primary Nextkeyindex02398113456228133339737-142936557183669279-171111887186-197739-110.6 ISAM is space efcient, more so than the B-