# FUNDAMENTAL OF DATA STRUCTURE IN C++ HOROWITZ PDF

- Contents:

PDF | On Jan 1, , Ellis Horowitz and others published Fundamentals of Data Structure in C++. This is a free version of Fundamentals of Data Structures in C++. Enjoy and Remember me in your Prayers. Good Luck!. [Matching item] Fundamentals of data structures in C Ellis Horowitz, Sartaj Sahni, Susan Anderson-Freed. New York Computer Science Press. - 2nd ed.

Author: | DAMIEN HEIDTBRINK |

Language: | English, German, Japanese |

Country: | El Salvador |

Genre: | Lifestyle |

Pages: | 472 |

Published (Last): | 24.02.2016 |

ISBN: | 262-9-62092-347-3 |

ePub File Size: | 16.50 MB |

PDF File Size: | 15.15 MB |

Distribution: | Free* [*Sign up for free] |

Downloads: | 41259 |

Uploaded by: | ALPHA |

Get this from a library! Fundamentals of data structures in C++. [Ellis Horowitz; Sartaj Sahni; Dinesh P Mehta]. Fundamentals: Table of Contents tisidelaso.ml Fundamentals of Data Structures by Ellis Horowitz and Sartaj Sahni PREFACE CHAPTER 1. PDF generated using the open source mwlib toolkit. Fundamental Data algorithms, to classify and evaluate data structures, and to formally describe the type .. Many modern programming languages, such as C++ and Java, come with.

Good Luck! SlideShare Explore Search You. Submit Search. Successfully reported this slideshow. We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime. Upcoming SlideShare. Like this document? Why not share! Fundamentals of data structures e Embed Size px. Start on.

Show related SlideShares at end. WordPress Shortcode. Munawar Ahmed , Web Developer at student Follow. Published in: Different situations call for different decisions, but we suggest you eliminate the idea of working on both at the same time. If you do decide to scrap your work and begin again, you can take comfort in the fact that it will probably be easier the second time. In fact you may save as much debugging time later on by doing a new version now.

This is a phenomenon which has been observed in practice. The graph in figure 1. For each compiler there is the time they estimated it would take them and the time it actually took. For each subsequent compiler their estimates became closer to the truth, but in every case they underestimated.

Unwarrented optimism is a familiar disease in computing. But prior experience is definitely helpful and the time to build the third compiler was less than one fifth that for the first one. Figure 1. Verification consists of three distinct aspects: program proving, testing and debugging. Each of these is an art in itself. Before executing your program you should attempt to prove it is correct. Proofs about programs are really no different from any other kinds of proofs, only the subject matter is different.

If a correct proof can be obtained, then one is assured that for all possible combinations of inputs, the program and its specification agree. Testing is the art of creating sample data upon which to run your program.

If the program fails to respond correctly then debugging is needed to determine what went wrong and how to correct it. One proof tells us more than any finite amount of testing, but proofs can be hard to obtain. Many times during the proving process errors are discovered in the code. The proof can't be completed until these are changed.

This is another use of program proving, namely as a methodology for discovering errors. Finally there may be tools available at your computing center to aid in the testing process.

One such tool instruments your source code and then tells you for every data set: i the number of times a statement was executed, ii the number of times a branch was taken, iii the smallest and largest values of all variables.

As a minimal requirement, the test data you construct should force every statement to execute and every condition to assume the value true and false at least once. One thing you have forgotten to do is to document. But why bother to document until the program is entirely finished and correct? Because for each procedure you made some assumptions about its input and output.

If you have written more than a few procedures, then you have already begun to forget what those assumptions were. If you note them down with the code, the problem of getting the procedures to work together will be easier to solve. The larger the software, the more crucial is the need for documentation. The previous discussion applies to the construction of a single procedure as well as to the writing of a large software system. Let us concentrate for a while on the question of developing a single procedure which solves a specific task.

The design process consists essentially of taking a proposed solution and successively refining it until an executable program is achieved.

