Data Structures and Algorithm Analysis in C++ (3rd Edition)

Data Structures and Algorithm Analysis in C++ (3rd Edition)

Language: English

Pages: 586

ISBN: 032144146X

Format: PDF / Kindle (mobi) / ePub

In this text, readers are able to look at specific problems and see how careful implementations can reduce the time constraint for large amounts of data from several years to less than a second. Class templates are used to describe generic data structures and first-class versions of vector and string classes are used. Included is an appendix on a Standard Template Library (STL). This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amount of efficiency. Readers should have some knowledge of intermediate programming, including topics as object-based programming and recursion, and some background in discrete math.

item in the list in constant time. The operations are: r void push_back( const Object & x ): adds x to the end of the list. r void pop_back( ): removes the object at the end of the list. r const Object & back( ) const: returns the object at the end of the list (a mutator that returns a reference is also provided). r const Object & front( ) const: returns the object at the front of the list (a mutator that returns a reference is also provided). Because a doubly linked list allows efﬁcient

that these operations are performed in not only constant time but very fast constant time. On some machines, pushes and pops (of integers) can be written in one machine instruction, operating on a register with auto-increment and auto-decrement addressing. The fact that most modern machines have stack operations as part of the instruction set enforces the idea that the stack is probably the most fundamental data structure in computer science, after the array. 3.6.3 Applications It should come as

empty subtree that was originally the left child of the node with item 7, subtree C is the tree rooted at the node with item 14, and ﬁnally, subtree D is the tree rooted at the node with item 16. 4 4 k1 6 2 1 3 k3 15 5 k2 7 before k2 7 2 1 16 14 k3 15 k1 6 3 5 14 16 after If 13 is now inserted, there is an imbalance at the root. Since 13 is not between 4 and 7, we know that the single rotation will work. 151 152 Chapter 4 Trees 4 7 2 7 1 3 6 15 5 14 before 15 4 2