DATA STRUCTURES AND ALGORITHMS USING VISUAL BASIC.NET potx

412 351 0
DATA STRUCTURES AND ALGORITHMS USING VISUAL BASIC.NET potx

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

P1: KSF/ICD 0521547652pre CB820-McMillan-v1 April 21, 2005 16:14 DATA STRUCTURES AND ALGORITHMS USING VISUAL BASIC .NET This is the first Visual Basic.NET (VB.NET) book to provide a comprehensive discussion of the major data structures and algorithms. Here, instead of having to translate material on C++ or Java, the professional or student VB.NET programmer will find a tutorial on how to use data structures and algorithms and a reference for implementation using VB.NET for data structures and algorithms from the .NET Framework Class Library as well as those that must be developed by the programmer. In an object-oriented fashion, the author presents arrays and ArrayLists, linked lists, hash tables, dictionaries, trees, graphs, and sorting and searching as well as more advanced algorithms, such as probabilistic algorithms and dynamic programming. His approach is very practical, for example using timing tests rather than Big O analysis to compare the performance of data structures and algorithms. This book can be used in both beginning and advanced computer pro- gramming courses that use the VB.NET language and, most importantly, by the professional Visual Basic programmer. Michael McMillan is Instructor of Computer Information Systems at Pulaski Technical College. With more than twenty years of experience in the computer industry, he has written numerous articles for trade journals such as Software Development and Windows NT Systems. He is the author of Perl from the Ground Up and Object-Oriented Programming with Visual Basic.Net and coauthor of several books. i P1: KSF/ICD 0521547652pre CB820-McMillan-v1 April 21, 2005 16:14 ii P1: KSF/ICD 0521547652pre CB820-McMillan-v1 April 21, 2005 16:14 DATA STRUCTURES AND ALGORITHMS USING VISUAL BASIC.NET MICHAEL MCMILLAN Pulaski Technical College iii    Cambridge, New York, Melbourne, Madrid, Cape Town, Singapore, São Paulo Cambridge University Press The Edinburgh Building, Cambridge  , UK First published in print format - ---- - ---- © Michael McMillan 2005 2005 Information on this title: www.cambrid g e.or g /9780521547659 This book is in copyright. Subject to statutory exception and to the provision of relevant collective licensing agreements, no reproduction of any part may take place without the written permission of Cambridge University Press. - --- - --- Cambridge University Press has no responsibility for the persistence or accuracy of s for external or third-party internet websites referred to in this book, and does not guarantee that any content on such websites is, or will remain, accurate or appropriate. Published in the United States of America by Cambridge University Press, New York www.cambridge.org p a p erback eBook (NetLibrary) eBook (NetLibrary) p a p erback P1: KSF/ICD 0521547652pre CB820-McMillan-v1 April 21, 2005 16:14 Contents Preface vii Introduction 1 Chapter 1 Collections 14 Chapter 2 Arrays and ArrayLists 46 Chapter 3 Basic Sorting Algorithms 72 Chapter 4 Basic Searching Algorithms 86 Chapter 5 Stacks and Queues 99 Chapter 6 The BitArray Class 124 Chapter 7 Strings, the String Class, and the StringBuilder Class 150 v P1: KSF/ICD 0521547652pre CB820-McMillan-v1 April 21, 2005 16:14 vi CONTENTS Chapter 8 Pattern Matching and Text Processing 181 Chapter 9 Building Dictionaries: The DictionaryBase Class and the SortedList Class 200 Chapter 10 Hashing and the HashTable Class 210 Chapter 11 Linked Lists 227 Chapter 12 Binary Trees and Binary Search Trees 249 Chapter 13 Sets 268 Chapter 14 Advanced Sorting Algorithms 283 Chapter 15 Advanced Data Structures and Algorithms for Searching 298 Chapter 16 Graphs and Graph Algorithms 320 Chapter 17 Advanced Algorithms 352 References 379 Index 381 P1: KSF/ICD 0521547652pre CB820-McMillan-v1 April 21, 2005 16:14 Preface The Visual Basic.NET (VB.NET) programming language is not usually associ- ated with the study of data structures and algorithms. The primary reason for this must be because most university and college computer science depart- ments don’t consider VB.NET to be a “serious” programming language that can be used to study serious topics. This is primarily a historical bias based on Basic’s past as a “nonprogrammer’s” language often taught to junior high, senior high, and liberal arts college students, but not to computer science or computer engineering majors. The present state of thelanguage, however, aligns it with other, more serious programming languages, most specifically Java. VB.NET, in its current form, contains everything expected in a modern programming language, from true object-oriented features to the .NET Framework library, which rivals the Java libraries in both depth and breadth. Included in the .NET Framework library is a set of collection classes, which range from the Array, ArrayList, and Collection classes, to the Stack and Queue classes, to the Hashtable and the SortedList classes. Students of data structures and algorithms can now see how to use a data structure before learning how to implement it. Previously, an instructor had to discuss the concept of, say, a stack, abstractly until the complete data structure was constructed. Instructors can now show students how to use a stack to perform some computations, such as number base conversions, demonstrating the utility of the data struc- ture immediately. With this background, students can then go back and learn the fundamentals of the data structure (or algorithm) and even build their own implementation. This book is written primarily as a practical overview of the data struc- tures and algorithms all serious computer programmers need to know and vii P1: KSF/ICD 0521547652pre CB820-McMillan-v1 April 21, 2005 16:14 viii PREFACE understand. Given this, there is no formal analysis of the data structures and algorithms covered in the book. Hence, there is not a single mathematical formula and not one mention of Big O analysis (for the latter the reader is referred to any of the books listed in the bibliography). Instead, the various data structures and algorithms are presented as problem-solving tools. We use simple timing tests to compare the performance of the data structures and algorithms discussed in the book. PREREQUISITES There are very few prerequisites for this book. The reader should be com- petent in one or more programming languages, preferably VB.NET, though a course or two in Java will serve as well. C/C++ programmers should not have too much trouble picking up the language. There are no mathematical prerequisites since we don’t take a formal approach in the book. C HAPTER - BY-CHAPTER ORGANIZATION The Introduction provides an overview of object-oriented programming using VB.NET and introduces the benchmark tool used for comparing the perfor- mance of the data structures and algorithms studied in the book. This tool is aTiming class developed by the author as a practical means for timing code in the .NET environment. Chapter 1 introduces the reader to the concept of the data structure as a collection of data. The concepts of linear and nonlinear collections are introduced. The Collection class is demonstrated. Chapter 2 provides a review of how arrays are constructed in VB.NET, along with demonstrating the features of the Array class. The Array class encapsulates many of the functions associated with arrays (UBound, LBound, and so on) into a single package. Arraylists are special types of arrays that provide dynamic resizing capabilities. Chapter 3 gives an introduction to the basic sorting algorithms, such as the bubble sort and the insertion sort, and Chapter 4 examines the most funda- mental algorithms for searching memory, the sequential and binary searches. Tw o classic data structures are examined in Chapter 5—the stack and the queue. This chapter emphasizes the practical use of these data structures in solving everyday problems in data processing. Chapter 6 covers the BitArray P1: KSF/ICD 0521547652pre CB820-McMillan-v1 April 21, 2005 16:14 Preface ix class, which can be used to efficiently represent a large number of integer values, such as test scores. Strings are not usually covered in a data structures book, but Chapter 7 covers strings, the String class, and the StringBuilder class. We feel that be- cause so much data processing in VB.NET is performed on strings, the reader should be exposed to the special techniques found in the two classes. Chap- ter 8 examines the use of regular expressions for text processing and pattern matching. Regular expressions often provide more power and efficiency than can be had with more traditional string functions and methods. Chapter 9 introduces the reader to the use of dictionaries as data structures. Dictionaries, and the different data structures based on them, store data as key/value pairs. This chapter shows the reader how to create his or her own classes based on the DictionaryBase class, which is an abstract class. Chap- ter 10 covers hash tables and the Hashtable class, which is a special type of dictionary that uses a hashing algorithm for storing data internally. Another classic data structure, the linked list, is covered in Chapter 11. Linked lists are not as important a data structure in VB.NET as they are in a pointer-based language such as C++, but they still play a role in VB.NET programming. Chapter 12 introduces the reader to yet another classic data structure—the binary tree. A specialized type of binary tree, the binary search tree, comprises the primary topic of the chapter. Other types of binary trees are covered in Chapter 15. Chapter 13 shows the reader how to store data in sets, which can be useful in situations when only unique data values can be stored in the data structure. Chapter 14 covers more advanced sorting algorithms, including the popular and efficient QuickSort, which forms the basis for most of the sorting proce- dures implemented in the .NET Framework library. Chapter 15 looks at three data structures that prove useful for searching when a binary search tree is not called for: the AVL tree, the red–black tree, and the skip list. Chapter 16 discusses graphs and graph algorithms. Graphs are useful for representing many different types of data, especially networks. Finally, Chap- ter 17 introduces the reader to what are really algorithm design techniques— dynamic algorithms and greedy algorithms. ACKNOWLEDGMENTS There are several different groups of people who must be thanked for helping me finish this book. First, I owe thanks to a certain group of students who [...]... preliminary chapter, we introduce a couple of topics we’ll be using throughout the book First, we discuss how to use classes and object-oriented programming (OOP) to aid in the development of data structures and algorithms Using OOP techniques will make our algorithms and data structures more general and easier to modify, not to mention easier to understand The second part of this Introduction familiarizes... This book discusses the development and implementation of data structures and algorithms using VB.NET The data structures we use here are found in the NET Framework class library System.Collections In this chapter we develop the concept of a collection by first discussing the implementation of our own collection class (using the array as the basis of our implementation) and then by covering the collection... or two features of a geometric data processing system: the Point class and the Circle class Data Members and Constructors The data defined in a class, generally, are meant to stay hidden within the class definition This is part of the principle of encapsulation The data stored in a class are called data members, or alternatively, fields To keep the data in a class hidden, data members are usually declared... Framework COLLECTIONS DEFINED A collection is a structured data type that stores data and provides operations for adding data to the collection, removing data from the collection, updating data in the collection, and setting and returning the values of different attributes of the collection Collections can be broken down into two types—linear and nonlinear A linear collection is a list of elements where... PREFACE first sat through my lectures on developing data structures and algorithms in VB.NET These students include (not in any particular order): Matt Hoffman, Ken Chen, Ken Cates, Jeff Richmond, and Gordon Caffey Also, one of my fellow instructors at Pulaski Technical College, Clayton Ruff, sat through many of the lectures and provided excellent comments and criticism I also have to thank my department... declared as a ReadOnly property This means that it only retrieves a value and cannot be used to set a data member’s value When you use the ReadOnly modifer, Visual Studio.NET only provides you with the Get part of the method TIMING TESTS Because this book takes a practical approach to the analysis of the data structures and algorithms examined, we eschew the use of Big O analysis, preferring instead... userdefined type in Visual Basic 6 A structure is a composite data type that holds data that may consist of many different data types For example, an employee record consists of the employee’s name (a string), salary (an integer), and identification number (a string, or an integer), as well as other attributes Since storing each of these data values in separate variables could becoming confusing very easily,... Timing class needs the following data members: r startingTime—to store the starting time of the code we are testing, r duration—the ending time of the code we are testing, The starting time and the duration members store times and we chose to use the TimeSpan data type for these data members We’ll use just one constructor method, a default constructor that sets both the data members to 0 We’ll need methods... performing timing tests on data structures and, most importantly, the different algorithms examined in this book Running timing tests (also called benchmarking) is notoriously difficult to get exactly right, and in the NET environment, it is even more complex than in other environments We develop a Timing class that makes it easy to test the efficiency of an algorithm (or a data structure when appropriate)... After the data member values are initialized, the next set of operations we need to write involves methods for setting and retrieving values from the data members In VB.NET, these methods are usually written as Property methods A Property method provides the ability to both set and retrieve the value of a data member within the same method definition This is accomplished by utilizing a Get clause and a . 2005 16:14 DATA STRUCTURES AND ALGORITHMS USING VISUAL BASIC .NET This is the first Visual Basic. NET (VB .NET) book to provide a comprehensive discussion of the major data structures and algorithms. . student VB .NET programmer will find a tutorial on how to use data structures and algorithms and a reference for implementation using VB .NET for data structures and algorithms from the .NET Framework. 16:14 ii P1: KSF/ICD 0521547652pre CB820-McMillan-v1 April 21, 2005 16:14 DATA STRUCTURES AND ALGORITHMS USING VISUAL BASIC. NET MICHAEL MCMILLAN Pulaski Technical College iii  

Ngày đăng: 27/06/2014, 11:20

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan