P. 1
Data Structures and Algorithms

# Data Structures and Algorithms

Ratings: (0)|Views: 217|Likes:
Data Structures and Algorithms
Data Structures and Algorithms

### Availability:

See more
See less

06/05/2013

pdf

www.earnrupees4you.comPage 1
Data Structures and Algorithms
CST I
B
, CST II(General) and DiplomaMartin Richards
mr@cl.cam.ac.uk
October 2001
Computer LaboratoryUniversity of Cambridge
(Version October 11, 2001)
1
Acknowledgements
These notes are closely based on those originally written by Arthur Norman in1994, and combined with some details from Roger Needham
s notes of 1997.
1 Introduction
Just as Mathematics is the
Queen and servant of science
, the materialcoveredby this course is fundamental to all aspects of computer science. Almost allthecourses given in the Computer Science Tripos and Diploma describe structuresand algorithms specialised towards the application being covered, whether itbedatabases, compilation, graphics, operating systems, or whatever. Thesediversefields often use similar data structures, such as lists, hash tables, treesand graphs,and often apply similar algorithms to perform basic tasks such as tablelookup,sorting, searching, or operations on graphs. It is the purpose of this courseto givea broad understanding of such commonly used data structures and their relatedalgorithms. As a byproduct, you will learn to reason about the correctness andefficiency of programs.It might seem that the study of simple problems and the presentation oftextbook-style code fragments to solve them would make this first simplecoursean ultimately boring one. But this should not be the case for various reasons.The course is driven by the idea that if you can analyse a problem well enoughyou ought to be able to find the best way of solving it. That usually meansthe

www.earnrupees4you.comPage 2
most efficient procedure or representation possible. Note that this is thebestsolution not just among all the ones that we can think of at present, but thebestfrom among all solutions that there ever could be, including ones that mightbeextremely elaborate or difficult to program and still to be discovered. A wayofsolving a problem will (generally) only be accepted if we can demonstrate thatit
always
works. This, of course, includes proving that the efficiency of themethodis as claimed.Most problems, even the simplest, have a remarkable number of candidatesolutions. Often slight changes in the assumptions may render differentmethodsattractive. An effective computer scientist needs to have a good awareness oftherange of possiblities that can arise, and a feel of when it will be worthcheckingtext-books to see if there is a good standard solution to apply.Almost all the data structures and algorithms that go with them presentedhere are of real practical value, and in a great many cases a programmer whofailedto used them would risk inventing dramatically worse solutions to the problemsaddressed, or, of course in rare cases, finding a new and yet better solution
but be unaware of what has just been achieved!Several techniques covered in this course are delicate, in the sense thatsloppyexplanations of them will miss important details, and sloppy coding will lead2
2 COURSE CONTENT AND TEXTBOOKS
to code with subtle bugs. Beware! A final feature of this course is that afairnumber of the ideas it presents are really ingenious. Often, in retrospect,theyare not difficult to understand or justify, but one might very reasonably beleftwith the strong feeling of
I wish I had thought of that
and an admirationforthe cunning and insight of the originator.

www.earnrupees4you.comPage 3
The subject is a young one and many of the the algorithms I will be coveringhad not been discovered when I attended a similar course as a Diploma studentin 1962. New algorithms and improvements are still being found and there is agood chance that some of you will find fame (if not fortune) frominventivenessin this area. Good luck! But first you need to learn the basics.
2 Course content and textbooks
Even a cursory inspection of standard texts related to this course should bedaunting. There as some incredibly long books full of amazing detail, andtherecan be pages of mathematical analysis and justification for even simple-lookingprograms. This is in the nature of the subject. An enormous amount is known,and proper precise explanations of it can get quite technical. Fortunately,thislecture course does not have time to cover everything, so it will be builtarounda collection of sample problems or case studies. The majority of these will beones that are covered well in all the textbooks, and which are chosen fortheirpractical importance as well as their intrinsic intellectual content. Fromyear toyear some of the other topics will change, and this includes the possibilitythatlectures will cover material not explicitly mentioned in these notes.A range of text books will be listed here, and the different books suggestedall have quite different styles, even though they generally agree on whattopicsto cover. It will make good sense to take the time to read sections of severalofthem in a library before spending a lot of money on any
different books willappeal to different readers. All the books mentioned are plausible candidatesforthe long-term reference shelf that any computer scientist will keep: they arenotthe sort of text that one studies just for one course or exam then forgets.
Corman, Le
iserson and Rivest, “Introduction to Algorithms”.
Aheavyweight book at 1028 pages long, and naturally covers a little morematerial at slightly greater deapth than the other texts listed here. Itincludescareful mathematical treatment of the algorithms that it discusses,