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

TERM PAPER

EXPOSURE TO COMPUTER DISCIPLINE CSE 102

Topic: Explain the different operations on different types of data structures

DOA:10-02-10 DOS: 05-05-10

Submitted to: Ms. GEETIKA BHARDWAJ Deptt. CSE/IT

Submitted by: PRAVEEN KUMAR SINGH Roll. No. A30 Reg.No. 10905912 Section: C1903

ACKNOWLEDGEMENT

As usual large number of people deserves my thanks for the help they provided me for the preparation for this term paper. First of all I would like to thanks my teacher Miss. GEETIKA BHARDWAJ for his support during the preparation of this topic . I am very thankful for his guidance. I would also like to thanks my friends for the encouragement and information about the topic they provided to me during to me during my effort to prepare this topic.

INTRODUCTION TO DATA STRUCTURE


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 a group of data elements grouped together under one name. These data elements, known as members, can have different types and different lengths.

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 creates a new type:

Once a data structure is declared, a new type with the identifier specified as structure_name is created and can be used in the rest of the program as if it was any other type.

Example: struct product { int weight;

float price;

}; product apple; product banana, melon; Once declared, product has become a new valid type name like the fundamental ones int, char or short and from that point on we are able to declare objects (variables) of this compound new type, like we have done with apple, banana and melon. Right at the end of the struct declaration, and before the ending semicolon, we can use the optional field object_name to directly declare objects of the structure type. For example, we can also declare the structure objects apple, banana and melon at the moment we define the data structure type this way: struct product { int weight; float price; } apple, banana, melon;

struct structure_name { member_type1 member_name1; member_type2 member_name2; member_type3 member_name3; } object_names;

In computer science, a data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently.[1][2] 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 to look up identifiers. Data structures are used in almost every program or software system. Specific data structures are essential ingredients of many efficient algorithms, and make possible the management of huge amounts of data, such as large databases and internet indexing services. Some formal design methods and programming languages

emphasize data structures, rather than algorithms, as the key organizing factor in software design.

List of data structures This is a list of data structures. For a wider list of terms, see list of terms relating to algorithms and data structures. For a comparison of running time of subset of this list see comparison of data structures. Contents

1Data types o Primitive types o Composite types o Abstract data types 2 Linear data structures o 2.1 Arrays o 2.2 Lists 3 Trees o 3.1 Binary trees o 3.2 B-trees Primitive types o 3.3 Heaps o 3.4 Tries Boolean o 3.5 Multiway trees Character o 3.6 Space-partitioning trees Integer o 3.7 Application-specific trees String 4 Hashes Double Float 5 Graphs

Data types A data type (or datatype) In programming, a classification identifying one of various types of data, as floating-point, integer, or Boolean, stating the possible values for that type, the operations that can be done on that type, and the way the values of that type are stored

Composite types

Record (also called tuple or struct) Union Tagged union (also called a variant, variant record, discriminated union, or disjoint union)

Abstract data types

Container Deque List Map Multimap Multiset Priority queue Queue Set Stack String Tree

Some properties of abstract data types: Structure Stable Unique Cells per Node Bag (multiset) No No 1 Set No Yes 1 List Yes No 1 Map No Yes 2 "Stable" means that input order is retained. Other structures such as "linked list" and "stack" cannot easily be defined this way because there are specific operations associated with them.

Linear arrays:- List of finite number n of homogeneous data elements such that:

1. Elements of array are referenced resp. by an index set consisting of n consecutive numbers 2. Elements of array are stored respectively in successive memory locations 3. The number n of elements is called the length or size of array 4. Length or no. of elements can be obtained from index set by formula:5. 6. Length =UB-LB+1 7. UB-Upper Bound i.e largest index 8. LB-Lower Bound i.e smallest index 9. If LB=1,then Length=UB

Stack:- It is also called last-in-first-out(LIFO) system It is a linear list where insertions and deletions can take place at one end called top 2 operations: Push-To insert an element on top of stack Pop-To delete an element from top of stack