The initial solution may be expressed in English or some form of mathematical notation. In this book we will deal strictly with programs that always terminate. Hence, we will use these terms interchangeably.

An algorithm can be described in many ways. A natural language such as English can be used but we must be very careful that the resulting instructions are definite condition iii. An improvement over English is to couple its use with a graphical form of notation such as flowcharts. This form places each processing step in a "box" and uses arrows to indicate the next step.

Different shaped boxes stand for different kinds of operations. All this can be seen in figure 1. The point is that algorithms can be devised for many common activities. Have you studied the flowchart? Then you probably have realized that it isn't an algorithm at all! Which properties does it lack? Returning to our earlier definition of computer science, we find it extremely unsatisfying as it gives us no insight as to why the computer is revolutionizing our society nor why it has made us re-examine certain basic assumptions about our own role in the universe.

While this may be an unrealistic demand on a definition even from a technical point of view it is unsatisfying. The definition places great emphasis on the concept of algorithm, but never mentions the word "data". If a computer is merely a means to an end, then the means may be an algorithm but the end is the transformation of data.

That is why we often hear a computer referred to as a data processing machine. Raw data is input and algorithms are used to transform it into refined data. So, instead of saying that computer science is the study of algorithms, alternatively, we might say that computer science is the study of data: Figure 1.

Flowchart for obtaining a Coca-Cola There is an intimate connection between the structuring of data, and the synthesis of algorithms. In fact, a data structure and an algorithm should be thought of as a unit, neither one making sense without the other.

For instance, suppose we have a list of n pairs of names and phone numbers a1,b1 a2,b2 , This task is called searching. Just how we would write such an algorithm critically depends upon how the names and phone numbers are stored or structured.

One algorithm might just forge ahead and examine names, a1,a2,a3, This might be fine in Oshkosh, but in Los Angeles, with hundreds of thousands of names, it would not be practical. If, however, we knew that the data was structured so that the names were in alphabetical order, then we could do much better. We could make up a second list which told us for each letter in the alphabet, where the first name with that letter appeared.

For a name beginning with, say, S, we would avoid having to look at names beginning with other letters. So because of this new structure, a very different algorithm is possible. Other ideas for algorithms become possible when we realize that we can organize the data as we wish. We will discuss many more searching strategies in Chapters 7 and 9. Therefore, computer science can be defined as the study of data, its representation and transformation by a digital computer.

The goal of this book is to explore many different kinds of data objects. For each object, we consider the class of operations to be performed and then the way to represent this object so that these operations may be efficiently carried out. This implies a mastery of two techniques: The pedagogical style we have chosen is to consider problems which have arisen often in computer applications.

For each problem we will specify the data object or objects and what is to be accomplished. After we have decided upon a representation of the objects, we will give a complete algorithm and analyze its computing time. After reading through several of these examples you should be confident enough to try one on your own. There are several terms we need to define carefully before we proceed. These include data structure, data object, data type and data representation.

These four terms have no standard meaning in computer science circles, and they are often used interchangeably. A data type is a term which refers to the kinds of data that variables may "hold" in a programming language. With every programming language there is a set of built-in data types. This means that the language allows variables to name data of that type and. Some data types are easy to provide because they are already built into the computer's machine language instruction set.

Integer and real arithmetic are examples of this. Other data types require considerably more effort to implement. In some languages, there are features which allow one to construct combinations of the built-in types.

However, it is not necessary to have such a mechanism. All of the data structures we will see here can be reasonably built within a conventional programming language. Data object is a term referring to a set of elements, say D. Thus, D may be finite or infinite and if D is very large we may need to devise special ways of representing its elements in our computer. The notion of a data structure as distinguished from a data object is that we want to describe not only the set of objects, but the way they are related.

Saying this another way, we want to describe the set of operations which may legally be applied to elements of the data object. This implies that we must specify the set of operations and show how they work. To be more precise lets examine a modest example. The following notation can be used: SUCC stands for successor. The rules on line 8 tell us exactly how the addition operation works. For example if we wanted to add two and three we would get the following sequence of expressions: In practice we use bit strings which is a data structure that is usually provided on our computers.

But however the ADD operation is implemented, it must obey these rules. Hopefully, this motivates the following definition.

## Fundamentals Of Data Structures In C++

A data structure is a set of domains , a designated domain , a set of functions and a end. It is called abstract precisely because the axioms do not imply a form of representation. Our goal here is to write the axioms in a representation independent way.

Thus we say that integers are represented by bit strings. We might begin by considering using some existing language. But at the first stage a data structure should be designed so that we know what it does. Another way of viewing the implementation of a data structure is that it is the process of refining an abstract data type until all of the operations are expressible in terms of directly executable functions.

An implementation of a data structure d is a mapping from d to a set of other data structures e. Though some of these are more preferable than others. This division of tasks. This mapping specifies how every object of d is to be represented by the objects of e. In current parlance the triple is referred to as an abstract data type. Furthermore it is not really necessary to write programs in a language for which a compiler exists.

We would rather not have any individual rule us out simply because he did not know or. The triple denotes the data structure d and it will usually be abbreviated by writing In the previous example The set of axioms describes the semantics of the operations. Thus we would have to make pretense to build up a capability which already exists. First of all. The form in which we choose to write the axioms is important. Instead we choose to use a language which is tailored to describing the algorithms we want to write.

The way to assign values is by the assignment statement variable expression. Several cute ideas have been suggested.

## snowmotuanre.tk

In addition to the assignment statement. Several such statements can be combined on a single line if they are separated by a semi-colon. Expressions can be either arithmetic.. In order to produce these values. In the boolean case there can be only one of two values..

Most importantly. The meaning of this statement is given by the flow charts: Though this is very interesting from a theoretical viewpoint. S is as S1 before and the meaning is given by It is well known that all "proper" programs can be written using only the assignment.

To accomplish iteration.. If S1 or S2 contains more than one statement. Brackets must be used to show how each else corresponds to one if. So we will provide other statements such as a second iteration statement. On the contrary. This result was obtained by Bohm and Jacopini. One of them is while cond do S end where cond is as before. Another iteration statement is loop S forever which has the meaning As it stands.

One way of exiting such a loop is by using a go to label statement which transfers control to "label. A more restricted form of the go to is the command exit which will cause a transfer of control to the first statement after the innermost loop which contains it.

This looping statement may be a while.. The semantics is easily described by the file: We can write the meaning of this statement in SPARKS as vble fin incr start finish increment 0 do start to finish by increment do while vble.. It has the form where the Si. A variable or a constant is a simple form of an expression. A procedure may be invoked by using a call statement call NAME parameter list Procedures may call themselves.

The else clause is optional. The execution of an end at the end of procedure implies a return. Though recursion often carries with it a severe penalty at execution time. This may be somewhat restrictive in practice. All procedures are treated as external. The expr may be omitted in which case a return is made to the calling procedure.

Parameters which are constants or values of expressions are stored into internally generated words whose addresses are then passed to the procedure. Many such programs are easily translatable so that the recursion is removed and efficiency achieved. The association of actual to formal parameters will be handled using the call by reference rule. This penalty will not deter us from using recursion.

This means that at run time the address of each parameter is passed to the called procedure. This is a goal which should be aimed at by everyone who writes programs. These are often useful features and when available they should be used. We avoid the problem of defining a "format" statement as we will need only the simplest form of input and output.. See the book The Elements of Programming Style by Kernighan and Plauger for more examples of good rules of programming.

The command stop halts execution of the currently executing procedure. Comments may appear anywhere on a line enclosed by double slashes.. An n-dimensional array A with lower and upper bounds li.. We have avoided introducing the record or structure concept. The SPARKS language is rich enough so that one can create a good looking program by applying some simple rules of style. Avoid sentences like ''i is increased by one. It is often at this point that one realizes that a much better program could have been built.

But to improve requires that you apply some discipline to the process of creating programs. Assume that these operations already exist in the form of procedures and write an algorithm which solves the problem according to the requirements.

Designing an algorithm is a task which can be done independently of the programming language you eventually plan to use.

One of the criteria of a good design is file: Use a notation which is natural to the way you wish to describe the order of processing. If you have been careful about keeping track of your previous work it may not be too difficult to make changes. You should consider alternatives. In fact. Can you think of another algorithm?

If so. Make sure you understand the information you are given the input and what results you are to produce the output.

## Fundamental Data Structures

You are now ready to proceed to the design phase. This method uses the philosophy: It may already be possible to tell if one will be more desirable than the other. To understand this process better. The order in which you do this may be crucial.

Modern pedagogy suggests that all processing which is independent of the data representation be written out first. Perhaps you should have chosen the second design alternative or perhaps you have spoken to a friend who has done it better. By postponing the choice of how the data is stored we can try to isolate what operations depend upon the choice of data representation. For each object there will be some basic operations to perform on it such as print the maze.

Try to write down a rigorous description of the input and output which covers all cases. You must now choose representations for your data objects a maze as a two dimensional array of zeros and ones.

Finally you produce a complete version of your first program. If you can't distinguish between the two. You may have several data objects such as a maze. We hope your productivity will be greater. This happens to industrial programmers as well. The larger the software. The proof can't be completed until these are changed.

The previous discussion applies to the construction of a single procedure as well as to the writing of a large software system. Verification consists of three distinct aspects: Before executing your program you should attempt to prove it is correct.. Unwarrented optimism is a familiar disease in computing. This shifts our emphasis away from the management and integration of the file: One thing you have forgotten to do is to document.

Different situations call for different decisions. One such tool instruments your source code and then tells you for every data set: As a minimal requirement. Proofs about programs are really no different from any other kinds of proofs. B and C. If the program fails to respond correctly then debugging is needed to determine what went wrong and how to correct it.

Testing is the art of creating sample data upon which to run your program. For each subsequent compiler their estimates became closer to the truth.

It is usually hard to decide whether to sacrifice this first attempt and begin again or just continue to get the first version working. But why bother to document until the program is entirely finished and correct? Because for each procedure you made some assumptions about its input and output.

The graph in figure 1. In fact you may save as much debugging time later on by doing a new version now. If you note them down with the code. Each of these is an art in itself.

If you do decide to scrap your work and begin again. For each compiler there is the time they estimated it would take them and the time it actually took. Finally there may be tools available at your computing center to aid in the testing process.

Let us concentrate for a while on the question of developing a single procedure which solves a specific task. Many times during the proving process errors are discovered in the code. This is a phenomenon which has been observed in practice. If you have written more than a few procedures.

**READ ALSO:**

*UF4007 DIODE DATASHEET EPUB DOWNLOAD*

This is another use of program proving. But prior experience is definitely helpful and the time to build the third compiler was less than one fifth that for the first one. One proof tells us more than any finite amount of testing. If a correct proof can be obtained. This latter problem can be solved by the code file: Each subtask is similarly decomposed until all tasks are expressed within a programming language.

This is referred to as the bottom-up approach. The design process consists essentially of taking a proposed solution and successively refining it until an executable program is achieved. The initial solution may be expressed in English or some form of mathematical notation. Suppose we devise a program for sorting a set of n given by the following 1 distinct integers. A look ahead to problems which may arise later is often useful. This method of design is called the top-down approach.

At this level the formulation is said to be abstract because it contains no details regarding how the objects will be represented and manipulated in a computer. If possible the designer attempts to partition the solution into logical subtasks. We are now ready to give a second refinement of the solution: One solution is to store the values in an array in such a way that the i-th integer is stored in the i-th array position. One of the simplest solutions is "from those integers which remain unsorted.

