3/2/09

Define:

Data Structures


  • A data structure in computer science is a way of storing data in a computer so that it can be used efficiently. It is an organization of mathematical and logical concepts of data. Often a carefully chosen data structure will allow the most efficient algorithm to be used. The choice of the data structure often begins from the choice of an abstract data type. A well-designed data structure allows a variety of critical operations to be performed, using as few resources, both execution time and memory space, as possible. Data structures are implemented by a programming language as data types and the references and operations they provide.
  • In programming, the term data structure refers to a scheme for organizing related pieces of information. The basic types of data structures include:
    · files
    lists
    · arrays
    records
    · trees
    tables

Each of these basic structures has many variations and allows different operations to be performed on the data.

  • An organization of information, usually in memory, for better algorithm efficiency, such as queue, stack, linked list, heap, dictionary, and tree, or conceptual unity, such as the name and address of a person. It may include redundant information, such as length of the list or number of nodes in a subtree. Note: Most data structures have associated algorithms to perform operations, such as search, insert, or balance, that maintain the properties of the data structure.
  • Any of various methods or formats (as an array, file, or record) for organizing data in a computer.
  • A data structure is a group of data elements grouped together under one name. These data elements, known as members, can have different types and different lengths. Data structures are declared in C++ using the following syntax:
    struct structure_name {member_type1 member_name1;member_type2 member_name2;member_type3 member_name3;..} object_names; where structure_name is a name for the structure type, object_name can be a set of valid identifiers for objects that have the type of this structure. Within braces { } there is a list with the data members, each one is specified with a type and a valid identifier as its name.
  • A data structure is an actual implementation of a particular abstract data type.
  • A means of storing a collection of data. Computer science is in part the study of methods for effectively using a computer to solve problems, or in other words, determining exactly the problem to be solved. This process entails (1) gaining an understanding of the problem; (2) translating vague descriptions, goals, and contradictory requests, and often unstated desires, into a precisely formulated conceptual solution; and (3) implementing the solution with a computer program. This solution typically consists of two parts: algorithms and data structures.
  • Data structures are some objects that we generate to store data in them , these data can be more than one variable ( Arrays can be considered as built in data structures ) They also cotain algorithms to process those stored data .
  • A collection of data components that are constructed in a regular and characteristic way.
  • v

Heaps

In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: if B is a child node of A, then key(A) ≥ key(B). This implies that an element with the greatest key is always in the root node, and so such a heap is sometimes called a max heap. (Alternatively, if the comparison is reversed, the smallest element is always in the root node, which results in a min heap.) This is why heaps are used to implement priority queues. The efficiency of heap operations is crucial in several graph algorithms.
The operations commonly performed with a heap are
delete-max or delete-min: removing the root node of a max- or min-heap, respectively
increase-key or decrease-key: updating a key within a max- or min-heap, respectively
insert: adding a new key to the heap
merge: joining two heaps to form a valid new heap containing all the elements of both.
Heaps are used in the sorting algorithm heapsort.

Accessing the heap values

Stacks

A stack is an abstract data type and data structure based on the principle of Last In First Out (LIFO). Stacks are used extensively at every level of a modern computer system.

Implementation


A typical storage requirement for a stack of n elements is O(n). The typical time requirement of O(1) operations is also easy to satisfy with a dynamic array or (singly) linked list implementation.
C++'s Standard Template Library provides a "stack" templated class which is restricted to only push/pop operations. Java's library contains a Stack class that is a specialization of Vector. This could be considered a design flaw because the inherited get() method from Vector ignores the LIFO constraint of the Stack.

The two operations applicable to all stacks are:


♀A push operation, in which a data item is placed at the location pointed to by the stack pointer, and the address in the stack pointer is adjusted by the size of the data item;
♀A pop or pull operation: a data item at the current location pointed to by the stack pointer is removed, and the stack pointer is adjusted by the size of the data item.

Some environments that rely heavily on stacks may provide additional operations, for example:
Dup(licate): the top item is popped and pushed again so that an additional copy of the former top item is now on top, with the original below it.
Peek: the topmost item is popped, but the stack pointer is not changed, and the stack size does not change (meaning that the item remains on the stack). This is also called top operation in many articles.
Swap or exchange: the two topmost items on the stack exchange places.
Rotate: the n topmost items are moved on the stack in a rotating fashion. For example, if n=3, items 1, 2, and 3 on the stack are moved to positions 2, 3, and 1 on the stack, respectively. Many variants of this operation are possible, with the most common being called left rotate and right rotate.

Graph

A graph is a kind of data structure, specifically an abstract data type (ADT), that consists of a set of nodes (also called vertices) and a set of edges that establish relationships (connections) between the nodes. The graph ADT follows directly from the graph concept from mathematics.

Graph algorithms are a significant field of interest within computer science. Typical operations associated with graphs are: finding a path between two nodes, like depth-first search and breadth-first search and finding the shortest path from one node to another, like Dijkstra's algorithm. A solution to finding the shortest path from each node to every other node also exists in the form of the Floyd-Warshall algorithm.
A directed graph can be seen as a flow network, where each edge has a capacity and each edge receives a flow. The Ford-Fulkerson algorithm is used to find out the maximum flow from a source to a sink in a graph.
The graphs can be represented in two ways. One is adjacency matrix and adjacency list.
For example, let us consider the following graph.

A----------->B
^


V
C ------------
Adjacency Matrix

A B C
A 0 1 1
B 0 0 0
C 0 1 0
Adjacency List

A ----> B ----> C ---- NULL
B ----> ---- NULL
C ----> B ---- NULL

2/4/09

Queue Report :

Queues
  • A queue is a inear list in which data can be inserted only at one end called the rear, and deleted on the other end called the front.

Queue Operations

  • There are two basic operations. The enqueue and dequeue. Although there are similarities between stacks and queues, one significant structural difference is that the queue implementation needs to keep track of the front and the rear of the queue, whereas the stack needs to worry about one end: the top.

Enqueue

  • The queue insert operation is known as enqueue. After the data have been inserted into the queue, the new element becomes the rear.

For instance, a queue has two elements 123 and 757. The element 123 is the front and the element 757 is the rear. If we want to insert a new element in a queue, we are going to insert it at the rear. And the new element becomes the rear.

If there i s niot enough room for onother element in the queue, the queue is an overflow state.

Dequeue

  • The queue delete operation is known as dequeue. The data at the front of the queue are returned to the user and removed from the queue.

For example, a queue has three elements: 123, 757, and 459. 123 is the front and 459 is the rear. If we are going to delete an element from the queue, we deleted it at the front and the element next to it becomes the front.

If there are no data in the queue when dequeue is attempted, the queue is an underflow state.

Queue Link List Design

  • We implement our queue using a linked list.
  • We ned two different structures to implement the queue: a queue head structure and a data node structure. After it is created, the queue will have one head node a nd zero depending on its current state.

Queue Head

  • The queue requires two pointers and a count. These fields are stored in the queue head structure.

The two pointers are the front and the rear. A count counts of how many datas are in the queue.

Queue Data Node

  • The queue data node contains the user data and a link field pointing to the next node, if any. These nodes are stored in a dynamic memory and are inserted and deleted as requested by the using program.