Largest number of times

Assignment Help Basic Computer Science
Reference no: EM13844158

1. Consider a sorted list L of n integers, each of which must be distinct (that is, the list contains no duplicates). L may contain negative elements. Give an algorithm (describe in English, and then give pseudo-code) that finds all indicies i such that L[i] = i. Your algorithm should run in O(lg n + k) time, where k is the number of elements i such that L[i] = i.

2. In Randomized-Quicksort of a list of length n, what is the largest number of times that RANDOM will be called? What is the smallest possible number of times that RANDOM will be called? Be as exact as possible.

3. Consider the following sorting algorithm:

TripleSort(A, low, high)
if (high > low)
if (high == low + 1)
if (A[low] > A[high])
swap A[low] ↔ A[high]
else
mid1 ← d(low + high) / 3e
mid2 ← b 2 * (low + high) / 3 c
TripleSort(A, low, mid2)
TripleSort(A, mid1, high)
TripleSort(A, low, mid2)

(a) Does this sorting algorithm correctly sort all lists? Explain why, or give a counter-example.

(b) Is this sorting algorithm stable? Explain your answer for full credit

(c) Give a recurrence relation for the running time of TripleSort, solve it to provide a tight (Θ()) bound.

4. The quicksort PARTITION procedure divides returns an index q such that each element of A[p..q - 1] is less than or equal to q, and each element of A[q + 1..r] is greater than A[q]. Modify the partition procedure to produce a procedure PARITION'(A,p,r) which returns two indices q and t. where p ≤ q ≤ t ≤ r, such that:

• All elements of A[q..t] are equal
• All elements of A[p..q - 1] are less than A[q]
• All elements of A[t + 1..r] are greater than A[q]

Give pesudo-code for PARTITION'. You can assume that a function can return two values a and b with return (a,b). For full credit, your algorithm must take time Θ(n) and extra space (beyond the actual array) Θ(1).

5. Which of the following sorting algorithms are stable: insertion, merge, heap, quick. Give a simple scheme that makes any sorting algorithm stable. How much additional time does your sorting algorithm require?

Reference no: EM13844158

Questions Cloud

Analysis of the organization : Analysis of the organization, Describe the organization's: Facility physical settings, Patient or client base, Level of clinical activity, Organization structure
The lower breakeven and greater profit potential : Consider two put options differing only by exercise price. The one with the higher exercise price has Select one: a. the lower breakeven and lower profit potential b. the lower breakeven and greater profit potential c. the higher breakeven and gre..
Discuss types of sources a company can use to raise capital : Discuss the types of sources a company can use to raise capital. Do these different sources of capital have different costs? Why or why not?
Compare and contrast how you would expect nursing leaders : Select an issue from the following list: nursing shortage and nurse turn-over, nurse staffing ratios, unit closures and restructuring, use of contract employees (i.e., registry and travel nurses), continuous quality improvement and patient satisfa..
Largest number of times : In Randomized-Quicksort of a list of length n, what is the largest number of times that RANDOM will be called? What is the smallest possible number of times that RANDOM will be called? Be as exact as possible.
What decision does the expected value approach recommend : What decision does the expected value approach recommend and what is your indifference probability for the $0.00 payoff?
Which of cash flows would be included in capital budgeting : If the Felicia & Fred decide to purchase the building, which of the above cash flows would be included in the capital budgeting analysis? If the company decided not to purchase the building, how would your answer change?
Estimate the probability that it is private insurance : Estimate the probability that it is private insurance
Describe an example of a psychic prison : Describe an example of a "psychic prison" you or a colleague have experienced in your organization or one with which you are familiar

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

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