Question

In: Computer Science

In all algorithm, always explain how and why they work. ALWAYS, analyze the complexity of your...

In all algorithm, always explain how and why they work. ALWAYS, analyze the complexity of your algorithms. In all algorithms, always try to get the fastest possible. A correct algorithm with slow running time may not get full credit. In all data structures, try to minimize as much as possible the running time of any operation.

1.Show that if a binary tree has a vertex with a single child, then this can not be an optimal Huffman tree.

2. Question 2: Say that the input for an Huffman coding contains 256 letters. Each appearing the the same number of times. (a) If we choose to code all letters by codes of the same length, what is the number of bits required? (b) Is the Huffman code better than the code of the first item?

3. Question 3: Say that we code 256 different letters. Let num(X) be the number of times an arbitrary letter appears in the text . Assume that for every X and Y both num(Y ) > num(X)/2 and num(X) > num(Y)/2 hold. Is the ASCII (8 bits) code worse than the Huffman code in this case?

Solutions

Expert Solution

Answer;

Below is the recursive algorithm which performs the desired task. In this algorithm name "find(root,height,number_of_nodes, h)", root is the pointer to root of present subtree, variable height and number_of_nodes are passed by reference such that we are updating the value of vairable height and variable number_of_nodes as per the result returned in recursive call and this value change in recursive call will be reflected in original call.

Also in below algorithm, we are checking if height of a particular subtree is equal to h or not. If height is equal to h, then we are updating the vairable maximum_nodes accordingly.*********THE END********** Please vote


Related Solutions

Q1. In all algorithm, always explain how and why they work. If not by a proof,...
Q1. In all algorithm, always explain how and why they work. If not by a proof, at least by a clear explanation. ALWAYS, analyze the running time complexity of your algorithms. Do not write a program. Write pseudo codes or explain in words. (A) Find an efficient data structure supporting the following operations. Insert(S, x), Delete−Max(S), and Delete−100'th(S) which deletes from H the 100 largest element in the structure. Assume that the number of elements is more than 100. Also...
For each algorithm, always explain how and why they work. If not by a proof, at...
For each algorithm, always explain how and why they work. If not by a proof, at least by a clear explanation. ALWAYS, analyze the running time complexity of your algorithms. Do not write a program. Write pseudo codes or explain in words Q2: Give a data structure that implements a Min-Heap and the command Max(S) that returns the maximum in the heap. Try and make the last operation as fast as possible. Q3: (a)Show how to implement a Queue by...
DATA STRUCTURES: For each algorithm, always explain how and why they work. If not by a...
DATA STRUCTURES: For each algorithm, always explain how and why they work. If not by a proof, at least by a clear explanation. ALWAYS, analyze the running time complexity of your algorithms. Do not write a program. Write pseudo codes or explain in words Q1: We want to maintain both a Queue and a Priority Queue. When you do Enqueue you also add the item to the Priority Queue and when you do Dequeue you also remove the item from...
Is mixed methods research worth all of the extra work and complexity? Why, or why not?
Is mixed methods research worth all of the extra work and complexity? Why, or why not?
Give the asymptotic (“big-Oh”) running time complexity of the following algorithm, show all the work you...
Give the asymptotic (“big-Oh”) running time complexity of the following algorithm, show all the work you have done. Algorithm: ArrayMangle(A[ ], int n) Input: an array A, an integer n x = 0; for (i=0; i<=n-1; i++) { for (j=i; j<=n-1; j++) { x = x + A[j]; } for (k=0; k<= n-1; k++) { for (j=0; j< =n-1; j++) { x = x + A[j]*A[k]; } } }
1. Mathematically analyze the given Recurrence Relation and find out the time complexity of the algorithm....
1. Mathematically analyze the given Recurrence Relation and find out the time complexity of the algorithm. T(n) = T(n-1)+1 , if n> 0 1 if n = 0
Calculate the time complexity of each algorithm for best, worst and average cases. Give all steps...
Calculate the time complexity of each algorithm for best, worst and average cases. Give all steps of your calculation and results in Big-O notation. algorithm : Selection Sort Bubble Sort Insertion Sort
Implement 2-D peak finder and explain the asymptotic complexity of the algorithm For Design and Analysis...
Implement 2-D peak finder and explain the asymptotic complexity of the algorithm For Design and Analysis of the Algorithme lecture
Analyze the algorithm experimentally. a)Implement the algorithm b)Let p be the string length at which your...
Analyze the algorithm experimentally. a)Implement the algorithm b)Let p be the string length at which your program takes 2 seconds to run, collect running times for your algorithm using the following string lengths: p/4, 2p/4, 3p/4, p, 5p/4, 6p/4, 7p/4, 2p. c)Generate your strings by reading the attached file, only reading as many characters as you need. d)Plot your results (x-axis is string length, y-axis should be time) e)Draw conclusions based on your graph. You may also need to plot...
Explain how does Baker’s algorithm works? Explain all the types of pointers it has and their...
Explain how does Baker’s algorithm works? Explain all the types of pointers it has and their complete functions. [25 points]
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT