You are on page 1of 4

Chapter I Introduction to data structures and algorithms

1. Data structures and algorithms


- A data structure is a particular arrangement of data in a computer's memory so that it can be used
efficiently.
- Popular data structures include: arrays, linked lists, binary trees, hash tables, etc.
- We use algorithms to manipulate the data in these structures in various ways.
- !"A are useful for:
#eal-word data storage.
Programmer's tools.
#eal-world modeling.
Real-word data storage :
- $any of the structures and techni%ues are concerned with how to handle real-word data storage.
- &y real world-data, we mean data that describes physical entities.
- A non-computer e'ample of a real-word data storage is a stack of inde' cards. (hese cards can be
used for a variety of purposes )e.g. address book, home inventory*.
- Whenever we deal with abstract data, we'll have to respond to %uestions like:
+ow to store the data in our computer's memory ,
Would this method work for a varying amount of records-entities ,
Would this method permit %uick insertion and deletion ,
Would this method allow for fast searching for a specific record ,
+ow to sort the data ,

- esigning comple' systems may include many data structures and re%uires the application of
software engineering techni%ues.
Programmer's tools :
- .ot all data structures are used to store real-word data.
- (ypically, real-word data is accessed more or less directly by a program's users.
+owever, some of those are not meant to act as an interface, but are rather used as tools
to facilitate some other operations.

Real-word modeling :
- !ome data structures directly model real-word situations. (he most important ! of this type is
the graph.
- /raphs can be used to represent airline routes, connections in an electric circuit, maps, networks,
molecules, etc.
Chapter I Introduction to data structures and algorithms
2. Short overview of Data Structures
- Another way to look at data structures is to focus on their strengths and weaknesses:
Data Structure Advantages Disadvantages
Array
0uick insertion
1ery fast access
!low search
!low deletion
2i'ed si3e
4rdered Array
1ery fast access
0uick search
!low deletion, insertion
2i'ed si3e
!tack 5624 access !low access to other items
0ueue 2624 access !low access to other items
5inked 5ist 0uick insertion, deletion !low search
&inary (ree
0uick search, insertion
0uick deletion )if tree remains
balanced*
eletion algorithm is comple'
#ed-black (ree
0uick search, insertion, deletion
(ree always balanced
7omple' !
8-9-: (ree
0uick search, insertion, deletion
(ree always balanced
/ood for disk storage
7omple' !
+ash (able
1ery fast access
2ast insertion
!low deletion
6nefficient memory usage
+eap
2ast insertion, deletion
Access to smallest-largest item
!low access to other items
/raph $odels real-word situations
!ome algorithms are slow and
comple'

- ;'cept the arrays, these data structures can be thought of as Abstract ata (ypes )A(s*.
3. Definitions
Database/File/Class:
- #efers to all the data that will be dealt with in a particular situation.
- Assumes that each item in a database has a similar format.
)e.g. the entries in an address book constitute a database*.
Record/Entry/Object:
- 6s the unit into which a database is divided.
- Provides a format for storing information.
- 6ncludes all the information about some entity.
)e.g. a recipe in a cookbook file, a person in a personnel file*.
Field/Member:
- 6s the unit into which a record is divided.
- +olds a particular kind of data.
)e.g. a person's name, address, or telephone number in an entry of an address book*.
Chapter I Introduction to data structures and algorithms
- 6n 44P languages, records are usually represented by the ob<ects of a class, and the individual
variables within an ob<ect represent data fields.
- 2ields within a class ob<ect are called:
a* 2ields )in =ava*
b* ata members )in 7>>*
Key:
- #epresents one of the record's fields which is used in various operations, such as sorting or
searching.
4. Object-Oriented Programming
- 44P was invented because procedural languages were found inade%uate for large and comple'
programs.
- Problems that lead to the 44P style:
a* (he lack of correspondence between the program and the real word.
b* (he internal organi3ation of the program.
- 7onceptuali3ing a real-word problem using procedural languages is difficult, because they do not
encapsulate both the functions-procedures that carry out a task and the data they operate on.
- As such, the functions and the data wouldn't form any sort of programming unit.
- 7onse%uently, the concept of a real-word ob<ect would only be in the programmer's mind.
- Procedural languages organi3e the code by diving it into functions. (he problem with this kind of
division is that it focuses on functions at the e'pense of data.
- (his means that the data could either be local)to a function*, or global)to the whole program*,
but there is no fle'ible way of controlling the access levels of data so that some functions could
access a variable and others couldn't.
- (he solution to these problems was the concept of ob<ects. An ob<ect:
a* 7ontains &4(+ functions A. variables.
b* 7orresponds more closely to an ob<ect in the real word.
c* 7ompletely retains its integrity through encapsulation.
- &y generali3ing even further the idea of ob<ects, the concept of classes was found.
- A class is a specification )a blueprint* that represents the commonalities between one or more
ob<ects.
5. Summar
A ! is the organi3ation of data in a computer's memory or in a disk file.
(he correct choice of ! allows ma<or improvements in program efficiency.
;'amples of ! are arrays, stacks, and linked lists.
An algorithm is a procedure for carrying out a particular task.
$any of the !s and algorithms are most often used to build databases.
!ome !s are used as programmer's tools: they help e'ecute an algorithm.
Chapter I Introduction to data structures and algorithms
4ther !s model real-word situations, such as telephone lines between cities.
A data base is a unit of data storage composed of many similar records.
A record often represents a real-word ob<ect, such as an employee or a car part.
A record is divided into fields. ;ach field stores one characteristic of the ob<ect described
by the record.
A key is a field in a record that's used to carry out some operation on the database.
A & can be searched for all records whose key field has a certain value. (his value is called a
search key.

You might also like