You are on page 1of 2

Algorithms: procedres that take in some values and produce some output.

Example: Sorting problem For example, given the input sequence h31; 41; 59; 26; 41; 58i, a sorting algori thm returns as output the sequence h26; 31; 41; 41; 58; 59i. Such an input sequence is called an instance of the sorting problem. In general, an instance of a problem consists of the input (satisfying whatever constraints are imposed in the proble m statement) needed to compute a solution to the problem. -An algorithm is said to be correct if, for every input instance, it halts with the correct output. We say that a correct algorithm solves the given computational problem. A data structure is a way to store and organize data in order to facilitate access and modifications. No single dat a structure works well for all purposes, and so it is important to know the streng ths and limitations of several of them. Analyzing an algorithm has come to mean predicting the resources that the algori thm requires. Occasionally, resources such as memory, communication bandwidth, or computer hardware are of primary concern, but most often it is computational time that we want to measure. we shall assume a generic oneprocessor, random-access machine (RAM) model of computation as our implementation technology and understand that our algorithms will be implemented as computer programs. In the RAM model, instructions are executed one after another , with no concurrent operations. the best notion for input size is the number of items in the input The running time of an algorithm on a particular input is the number of primitiv e operations executed concentrate on finding only the worst-case running time, that is, the longest running time for any input of size n. We usually consider one algorithm to be more efficient than another if its wordst case running tine has a lower order growth(rate of growth) Many useful algorithms are recursive in structure: to solve a given problem, the y call themselves recursively one or more times to deal with closely related subpr oblems. These algorithms typically follow a divide-and-conquer approach:they break the problem into several subproblems that are similar to the original prob lem but smaller in size, solve the subproblems recursively, and then combine these solutions to create a solution to the original problem.

example of divide and conquer: Divide: Divide the n-element sequence to be sorted into two subsequences of n=2 elements each. Conquer: Sort the two subsequences recursively using merge sort. Combine: Merge the two sorted subsequences to produce the sorted answer. Analyzing divide-and-conquer algorithms We can often describe its running time by a recurrence equation When we look at input sizes large enough to make the order of growth of the running rime relevant, we are studying the asymptotic efficienc y of the algorithm

You might also like