Data structures & their algorithms (original) (raw)
Data Structures and Algorithms
users.utcluj.ro
A collection of values that share a common set of operations is called a data type. Structured or composite data types are collections of individual data items of the same or different data types. Data structures are collections of variables, possibly of different data types, connected in various ways. High-level languages prior to Pascal usually limited their concepts of data types to those provided directly by hardware (integers, reals, double precision integers and reals, and blocks of contiguous locations). Two objects had different types if it was necessary to generate different code to manipulate them. Pascal and later languages have taken a rather different approach, based on the concept of abstract data types. An abstract data type is a programming language facility for organizing programs into modules using criteria that are based on the data structures of the program. Also, an abstract data type can be defines as a set of values and a set of procedures that manipulate those values. The specification of the module should provide all information required for using the type, including the allowable values of the data and the effects of the operations. However, details about the implementation, such as data representations and algorithms for implementing the operations, are hidden within the module. This separation of specification from implementation is a key idea of abstract data types.
COSC 302 surveys the most important algorithms and data structures in use in our digital world. Particular emphasis is given to algorithms for sorting, searching, and string processing. Fundamental algorithms in a number of other areas are basic data structure operations are covered. The course will concentrate on developing implementations, understanding their performance characteristics, and estimating their potential effectiveness in applications. File system organization and access methods. Course projects require advanced problem-solving, design, and implementation skills.
Data structures and program design in C
2007
Preface functions and complete programs of substantial length. The exercises and programming projects, moreover, constitute an indispensable part of the book. Many of these are immediate applications of the topic under study, often requesting that programs be written and run, so that algorithms may be tested and compared. Some are larger projects, and a few are suitable for use by a small group of students working together. Our programs are written in the popular object-oriented language C++. We take the view that many object-oriented techniques provide natural implementations for basic principles of data-structure design. In this way, C++ allows us to construct safe, efficient, and simple implementations of data-structures. We recognize that C++ is sufficiently complex that students will need to use the experience of a data structures courses to develop and refine their understanding of the language. We strive to support this development by carefully introducing and explaining various object-oriented features of C++ as we progress through the book. Thus, we begin Chapter 1 assuming that the reader is comfortable with the elementary parts of C++ (essentially, with the C subset), and gradually we add in such object-oriented elements of C++ as classes, methods, constructors, inheritance, dynamic memory management, destructors, copy constructors, overloaded functions and operations, templates, virtual functions, and the STL. Of course, our primary focus is on the data structures themselves, and therefore students with relatively little familiarity with C++ will need to supplement this text with a C++ programming text. SYNOPSIS By working through the first large project (CONWAY's game of Life), Chapter 1 Programming Principles expounds principles of object-oriented program design, top-down refinement, review, and testing, principles that the student will see demonstrated and is expected to follow throughout the sequel. At the same time, this project provides an opportunity for the student to review the syntax of elementary features of C++, the programming language used throughout the book. Chapter 2 introduces the first data structure we study, the stack. The chapter Preface • Synopsis xiii destructors, copy constructors, and overloaded assignment operators, all of which are needed in the safe C++ implementation of linked structures. Chapter 5 continues to elucidate stacks by studying their relationship to prob-Recursion lem solving and programming with recursion. These ideas are reinforced by exploring several substantial applications of recursion, including backtracking and tree-structured programs. This chapter can, if desired, be studied earlier in a course than its placement in the book, at any time after the completion of Chapter 2. More general lists with their linked and contiguous implementations provide Lists and Strings the theme for Chapter 6. The chapter also includes an encapsulated string implementation, an introduction to C++ templates, and an introduction to algorithm analysis in a very informal way. Chapter 7, Chapter 8, and Chapter 9 present algorithms for searching, sorting, Searching and table access (including hashing), respectively. These chapters illustrate the interplay between algorithms and the associated abstract data types, data struc-Sorting tures, and implementations. The text introduces the "big-O " and related notations for elementary algorithm analysis and highlights the crucial choices to be made regarding best use of space, time, and programming effort. These choices require Tables and Information Retrieval that we find analytical methods to assess algorithms, and producing such analyses is a battle for which combinatorial mathematics must provide the arsenal. At an elementary level we can expect students neither to be well armed nor to possess the mathematical maturity needed to hone their skills to perfection. Our goal, therefore, is to help students recognize the importance of such skills in anticipation of later chances to study mathematics. Binary trees are surely among the most elegant and useful of data structures. Their study, which occupies Chapter 10, ties together concepts from lists, searching, Binary Trees and sorting. As recursively defined data structures, binary trees afford an excellent opportunity for the student to become comfortable with recursion applied both to data structures and algorithms. The chapter begins with elementary topics and progresses as far as such advanced topics as splay trees and amortized algorithm analysis. Chapter 11 continues the study of more sophisticated data structures, including Multiway Trees tries, B-trees, and red-black trees. Chapter 12 introduces graphs as more general structures useful for problem Graphs solving, and introduces some of the classical algorithms for shortest paths and minimal spanning trees in graphs. The case study in Chapter 13 examines the Polish notation in considerable detail, exploring the interplay of recursion, trees, and stacks as vehicles for problem Case Study: The Polish Notation solving and algorithm development. Some of the questions addressed can serve as an informal introduction to compiler design. As usual, the algorithms are fully developed within a functioning C++ program. This program accepts as input an expression in ordinary (infix) form, translates the expression into postfix form, and evaluates the expression for specified values of the variable(s). Chapter 13 may be studied anytime after the completion of Section 10.1. The appendices discuss several topics that are not properly part of the book's subject but that are often missing from the student's preparation. Appendix A presents several topics from discrete mathematics. Its final two Mathematical Methods sections, Fibonacci numbers amd Catalan numbers, are more advanced and not xiv Preface needed for any vital purpose in the text, but are included to encourage combinatorial interest in the more mathematically inclined. Appendix B discusses pseudorandom numbers, generators, and applications, Random Numbers a topic that many students find interesting, but which often does not fit anywhere in the curriculum. Appendix C catalogues the various utility and data-structure packages that are Packages and Utility Functions developed and used many times throughout this book. Appendix C discusses declaration and definition files, translation units, the utility package used throughout the book, and a package for calculating CPU times. Appendix D, finally, collects all the Programming Precepts and all the Pointers Programming Precepts, Pointers, and Pitfalls and Pitfalls scattered through the book and organizes them by subject for convenience of reference. COURSE STRUCTURE The prerequisite for this book is a first course in programming, with experience prerequisite using the elementary features of C++. However, since we are careful to introduce sophisticated C++ techniques only gradually, we believe that, used in conjunction with a supplementary C++ textbook and extra instruction and emphasis on C++ language issues, this text provides a data structures course in C++ that remains suitable even for students whose programming background is in another language such as C, Pascal, or Java. A good knowledge of high school mathematics will suffice for almost all the algorithm analyses, but further (perhaps concurrent) preparation in discrete mathematics will prove valuable. Appendix A reviews all required mathematics. This book is intended for courses such as the ACM Course CS2 (Program Design content and Implementation), ACM Course CS7 (Data Structures and Algorithm Analysis), or a course combining these. Thorough coverage is given to most of the ACM/IEEE knowledge units 1 on data structures and algorithms. These include: AL1 Basic data structures, such as arrays, tables, stacks, queues, trees, and graphs; AL2 Abstract data types; AL3 Recursion and recursive algorithms; AL4 Complexity analysis using the big Oh notation; AL6 Sorting and searching; and AL8 Practical problem-solving strategies, with large case studies. The three most advanced knowledge units, AL5 (complexity classes, NP-complete problems), AL7 (computability and undecidability), and AL9 (parallel and distributed algorithms) are not treated in this book.
CSE2003 Data Structures and Algorithms
Programming forms the core of Computer Science and Engineering . A course on "Data structures and Algorithms" stresses much on effective programming than focusing on the syntax / semantics of any programming language. In other words, this course views the problem solving not just as solving the problem somehow but about solving the problem in the most efficient way. Choice of an appropriate data structure and an appropriate algorithmic technique greatly influences the characteristics of the obtained solution such as performance, space requirements , scalability, reuse, robustness etc. Objective of the course (1) To stress the importance of Algorithms and Data structures in becoming a more productive computer scientist.