Upcoming SlideShare
×

# Short dec

452 views

Published on

data structure importants notes

Published in: Technology
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
Your message goes here
• Be the first to comment

• Be the first to like this

Views
Total views
452
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
10
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Short dec

1. 1. ARRAYan array data structure or simply an array is a data structure consisting of a collectionof elements (values orvariables), each identified by at least one array index or key.ApplicationsArrays are used to implement mathematical vectors and matrices, as well as other kinds ofrectangular tables.One-dimensional arraysA one-dimensional array (or single dimension array) is a type of linear array. Accessing itselements involves a single subscript which can either represent a row or column index.As an example consider the C declaration int anArrayName[10];Multidimensional arraysFor a two-dimensional array, the element with indices i,j would have address B + c · i + d · j,where the coefficients c and d are the rowand column address increments, respectively.For example: int a[3][2];STACK::A stack is a list in which insertion and deletion take place at the same endThis end is called topThe other end is called bottomStacks are known as LIFO (Last In, First Out) lists.The last element inserted will be the first to be retrievedPrimary operations: Push and PopPushAdd an element to the top of the stackPopRemove the element at the top of the stackImplementation of StacksAny list implementation could be used to implement a stackArrays (static: the size of stack is given initially)Linked lists (dynamic: never become full)CODE)CHECK ITLB=O;TOP=LB; INSEERTIONWHILE TOP!= 4READ XNUM[TOP]=XTOP=TOP+1TOP=TOP-1WHILE TOP!= -1 DELETION {TOP= TOP -1}QEUEE
2. 2. Like a stack, a queue is also a list. However, with a queue, insertion is done at one end, whiledeletion is performed at the other end.Accessing the elements of queues follows a First In, First Out (FIFO) order.Like customers standing in a check-out line in a store, the first customer in is the first customerserved.Enqueue and DequeuePrimary queue operations: Enqueue and DequeueLike check-out lines in a store, a queue has a front and a rear.Enqueue – insert an element at the rear of the queueDequeue – remove an element from the front of the queueImplementation of QueueJust as stacks can be implemented as arrays or linked lists, so with queues.Dynamic queues have the same advantages over static queues as dynamic stacks have over staticstacksQueue Implementation of ArrayThere are several different algorithms to implement Enqueue and DequeueNaïve wayWhen enqueuing, the front index is always fixed and the rear index moves forward in the array. rear rear rear 3 3 6 3 6 9 front front front Enqueue(3) Enqueue(6) Enqueue(9)Naïve way (cont’d)When dequeuing, the front index is fixed, and the element at the front the queue is removed.Move all the elements after it by one position. (Inefficient!!!)
3. 3. rear rear rear = -1 6 9 9 front front front Dequeue() Dequeue() Dequeue()Delete ( ):Description: Here QUEUE is an array with N locations. FRONT and REAR points to the frontand rear ofthe QUEUE.1. If (FRONT == 0) Then [Check for underflow]2. Print: Underflow3. Else4. ITEM = QUEUE[FRONT]5. If (FRONT == REAR) Then [Check if only one element is left](a) Set FRONT = 0(b) Set REAR = 06. Else7. Set FRONT = FRONT + 1 [Increment FRONT by 1][End of Step 5 If]8. Print: ITEM deleted[End ofInsert ( ):Description: Here QUEUE is an array with N locations. FRONT and REAR points to the frontand rear ofthe QUEUE. ITEM is the value to be inserted.1. If (REAR == N) Then [Check for overflow]2. Print: Overflow3. Else4. If (FRONT and REAR == 0) Then [Check if QUEUE is empty](a) Set FRONT = 1(b) Set REAR = 15. Else6. Set REAR = REAR + 1 [Increment REAR by 1][End of Step 4 If]7. QUEUE[REAR] = ITEM8. Print: ITEM inserted[End of Step 1 If]9. ExitLINKLIST A linked list or one way list is a linear collection of data elements called nodes where the linearorder is given by means of pointers. That is each node is divided into two parts the first part