Let T be a heap storing n keys. Give an efficient algorithm for
reporting all
the keys in T that are smaller than or equal to a given query key x
(which is
not necessarily in T). For example, given the heap of Figure 5.6
and query key
x = 7, the algorithm should report 4, 5, 6, 7. Note that the keys
do not need to be
reported in sorted order. Ideally, your algorithm should run in
O(k) time, where
k is the number of keys reported.
Please use psuedocode.
Let T be a heap storing n keys. Give an efficient algorithm for reporting all the...
(Problem C-9.34, page 397 of the text) Given a heap H and a key
k, give an algorithm to compute all the entries in H having keys
less than or equal to k. For example, given the heap in figure
9.12a and query k=7, the algorithm should report the entries with
keys 2, 4, 5, 6, and 7 (but not necessarily in this order). Your
algorithm should run in time proportional to the number of entries
returned, and should not...
6. Give an efficient algorithm to rearrange an array of n keys so that all negative keys precede all nonne- gative keys. Your algorithm must be in-place meaning you cannot allocate another array to temporarily hold the items.
2. (10 pts) Let T be a B-tree with a minimum degree (minimum branching factor) of t that holds n keys. Write the most efficient procedure you can to print the keys of T in sorted order. Then analyze the time complexity of your algorithm. Hint: Extend the procedure for inorder traversal of BST.
2. (10 pts) Let T be a B-tree with a minimum degree (minimum branching factor) of t that holds n keys. Write the most efficient procedure...
We are given a red-black tree T containing n keys and two keys X and Y, key X is stored in node x, wbhile key Y is stored in node y. Give an effective algorithm that determines the smallest key value stored on the path connecting x and y in T. The running time should be O(log n).
(20 points) Suppose you are given a binary search tree T of n nodes (as discussed in class. each node v has v.left, v.right, and v.key). We assume that no two keys in T are equal. Given a value x, the rank operation rank() is to return the rank of x in T, which is defined to be one plus the number of keys of T smaller than 2. For example, if T has 3 keys smaller than r, then...
I need the report like this (idea) *Sorting Algorithms: A sorting algorithm is an algorithm that puts elements of a list in a certain order. The most-used orders are numerical order and lexicographical order. Efficient sorting is important for optimizing the use of other algorithms (such as search and merge algorithms) which require input data to be in sorted lists; it is also often useful for canonical zing data and for producing human-readable output. More formally, the output must satisfy...
1. (10 points) Write an efficient iterative (i.e., loop-based) function Fibonnaci(n) that returns the nth Fibonnaci number. By definition Fibonnaci(0) is 1, Fibonnaci(1) is 1, Fibonnaci(2) is 2, Fibonnaci(3) is 3, Fibonnaci(4) is 5, and so on. Your function may only use a constant amount of memory (i.e. no auxiliary array). Argue that the running time of the function is Θ(n), i.e. the function is linear in n. 2. (10 points) Order the following functions by growth rate: N, \N,...
This is an assignment for my algorithm class which I have written the code partially and only need to complete it by adding a time function that calculates the average running time. We could use any programming language we want so I am using C++. I am including the instruction and my partial code below. Thank you! Implement linearSearch(a,key) and binarySearch( a,key)functions. Part A.In this part we will calculate theaverage-case running time of each function.1.Request the user to enter a...
Psuedocode works! DP is dynamic programming for this
algorithm
Problem 4.2. (Difficulty 3) Seam carving is a real-world application of DP for content- aware image resizing. The simplest way to reduce the size of an image is cropping and scaling, i.e. cutting out parts of the image and scaling down the size. However, cropping leaves visible crop lines of incontinuity while scaling reduces the details of the image. We would like to intelligently reducing the size while accounting for the...
Hey guys I need help with this assignment. However it contains 7
sub-problems to solve but I figured only 4 of them can be solved in
one post so I posted the other on another question so please check
them out as well :)
Here is the questions in this assignment:
Note: Two helper functions Some of the testing codes for the functions in this assignment makes use of the print_dict in_key_order (a dict) function which prints dictionary keyvalue pairs...