Example of stack:typedef struct stack_Rep stack_Rep; /* Type: instance representation (an opaque record). */ typedef stack_Rep *stack_T; /* Type: handle to a stack instance (an opaque pointer). */ typedef void *stack_Item; /* Type: value that can be stored in stack (arbitrary address). */ stack_T stack_create(void); /* Create new stack instance, initially empty. */ void stack_push(stack_T s, stack_Item e); /* Add an item at the top of the stack. */ stack_Item stack_pop(stack_T s); /* Remove the top item from the stack and return it . */ int stack_empty(stack_T ts); /* Check whether stack is empty. */ This implementation could be used in the following manner: #include <stack.h> /* Include the stack interface. */ stack_T t = stack_create(); /* Create a stack instance. */ int foo = 17; /* An arbitrary datum. */ t = stack_push(t, &foo); /* Push the address of 'foo' onto the stack. */ void *e = stack_pop(t); /* Get the top item and delete it from the stack. */ if (stack_empty(t)) { } /* Do something if stack is empty. */ typedef struct stack_Rep stack_Rep; /* Type: stack state representation (an opaque record). */ typedef stack_Rep *stack_T; /* Type: handle to a stack state (an opaque pointer). */ typedef void *stack_Item; /* Type: item (arbitrary address). */ stack_T stack_empty(void); /* Returns the empty stack state. */ stack_T stack_push(stack_T s, stack_Item x); /* Adds x at the top of s, returns the resulting state. */ stack_Item stack_top(stack_T s); /* Returns the item currently at the top of s. */

stack_T stack_pop(stack_T s); /* Remove the top item from s, returns the resulting state. */

Linked List:- It is a linear collection of data elements called nodes. Linear order is maintained by pointers 3 types of linked list:1. Linear 2. Doubly 3. Circular Linear linked list Each node is divided into 2 parts:1. It contains information of element 2. It is called link field/next field pointer contains address of next node in the list 3. Another pointer variable called head contains address of first element 4. Last element of linked list has NULL value

Doubly Linked List Each node is divided into 3 parts:1. It contains information of element 2. It is called previous pointer field pointer contains address of preceding element in the list 3. It is called next pointer field pointer contains address of succeeding element in the list Example of link list:typedef struct { int size;

int items[STACKSIZE]; } STACK; void push(STACK *ps, int x) { if (ps->size == STACKSIZE) { fputs("Error: stack overflow\n", stderr); abort(); } else ps->items[ps->size++] = x; } int pop(STACK *ps) { if (ps->size == 0){ fputs("Error: stack underflow\n", stderr); abort(); } else return ps->items[--ps->size]; }

typedef struct stack { int data; struct stack *next; } STACK; void push(STACK **head, int value) { STACK *node = malloc(sizeof(STACK)); /* create a new node */ if (node == NULL){ fputs("Error: no space available for node\n", stderr); abort();

} else { /* initialize node */ node->data = value; node->next = empty(*head) ? NULL : *head; /* insert new head if any */ *head = node; } } int pop(STACK **head) { if (empty(*head)) { /* stack is empty*/ fputs("Error: stack underflow\n", stderr); abort(); } else { /* pop a node */ STACK *top = *head; int value = top->data; *head = top->next; free(top); return value; }

#include<stdio.h> int main() Stack 29 { int a[100], i; printf("To pop enter -1\n"); for(i = 0;;) { printf("Push "); scanf("%d", &a[i]);

if(a[i] == -1) { if(i == 0) { printf("Underflow\n"); } else { printf("pop = %d\n", a[--i]); } } else { i++; } } } Example (Pascal) This is an implementation in Pascal, using marked sequential file as data archives. { programmer : clx321 file : stack.pas unit : Pstack.tpu } program TestStack; {this program use ADT of Stack, i will assume that the unit of ADT of Stack has already existed} uses PStack; {ADT of STACK} {dictionary}

const mark = '.'; var data : stack; f : text; cc : char; Stack 30 ccInt, cc1, cc2 : integer; {functions} IsOperand (cc : char) : boolean; {JUST Prototype} {return TRUE if cc is operand} ChrToInt (cc : char) : integer; {JUST Prototype} {change char to integer} Operator (cc1, cc2 : integer) : integer; {JUST Prototype} {operate two operands} {algorithms} begin assign (f, cc); reset (f); read (f, cc); {first elmt} if (cc = mark) then begin writeln ('empty archives !'); end else begin repeat if (IsOperand (cc)) then begin ccInt := ChrToInt (cc);

push (ccInt, data); end else begin pop (cc1, data); pop (cc2, data); push (data, Operator (cc2, cc1)); end; read (f, cc); {next elmt} until (cc = mark); end; close (f); end.

Queues:- It is also called First in First out(FIFO) A linear list in which insertions can take place at one end of the list called rear of list deletions can take place at other end of the list called front of list A queue is an example of commonly used simple data structure. A queue has beginning and end, called the front and back of the queue. Data enters the queue at one end and leaves at the other. Because of this, data exits the queue in the same order in which it enters the queue, like people in a checkout line at a supermarket

