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

  What do these two indexes represent

What do these two indexes represent - what are the limits for each one of these indexes?

  Object oriented approach versus the relational database

Supporters of object oriented databases list many benefits for using the object oriented approach versus the relational one.

  Opens an output file with the external name

Design an algorithm that does the following: opens an output file with the external name number_list.dat, uses a loop to write the numbers 1 through 100 to the file and then closes the file.

  How to access virtualised applications through unicore

How to access virtualised applications through UNICORE

  Create algorithm which takes as inputs matrices

Create the algorithm which takes as inputs, matrices C, D, and vertex indices i and j, and returns minimum-cost path from vertex i to vertex j.

  Data analysis and application template

Data Analysis and Application Template.

  What is the logarithm base-2 of zero? of one

What is the logarithm base-2 of zero? of one?

  Convert the following expression in postfix

Convert the following expression in postfix (reverse Polish notation). Remember the rules of precedence for arithmetic operators. To get full credit, you need to show all work done. i.e. sample snapshot of the stack

  Explain the fundamental concepts of cryptographic algorithms

Explain the fundamental concepts of cryptographic algorithms. Examine malicious activities that may affect the security of a computer program and justify the choice of various controls to mitigate threats.

  Write an algorithm that converts a decimal number

Write an algorithm that converts a decimal number between 0 and 15 into its 4 bit unsigned binary representation.

  Develop a sequential flow diagram

Develop a sequential flow diagram and a sequential VI in LabVIEW that illustrates how to solve the following problem, and provides a correct solution.

  What are some of the critical differences

When you start a new project, what are the essential tasks you take care or start with?

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