Datastructure free tutorial

Page 1

Datastructure Free Tutorial


Introduction to Datastructure In computer science, a DataStructures is a particular way and organizing data in a computer so that it can be use efficiently. A data structure is an arrangement of data in a computer memory or even disk storage. An example of several common data structures are arrays, linked lists, queues, stacks, binary trees, and hash tables. Different kinds of DataStructures are suited to different kinds of applications and some are highly specialized to specific basis. For example, 3-trees are particular well suited for implementation of databases, while compiler implementation usually use hash tables to look up identifiers.


Linear Queues in Data Structures Linear Queues A queue is an ordered list in which items may be added only at one end called the “rear” and items may be removed only at the other end called “front”. Examples A line of passengers waiting to buy tickets in a reservation counter. Each new passenger gets in line at the “rear”; the passenger at the front of the lines is reserved. A linear queue can be found in a time-sharing computer system where many users share the system simultaneously. The first element, which is added into the queue will be the first one to be removed. Thus queues are also called First-in First-Out lists (FIFO) or Last-In-Last-Out lists (LILO).


Circular Queue in Data Structures Circular Queue The Regular, static queues in data structures have a very big drawback, that once the queue is FULL, even though we delete few elements. From the “ front” and relive some occupied space, we are not able to add anymore elements, as the “rear” has already reaches the queues rear most partition. To overcome this drawback we can implement the queue as a circular queue. Here as we go on adding elements to the queue and reach the end of the array, the next element is stored in the first slot of the array (provide it is free).


Stack Applications in Data Stuctures A stack is useful in writing recursive calls. A stack is useful to convert in fix expression into post fix expression. It can be used in function calls for example, suppose that function “a” calls function “b” and passes two variables ,”x” and “y” to “b”. Then the function “a” can store these two variables on the stack, from where the function “b” can retrieve and use them.

A stack can be used to evaluate the postfix expression. A+B=>AB+=>30. A stack can be used to implement a calculator by storing the operands and the operators on the stack and using them as and when required. The stack can be used in the algorithms which needs the back traversal.


Binary search in Data Structures Binary search The binary search in data structures is yet another simple method. However in the binary search, the algorithm expect the list to be sorted you can apply any one of the sorting methods before using the binary search algorithm.

In binary search the given list is devided into two equal half’s. The given key is compared with the middle element of the list now three situations may occur. The middle element matches with the key the search will end peacefully here.

The middle element is greater than the key then the value which we are searhing is possibly in the first half of the list. The middle element is lower than the key. Then the value which were searching is possibly in the second half of the list


Postfix expression in Data Structures Evaluation of a postfix expression Suppose p is an arithmetic expression written in postfix notation. The following algorithm, which user a STACK to held operands, evaluates P. Algorithm This algorithm finds the value of an arithmetic expression P written in postfix notation Add a right parenthesis “)” at the end of p [This acts of a sentinel] Scan p from left to right and repeat steps 3 and 4 for each element of p until the sentinel ”)” is encountered. if an operand is encountered, put it on STACK If an operator X is encountered,Then : Remove the two top elements of STACK, where A is the top element and B is the next to top element Evaluate BXA Place the result of (b) back on STACK [End of if structure] [End of step2 loop] Set value equal to the top element on STACK Exit Not that, when step 5 is executed,There should only one number on STACK


Quick sort in Data Structures Quick sort The following are the steps to set up Quick Sort in Data Structures. 1. 2. 3. 4. 5. 6. 7.

Select first moment of Array A(or sub array) as pivot. Initiative and J to first and last elements of the array respectively. Increment : until A[i]>pivot;stop Decrement : until A[j]<pivot,stop if i<j : change A[i] and A[j] Repeat statements 3,4 and 5 until i>j, i.e when i and j cross each other. Exchange the pivot element with the element pointed to by J which is correct place for pivot

Note that in step 7, The swapping keeps the larger element to the right and smaller element to the left, relative to the pivot.


And Also Issues Interview Questions How to’s For More Datastructure Free Tutorials Please Visit: http://bit.ly/1tjnyfP


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.