Underlying all of these strategies is the assumption that a language exists for adequately describing the processing of data at several abstract levels. Let us examine two examples of top-down program development. Experience suggests that the top-down approach should be followed when creating a program.

There now remain two clearly defined subtasks: Eventually A n is compared to the current minimum and we are done. We first note that for any i. We observe at this point that the upper limit of the for-loop in line 1 can be changed to n. A j t The first subtask can be solved by assuming the minimum is A i. From the standpoint of readability we can ask if this program is good. Is there a more concise way of describing this algorithm which will still be as easy to comprehend?

Substituting while statements for the for loops doesn't significantly change anything.. Let us develop another program. By making use of the fact that the set is sorted we conceive of the following efficient method: There are three possibilities. Continue in this way by keeping two pointers. We assume that we have n 1 distinct integers which are already sorted and stored in the array A 1: Below is one complete version. This method is referred to as binary search.

Note how at each stage the number of elements in the remaining set is decreased by about one half. There are many more that we might produce which would be incorrect. In fact there are at least six different binary search programs that can be produced which are all correct.

Whichever version we choose. For instance we could replace the while loop by a repeat-until statement with the same English condition. Part of the freedom comes from the initialization step. Given a set of instructions which perform a logical operation.. Recursion We have tried to emphasize the need to structure a program to make it easier to achieve the goals of readability and correctness. As we enter this loop and as long as x is not found the following holds: Unfortunately a complete proof takes us beyond our scope but for those who wish to pursue program proving they should consult our references at the end of this chapter.

Actually one of the most useful syntactical features for accomplishing this is the procedure. The procedure name and its parameters file: Of course..

When is recursion an appropriate mechanism for algorithm exposition? One instance is when the problem itself is recursively defined. For these reasons we introduce recursion here. This view of the procedure implies that it is invoked. What this fails to stress is the fact that procedures may call themselves direct recursion before they are done or they may call other procedures which again invoke the calling procedure indirect recursion..

Factorial fits this category. These recursive mechanisms are extremely powerful. This is unfortunate because any program that can be written using assignment. Most students of computer science view recursion as a somewhat mystical technique which only is useful for some very special class of problems such as computing factorials or Ackermann's function. Given the input-output specifications of a procedure.. The answer is obtained by printing i a followed by all permutations of b.

Given a set of n 1 elements the problem is to print all possible permutations of this set. Then try to do one or more of the exercises at the end of this chapter which ask for recursive procedures.

It is easy to see that given n elements there are n! A is a character string e. A simple algorithm can be achieved by looking at the case of four elements a. B file: It implies that we can solve the problem for a set with n elements if we had an algorithm which worked on n.

This may sound strange. But for now we will content ourselves with examining some simple. This gives us the following set of three procedures. To rewrite it recursively the first thing we do is to remove the for loops and express the algorithm using assignment.

The main purpose is to make one more familiar with the execution of a recursive procedure. Suppose we start with the sorting algorithm presented in this section. We will see several important examples of such structures.. Another instance when recursion is invaluable is when we want to describe a backtracking procedure. Every place where a ''go to label'' appears. The effect of increasing k by one and restarting the procedure has essentially the same effect as the for loop.

Now let us trace the action of these procedures as they sort a set of five integers When a procedure is invoked an implicit branch to its beginning is made. These two procedures use eleven lines while the original iterative version was expressed in nine lines. Notice how in MAXL2 the fourth parameter k is being changed. Procedure MAXL2 is also directly reculsive. Thus a recursive call of a file: There are other criteria for judging programs which have a more direct relationship to performance.

In section 4. The above criteria are all vitally important when it comes to writing software.. Also in that section are several recursive procedures. The first is the amount of time a single execution will take. The parameter mechanism of the procedure is a form of assignment. These have to do with computing time and storage requirements of the algorithms.

