Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

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?

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M91876841
  • Price:- $40

Priced at Now at $40, Verified Solution

Have any Question?


Related Questions in Computer Engineering

What outside resources are available to assist technology

What outside resources are available to assist technology managers in the implementation and maintenance process of IT governances? Outline two resources.

Question when setting quotas for disk space what are the

Question : When setting quotas for disk space, what are the two tools for enabling and configuring quotas? And which of the two are the more flexible? When creating a new share, what is the configuration option that enab ...

What is marketing discipline what is most peoples

What is marketing discipline? What is most people's perception of marketing discipline? Name an organization that has done a great job marketing. What did they do to make you feel this way?

In a competitive market the market demand is qd 60- 6p and

In a competitive market, the market demand is Qd= 60- 6P and the market supply is the Qs= 4P the full economic price under a price ceiling of $3 is:?

A biostatistician is investigating the timenbspt to death

A biostatistician is investigating the time,  T , to death of a mouse exposed to a newly developed pesticide. He finds that the pdf of T is given by the following formula  f(t) = 15t 2 e -5t3 . Which of the following sta ...

The freemont automobile factory has discovered that the

The Freemont Automobile Factory has discovered that the longer a worker has been on the job, the more parts the worker can produce. I need help finding an application that computes and displays a worker's anticipated out ...

Question suppose we have 29 bytes of virtual memory and 27

Question : Suppose we have 29 bytes of virtual memory and 27 bytes of physical main memory. Suppose the page size is 23 bytes. (a) How many pages are there in virtual memory? (b) How many page frames are there in main me ...

Asses the challenges faced by financial managers due to

Asses the challenges faced by financial managers due to changes in the macroeconomic environment and how these impact businesses operations. Emphasize how there are consequences related to changes in strategies and prior ...

Write a c functionnbspescapechar s char tnbspthat converts

Write a C function escape(char s[], char t[]) that converts the characters newline and tab into two character sequences n and t as it copies the string t to the string s. Use the C switch statement. Also write the revers ...

Below is a simple data gird with a header

Below is a simple data gird with a header row. kim|taylor|clara|654 763 1345|75|2016-01-17|null|N|90.76|A jack|jenkins|joseph|630 654 0265|92|2016-11-30|null|Y|131.00|B Identify what rules would you apply for ensuring th ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As