Algorithm design manual wiki




















Hint: think in terms of using the abstract dictionary operations, instead of mucking about with pointers and the like. A concatenate operation takes two sets S1 and S2, where every key in S1 is smaller than any key in S2, and merges them together.

Give an algorithm to concatenate two binary search trees into one binary search tree. The worst-case running time should be O h , where h is the maximal height of the two trees. In the bin-packing problem, we are given n metal objects, each weighing between zero and one kilogram.

Our goal is to find the smallest number of bins that will hold the n objects, with each bin holding one kilogram at most.

Suppose that we are given a sequence of n values x1,x2, …, xn and seek to quickly answer repeated queries of the form: given i and j, find the smallest value in xi,…,xj. For partial credit, your data structure can use O nlogn space and have O logn query time.

Suppose you are given an input set S of n numbers, and a black box that if given any sequence of real numbers and an integer k instantly and correctly answers whether there is a subset of input sequence whose sum is exactly k. Show how to use the black box O n times to find a subset of S that adds up to k. Let A[ Design an algorithm to perform any sequence of the following operations:. There are no insertions or deletions; the only change is to the values of the numbers. Each operation should take O logn steps.

You may use one additional array of size n as a work space. Extend the data structure of the previous problem to support insertions and deletions. Each element now has both a key and a value. An element is accessed by its key. The addition operation is applied to the values, but the elements are accessed by its key. The Partial sum operation is different. Design a data structure that allows one to search, insert, and delete an integer X in O 1 time i. Hint: use two arrays A[ You are not allowed to initialize either A or B, as that would take O m or O n operations.

Could not load tags. Latest commit. Git stats commits. Failed to load latest commit information. View code. Remove all global variables. Converted original test cases, included in test-script, into set of nosetests. Implemented generic Graph data structure to cover unweighted, weights, flow graph instances. Propose a replication scheme to minimize data loss as nodes fail. What is the expected number of data entries that get lost when three random nodes fail?

Consider the following algorithm to find the minimum element in an array of numbers. One extra variable tmp is allocated to hold the current minimum value.

You have a story building and a couple of marbles. You must identify the lowest floor for which a marble will break if you drop it from this floor. How fast can you find this floor if you are given an infinite supply of marbles?

What if you have only two marbles? You are given 10 bags of gold coins. Nine bags contain coins that each weigh 10 grams. One bag contains all false coins that weigh one gram less. I assume the reader has completed the equivalent of a second programming course, typically titled Data Structures or Computer Science II. The book, and associated supporting material, stresses design over analysis.

A full set of lecture slides integrated with audio and video lectures are freely available on line. Let me help teach your course! I have made several pedagogical improvements throughout the book. Textbook-oriented features include: More Leisurely Discussion -- The tutorial material in the first part of the book has been doubled over the previous edition.

The pages have been devoted to more thorough and careful exposition of fundamental material, instead of adding more specialized topics. False Starts -- Algorithms textbooks generally present important algorithms as a fait accompli, obscuring the ideas involved in designing them and the subtle reasons why other approaches fail. The war stories illustrate such development on certain applied problems, but I have expanded such coverage into classical algorithm design material as well.



0コメント

  • 1000 / 1000