The product of these numbers will be the total time taken by this statement. Performance evaluation can be loosely divided into 2 major phases: The second statistic is called the frequency count. Hopefully this more subtle approach will gradually infect your own program writing habits so that you will automatically strive to achieve these goals. Both of these are equally important. Though we will not be discussing how to reach these goals. There are many criteria upon which we can judge a program.

First consider a priori estimation. We would like to determine two numbers for this statement. Rules are also given there for eliminating recursion. It is impossible to determine exactly how much time it takes to execute any command unless we have the following information: Parallelism will not be considered. In both cases the exact times we would determine would not apply to many machines or to any machine.

Neither of these alternatives seems attractive. All these considerations lead us to limit our goals for an a priori analysis. Consider the three examples of Figure 1.

The anomalies of machine configuration and language will be lumped together when we do our experimental studies.

**Related Post:**

*FUNDAMENTALS OF COMPUTATIONAL NEUROSCIENCE PDF*

Another approach would be to define a hypothetical machine with imaginary execution times. One of the hardest tasks in estimating frequency counts is to choose adequate samples of data. It is possible to determine these figures by choosing a real machine and an existing compiler. The program on the following page takes any non-negative integer n and prints the value Fn.

In the program segment of figure 1. Each new term is obtained by taking the sum of the two previous terms. In our analysis of execution we will be concerned chiefly with determining the order of magnitude of an algorithm. Now 1. In general To clarify some of these ideas.. This means determining those statements which may have the greatest frequency count.

In program b the same statement will be executed n times and in program c n2 times assuming n 1. Then its frequency count is one. The Fibonacci sequence starts as 0. To determine the order of magnitude.. Three simple programs for frequency counting.. A complete set would include four cases: Below is a table which summarizes the frequency counts for the first three cases.

Though 2 to n is only n. None of them exercises the program very much. Step Frequency Step Frequency 2 3 4 5 6 7 1 1 1 0 1 0 1 9 10 11 12 13 14 15 2 n n-1 n-1 n-1 n-1 1 file: We can summarize all of this with a table.

At this point the for loop will actually be entered. Steps 1. These may have different execution counts. Both commands in step 9 are executed once.

The for statement is really a combination of several statements. O n is called linear. Execution Count for Computing Fn Each statement is counted once. This notation means that the order of magnitude is proportional to n. We will often write this as O n. For example n might be the number of inputs or the number of outputs or their sum or the magnitude of one of them. O n2 is called quadratic. O n log n is better than O n2 but not as good as O n.

The reason for this is that as n increases the time for the second algorithm will get far worse than the time for the first. O n3 is called cubic. We write O 1 to mean a computing time which is a constant. These seven computing times.O n2 is called quadratic. This is unfortunate because any program that can be written using assignment, the if-then-else statement and the while statement can also be written using assignment, if-then-else and recursion.

Such a choice is often complicated by the practical matters of student background and language availability. Flowchart for obtaining a Coca-Cola There is an intimate connection between the structuring of data, and the synthesis of algorithms.

B REM B. For each object there will be some basic operations to perform on it such as print the maze, add two polynomials, or find a name in the list. The dictionary's definition "any mechanical or recursive computational procedure" is not entirely satisfying since these terms are not basic enough. The goal of this book is to explore many different kinds of data objects. Also in that section are several recursive procedures.

### Related files

- LAKHTIN PHYSICAL METALLURGY PDF
- NOVEL SURGA YANG TAK DIRINDUKAN PDF GRATIS
- FAHRENHEIT 451 BOOK
- THE BREASTFEEDING ANSWER BOOK
- OSIRIS GIL GUIDE PDF
- ASP NET TUTORIAL BEGINNERS PDF
- LA NOIRE STRATEGY GUIDE PDF
- ISLAMIC BOOK SAHIH MUSLIM URDU
- LIHAF NOVEL IN URDU PDF
- SYSTEM SIMULATION BY GEOFFREY GORDON EBOOK
- THE BOOK THIEF IBOOK
- CAE RESULT STUDENTS BOOK LISTENING
- HARD DRIVE BILL GATES PDF