Vous êtes sur la page 1sur 5

9/22/13

CAPE Computer Science Unit 2 - LiveBinder

A data structure is a particular way of storing and organizing data in acomputer so that it can be usedefficiently

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 compilerimplementations 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 efficientalgorithms. 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 arraydata 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

www.livebinders.com/play/play?id=127326

1/5

9/22/13

CAPE Computer Science Unit 2 - LiveBinder

Recall that an array is a named collection of homogeneous items 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 unsorted 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 the item that the user wants in the list, and a pointer to the next node in the list

Lists

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

Sorting

Because sorting a large number of elements can be extremely time-consuming, a good sorting algorithm is
www.livebinders.com/play/play?id=127326 2/5

9/22/13

CAPE Computer Science Unit 2 - LiveBinder

very desirable We present several quite different sorting algorithms

Selection Sort

List of names 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 As you cross a name off the original list, a free space opens up 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 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

Searching

www.livebinders.com/play/play?id=127326

3/5

9/22/13

CAPE Computer Science Unit 2 - LiveBinder

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 strategy

Binary Search

Binary Search Algorithm Binary search algorithm assumes that the items in the list being searched are sorted The algorithm begins at the middle of the list in a binary search 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 Once again we examine the middle element (which is really the item 25% of the way into the list) The process continues with each comparison cutting in half the portion of the list where the item might be

Stacks

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

Queues

A Queue is an abstract datatype in which items are entered at one end and removed from the other end FIFO, for First In First Out
www.livebinders.com/play/play?id=127326 4/5

9/22/13

CAPE Computer Science Unit 2 - LiveBinder

Like a waiting line in a bank or supermarket No standard queue terminology Enqueue, Enque, Enq, Enter, andInsert are used for the insertion operation Dequeue, Deque, Deq, Delete, andRemove are used for the deletion operation.

www.livebinders.com/play/play?id=127326

5/5

Vous aimerez peut-être aussi