Draw the dictionary data structure obtained after inserting

Assignment Help Data Structure & Algorithms
Reference no: EM131119277

Questions 1. Consider the following code for finding a maximum element in an array:

// Find a maximum element in the array A. findMax(A) findMaxHelper(A, 0, A.length)//

Return the maximum element in A[left...right-1] findMaxHelper(A, left, right) if left == right - 1 return A[left] else { max1 = findMaxHelper(A, left, (right + left) / 2) max2 = findMaxHelper(A, (right + left) / 2, right) if max1 > max2 return max1 else return max2 }

(a) Let n be the length of the parameter A, where n ≥ 1. Let T(n) be the run time of this algorithm. Express T(n) as a recurrence relation. Use repeated substitution (ignore floors/ceilings when calculating n/2) to determine a closed-form solution for T(n) (i.e., express T(n) as a non-recursive function of n with no summations.

(b) Use induction to prove that this code correctly returns the maximum element in the array (again, where the array is of length at least 1). 1 2. We want to prove that the following function ss sorts the first n elements of array x. void ss( int *x, int n ) { int i = 0; while( i < n-1 ) { // A // int iom = i; int j = i+1; while( j < n ) { // B // if( x[j] < x[iom] ) iom = j; j++; } swap(x[i], x[iom]); i++; } }

(a) State an appropriate loop-invariant for location B in the code and prove that it is true.

(b) State an appropriate loop-invariant for location A in the code and prove that it is true, using your invariant from B.

(c) Prove that the code sorts the first n elements of array x, using the two invariants.

3. A room contains 6 computers. Each computer is directly connected to 0 or more of the other computers in the room. Show that there are at least two computers in the room that are directly connected to the same number of other computers. Hint: You might first try the problem assuming each computer is directly connected to 1 or more of the other computers.

4. I want to place red, green, blue, and yellow balls into eight buckets so that no matter which four buckets I choose, one contains a red ball, another contains a green ball, a third contains a blue ball, and the final one contains a yellow ball. Each bucket might contain other balls as well. Find the least number of balls (in total) that I need to achieve this. Prove that your answer is correct (i.e., show how to do it with that number and why it can't be done with fewer).

Hint: This is not an application of the Generalized Pigeonhole Principle but it uses the same techniques.

5. Draw the Dictionary data structure obtained after inserting: 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 93, 97, 96 one after the other into the following initially empty structures.

(a) A Hash Table of size 11 that uses chaining (with unsorted linked-list chains, insert items at the front of the chain). Use hash function hash(k) = k mod 11.

(b) A Hash Table of size 23 that uses open addressing with double hashing. The first hash function is: hash1(k) = k mod 23. The second is: hash2(k) = 13-(k mod 13). For each key, indicate the table slots probed.

(c) A B+-Tree with M = 5 and L = 3. When nodes split, put half of the items on the left and half on the right, and put the extra item on the left if there is one. Draw the tree after every insertion that causes a split as well as the final tree.

(d) A B+-Tree with M = 100 and L = 20. Draw the tree after every insertion that causes a split as well as the final tree.

6. Professor Twiddle decides to implement AVL trees without left and right child pointers by using the same trick we used for heaps: store the tree nodes in an array so that the node stored at index i has its left child at index 2i + 1 and its right child at index 2i + 2. Brilliant! except that many of the array locations might be empty because an AVL tree may not be nearly complete.

Your task is to determine if Professor Twiddle's method is always more space efficient (for large enough AVL trees).

(a) Let N(h) be the smallest number of nodes in an AVL tree of height h. For example, N(0) = 1 and N(1) = 2. Write a recurrence relation for N(h).

(b) Solve your recurrence relation to express N(h) as a function of some Fibonacci number.

(c) At this point, you should know (using what you know about Fibonacci numbers) that if an AVL tree has n nodes then its height can be ≈ 1.44 log2 n. Approximately what size array is required by Professor Twiddle's heap-like data structure to store an n node AVL tree in the worst case? Does Professor Twiddle's method always save space? Why or why not?

Reference no: EM131119277

Questions Cloud

How does the concept of substantial performance : How does the concept of “substantial performance” apply to accounting for franchise sales?
Which design has dorothy employed : Sharon wanted to investigate student perceptions of homework. First, she distributed a survey to students and their parents and collected quantitative data. Second, she interviewed a few participants to gain insights on their survey responses. Whi..
More heavily involved in the consumer protection laws : Class, this week we get more heavily involved in the consumer protection laws and maybe we will even get into discussing whether or not they are effective. The best (or worst) part of this threaded discussion is that we will see that the warnings whi..
Why in franchise arrangements may it not be proper : Why in franchise arrangements may it not be proper to recognize the entire franchise fee as revenue at the date of sale?
Draw the dictionary data structure obtained after inserting : Draw the Dictionary data structure obtained after inserting: 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 93, 97, 96 one after the other into the following initially empty structures.
Summarize the facts in narrative or outline form : Summarize the facts in narrative or outline form. These should include the most important and pertinent incidents in the situation. Do not simply restate the entire case
How much revenue should livesey company report : The costs cannot be reliably estimated. How much revenue should Livesey Company report in the first year under iGAAP?
What are the benefits of engaging in strategic planning : What are the major costs or problems in doing strategic planning in your organization?
Electronic commerce and the social enterprise : Module 4 introduces online presence for business and information security policies. E-commerce can result in a radical change in the manner business operate, but it needs to be integrated with the rest of the business.

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Declare a double array

Question 1: Declare a double array of size 100. Question 2: Fill out the array with 1 if a random value is greater than 0.5 else 0 Question 3: print the number of 0's in the array .

  Truth teller problem

Assume you were in a nation where each person was either a truth teller or a liar. Determine what single question could you ask a person that would permit you to detect whether that person was a truth teller or a liar?

  Implement the boyer-moore algorithm using any program

Implement the Boyer-Moore algorithm using any programming language you prefer.

  Developing an eer model

Construct an EER model for the given situation using the traditional EER notation, the Visio notation or the supertypes notation.

  Relationships in a database model

Discuss different types of classifications and do they overlap, or do they each tell us something unique about the entity relationship?

  Complete binary tree

Think about an n-node complete binary tree T, where n=2^d - 1 for some d. Each node v of T is labeled with a real number x_v.

  Design an algorithm (no code) just using if-then statement

Provide an example of an input string that is in the proper format and an example that is not in the proper format. Describe how your algorithm determines that the first string is in the proper format and that the second string is not in proper fo..

  Portfolio planning using optimization

Set this problem up as a linear programming model in Excel, and use Solver to determine how the $10 million should be invested. What is the overall return (in dollars terms)

  Diameter bounded minimum spanning tree of graph by prim-s

Modify Prim's or Kruskal's algorithm to determine diameter bounded minimum spanning tree of complete graph. A diameter bounded minimum spanning tree is spanning tree.

  Explain dynamic array as big oh in terms of n

If we presently have n items in the dynamic array, how many doubling operations will we have executed so far? Explain this as Big Oh in terms of n.

  Question about database administration

Should the data administrator really be on the same level as the DBA, generally somewhat low in corporate hierarchy or should this person have an elevated level of importance?

  Polynomial time algorithm for rooted directed acyclic graphs

Illustrate that if you were given a polynomial time algorithm for determining whether two rooted directed acyclic graphs are isomorphic, then polynomial time algorithm for testing.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd