Вы находитесь на странице: 1из 6

A data structure is a particular way of storing and organizing data in

a computer so that it can be used efficiently

Different kinds of data structures are suited to different kinds of applications, and
some are highly specialized to specific tasks. For example, B-trees are particularly
well-suited for implementation of databases, while compiler implementations
usually use hash tables.

Data structures are used in almost every program or software system. Data
structures provide a means to manage huge amounts of data efficiently, such as
large databases. Usually, efficient data structures are a key to designing
efficient algorithms. Some formal design methods and programming
languagesemphasize data structures, rather than algorithms, as the key organizing
factor in software design.

Data structures are generally based on the ability of a computer to fetch and store
data at any place in its memory, specified by an address a bit string that can be
itself stored in memory and manipulated by the program. Thus
the struct and array data structures are based on computing the addresses of data
items with arithmetic operations; while the linked data structures are based on
storing addresses of data items within the structure itself.

The implementation of a data structure usually requires writing a set

of procedures that create and manipulate instances of that structure. The efficiency
of a data structure cannot be analyzed separately from those operations. This
observation motivates the theoretical concept of an abstract data type, a data
structure that is defined indirectly by the operations that may be performed on it.

Common data structures include: array, linked list, hash-table, heap, Tree (Binary
Tree, B-tree, red-black tree, trie), stack, and queue.

Topics that will be covered in this section include:

Array-Based Implementations

Recall that
o an array is a named collection of homogeneous items
o An items place within the collection is called an index
If there is no ordering on the items in the container, we call the container
If there is an ordering, we call the container sorted

Linked Implementation

An implementation based on the concept of a node

A node is made up of two pieces of information
o the item that the user wants in the list, and
o a pointer to the next node in the list


List operations
o Create itself
o Insert an item
o Delete an item
o Print itself
o Know the number of items it contains


Because sorting a large number of elements can be extremely timeconsuming, a good sorting algorithm is very desirable
We present several quite different sorting algorithms

Selection Sort

List of names
o Put them in alphabetical order
Find the name that comes first in the alphabet,
and write it on a second sheet of paper

Cross out the name on the original list

Continue this cycle until all the names on the original list have
been crossed out and written
onto the second list, at which point the second list is sorted

A slight adjustment to this manual approach does away with the need to
duplicate space
o As you cross a name off the original list, a free space opens up
o Instead of writing the minimum value on a second list, exchange it
with the value currently in the position where the crossed-off item
should go

Bubble Sort

A selection sort that uses a different scheme for finding the minimum value
o Starting with the last list element, we compare successive pairs of
elements, swapping whenever the bottom element of the pair is
smaller than the one above it


A sequential search of a list begins at the beginning of the list and

continues until the item is found or the entire list has been searched

A binary search looks for an item in a list using a divide-and-conquer


Binary Search

Binary Search Algorithm

o Binary search algorithm assumes that the items in the list being
searched are sorted
o The algorithm begins at the middle of the list in a binary search
o If the item for which we are searching is less than the item in the
middle, we know that the item wont be in the second half of the list
o Once again we examine the middle element (which is really the
item 25% of the way into the list)
o The process continues with each comparison cutting in half the
portion of the list where the item might be


A stack is an abstract data type in which accesses are made at only one
o LIFO, which stands for Last In First Out
o The insert is called Push and the delete is called Pop


A Queue is an abstract data type in which items are entered at one end and
removed from the other end
o FIFO, for First In First Out
o Like a waiting line in a bank or supermarket
o No standard queue terminology
Enqueue, Enque, Enq, Enter, and Insert
are used for the insertion operation
Dequeue, Deque, Deq, Delete, and Remove
are used for the deletion operation.