Example C Program
#include <stdio.h> int main(){ int a[100],i,j; printf("To DQueue Enter -1\n"); for(i=0;;){

printf("NQueue "); scanf("%d",&a[i]); if(a[i]==0) break; if(a[i]==-1){ a[i]=0; if(i==0){ printf("Wrong\n"); continue; } printf("DQueue = %d\n",a[0]); for(j=0;j<i;j++) a[j]=a[j+1]; i--; } else i++; } for(j=0;j<i;j++) printf("%d ",a[j]); return 0; }

Example Pascal Program


Based on an example in R.S Algorithms . program queue; type link=^node; node=record next:link; Queue 35

key:integer; end; var U:integer; tail,Head:link; procedure queinit; // Initializes the queue begin New(tail); tail^.next:=nil; head:=tail; end; procedure put(u: integer); // Puts number u into the queue var t: link; begin New(t); tail^.key := u; tail^.next := t; tail := t; end; function pop:integer; //Pops one number at a time var s:link; begin pop:=head^.key; s:=head; head:=head^.next; dispose(s); end; function empty:boolean;//checks if the queue is empty

begin empty:=head=tail; end; begin queinit; u := 1; put(u); // Put 1 in the queue u := 2; Queue 36

Trees:- A tree T is defied as finite set of elements called nodes Either T is empty called null tree or empty tree T contains a distinguished node R called root of T and remaining nodes form an ordered pair of binary tress T1 and T2

Lists:- A list is an ordered set of data. It is often used to store objects that are to be processed sequentially. A list can be used to create a queue. Linear data structures Arrays

Array Bit field Bit array Bitboard Bitmaps Images Dynamic array

Circular buffer Control table Gap Buffer Hashed array tree Heightfields Lookup table Matrix Parallel array Sparse array Sparse matrix

Links:-Links between the entities are expressed using the indexes of objects in arrays.

Lists

Linked list Doubly linked list Xor linked list

Unrolled linked list Zipper Vlist Skip list Jump list Self-organizing list

Trees Binary trees


Binary tree Binary search tree Self-balancing binary search tree Randomized binary search tree Weight-balanced tree Threaded binary tree AVL tree Red-black tree AA tree Scapegoat tree Splay tree T-tree Rope Top Trees Tango Trees Cartesian tree Van Emde Boas tree Treap

B-trees

B-tree B+ tree B*-tree B sharp tree Dancing tree 2-3 tree 2-3-4 tree Queaps

Fusion tree Bx-tree

Heaps

Heap Binary heap Binomial heap Fibonacci heap 2-3 heap Soft heap Pairing heap Leftist heap Treap Beap Skew heap Ternary heap D-ary heap

Tries In these data structures each tree node compares a bit slice of key values.

Trie Radix tree Suffix tree Suffix array Compressed suffix array FM-index Generalised suffix tree B-trie Judy array

Multiway trees

Ternary search tree Andor tree (a,b)-tree Link/cut tree SPQR-tree Spaghetti stack

Disjoint-set data structure Fusion tree Enfilade Exponential tree Fenwick tree

Space-partitioning trees This is data structures used for space partitioning or binary space partitioning.

Segment tree Interval tree Range tree Bin Kd-tree Implicit kd-tree Min/max kd-tree Adaptive k-d tree Kdb tree Quadtree Octree Linear octrees Z-order UB-tree R-tree R+ tree R* tree Hilbert R-tree X-tree Metric tree Cover tree M tree VP-tree BK-tree Bounding interval hierarchy BSP tree

Application-specific trees

Syntax tree

Abstract syntax tree Parse tree Decision tree Alternating decision tree Minimax tree Expectiminimax tree Finger tree

Hashes

Hash table Bloom filter Hash list Hash tree Prefix hash tree Hash trie Hash array mapped trie Distributed hash table Koorde

Graphs

Graph Adjacency list Adjacency matrix Graph-structured stack Scene graph Binary decision diagram Zero suppressed decision diagram And-inverter graph Propositional directed acyclic graph

References
1. R.S. SALARIA Data structure 2. Dinesh Metha and Sartaj Sahni Handbook of Data Structures and

Applications,
3. Alfred V. Aho, Jeffrey D. Ullman, John E. Hopcroft. Data Structures and Algorithms. Addison Wesley, 1983.

4. Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein. Introduction to Algorithms. McGraw-Hill, 2001. 5. Donald E. Knuth. The Art of Computer Programming, Volumes 1-3. Addison-Wesley Professional, 1998.

Вам также может понравиться