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

  Algorithm to categorize problem using big-theta notation

Find a simple algorithm for solving following problem and categorize it using big-theta notation: Divide the group of people into two disjoint subgroups (of arbitrary size) such that difference in total ages.

  Making visual studio.net web application

Make a Visual Studio.NET 2005 web application with 2-aspx forms. Add a Menu control and a Label control to form. Populate the Menu control with data stored in the "Font" column and show your name in the Label control.

  Finding time taken to send packet from source to destination

Think about sending a document of F bytes over a path of Q links. Each link transmits at R bps. The network is lightly loaded so that there are no queuing delays.

  Linear-time algorithm to find odd-length cycle in graph

Give a linear-time algorithm to find an odd-length cycle in a directed graph. You may not suppose that graph is strongly connected.

  Can you find the element of an array

We would like to determine whether a given array A has a majority element, and if so, find the element.

  1 describe the following named usability design principles

1. describe the following named usability design principles and how you applied them in your coursework? consistency

  Use process flow charts procedures and orpolicy statements

Draft a 2-4-page (350 words per page) section that will use process flow charts, procedures, orpolicy statements to articulate the business requirements in terms of specific process or business development needs

  Develop a java application based on the jframe

You are required to write a Java Application that uses an interactive Graphical User Interface (GUI) based on the JFrame class using SWING GUI components.

  Find the middle element in a linked list in one pass

Write a program to check if there is a loop in a linked list. Create a loop in a linked list and use your method 'isLoop' to identify that the loop exists.

  Program to create huffman codes

Write a C++ program to create Huffman codes. Program input is a file called freq.txt (make up your own file for testing) that contains data on the characters in some cleartext file in the form of each character's non-zero frequency of occurrence i..

  An embedded system is a computer system performing

an embedded system is a computer system performing dedicated functions within a larger mechanical or electrical system.

  Compute result for receiver after error detection algorithm

If receiver A receives 101010010011100100011101 and another receiver, B, receives 101011111111100100011101 compute the result for each receiver after error detection algorithm is run?

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