1 tayangan

Judul Asli: Data Structure (1)

Diunggah oleh Bhuvana Pm

- Data Structures.docx
- data stucture and algorithm questions
- Data Structure Questions Bank
- Syllabus Data Structure
- Data Structures Cheat Sheet
- Data Structures VIVA Questions and Answers
- Data Structures
- Q2.Nabil Mohsen Alzeqri.docx
- Rr210301 Data Structures Through c
- Data Structures Lab Manual
- DOC-20180527-WA0030.docx
- DSA LAB
- dsmaterials-vasu
- sorting algos
- Guide to Data Structures
- Data Structures and Algorithm Questions
- Quiz Questions
- BC0038 DATA STRUCTURE USING C PAPER 2
- Ds Notes 2011
- Algorithms

Anda di halaman 1dari 26

In Linear Data structure, the elements will be in sequential order and traversal will

be in a linear manner

Example

The elements will be connected in a non linear manner. It branches to more than

one node

Eg

Stack:

Stack is a linear Data Structure which follows last in first out manner. The element

inserted last will be deleted first. Using Stack we can perform 2 main operations,

push and POP

Inserting the element into the Stack is known as Push

Undo Function uses the Stack operation, the change done recently will be

deleted first

Girls Bangles

Put some example and explain for push and pop both

QUEUE:

Queue is a linear data structure which follows First in first out .the element inserted

first will be the element deleted first

Operations Performed with the help of Queue are enqueue and dequeue

Eg:

Printer Queue

Put some example and explain for enqueue and dequeue both

LIST :

A list is a sequential data structure, i.e. a collection of items accessible one after another

beginning at the head and ending at the tail.

Operations:

Insert

Delete

Two type of List are,

Linked List:

insert

delete

Train cars are linked in a specific order so that they may be loaded, unloaded, transferred,

dropped off, and picked up in the most efficient manner possible.

U can insert or delete the compartment whenever needed (in the middle also)

In Doubly Linked Lists each node has two links: one points to previous node and

one points to next node. The

previous link of first node in the list points to a Null and the next link of last node

points to Null.

Eg:

Circularly Linked Lists:

Last node in the list points to the first node of the list. Circular Linked list can be singly linked

list and doubly linked list

Eg:

Round Robin Time Sharing jobs

(Balancing Symbols

Postfix Expressions

Trees:

Tree is a non linear data structure used to simulate the hierarchical

relationship with other nodes

EG

Show leaves

the leaves in

the tree above are B, C, H, I, P, Q, K, L, M, and N.

Nodes with the same parent are siblings ;

thus K, L, and M are all siblings

For any node ni, the depth of ni is the length of the unique path from the root to ni. Thus, the root

is at depth 0.

The height of ni is the longest path from ni

to a leaf. Thus all leaves are at height 0. The height of a tree is equal to the height of the root. For

the tree in

Figure 4.2, E is at depth 1 and height 2; F

is at depth 1 and height 1; the height of the tree is 3. The depth of a tree is equal to the depth of

the deepest

leaf; this is always equal to the height of the tree.

Binary trees:

A binary tree is a tree in which no node can have more than two children

constants or variable names, and the other nodes contain operators . This particular tree happens

to be binary,

because all of the operations are binary, and although this is the simplest case, it is possible for

nodes to have

more than two children. It is also possible for a node to have only one child, as is the case with

the unary minus

operator

Insert,delete also

AVL Tree

balance

condition.

and right subtrees have the same height

Single Rotation

Left Rotation

If a tree becomes unbalanced, when a node is inserted into the right

subtree of the right subtree, then we perform a single left rotation

right subtree of A's right subtree. We perform the left rotation by

making A the left-subtree of B.

Right Rotation

AVL tree may become unbalanced, if a node is inserted in the left subtree of

the left subtree. The tree then needs a right rotation.

As depicted, the unbalanced node becomes the right child of its left child by

performing a right rotation.

Double Rotation

Left-Right Rotation

Double rotations are slightly complex version of already explained versions

of rotations. To understand them better, we should take note of each action

performed while rotation. Let's first check how to perform Left-Right

rotation. A left-right rotation is a combination of left rotation followed by

right rotation.

State Action

A node has been inserted into the right subtree of the left

subtree. This makes C an unbalanced node. These

scenarios cause AVL tree to perform left-right rotation.

This makes A, the left subtree of B.

the left-subtree of the left-subtree.

We shall now right-rotate the tree, making B the new root

node of this subtree. C now becomes the right subtree of

its own left subtree.

Right-Left Rotation

The second type of double rotation is Right-Left Rotation. It is a

combination of right rotation followed by left rotation.

State Action

A node has been inserted into the left subtree of the right

subtree. This makes A, an unbalanced node with balance

factor 2.

First, we perform the right rotation along C node,

making C the right subtree of its own left subtree B.

Now, B becomes the right subtree of A.

its right subtree and requires a left rotation.

of the subtree. A becomes the left subtree of its right

subtree B.

The tree is

Heap is a special case of balanced binary tree data structure where the

root-node key is compared with its children and arranged accordingly

A Binary Search Tree (BST) is a tree in which all the nodes follow the below-

mentioned properties

The left sub-tree of a node has a key less than or equal to its parent

node's key.

The right sub-tree of a node has a key greater than to its parent node's

key.

Thus, BST divides all its sub-trees into two segments; the left sub-tree and

the right sub-tree and can be defined as

Linear search is a very simple search algorithm. In this type of search, a

sequential search is made over all items one by one. Every item is

checked and if a match is found then that particular item is returned,

otherwise the search continues till the end of the data collection.

n). This search algorithm works on the principle of divide and conquer. For

this algorithm to work properly, the data collection should be in the sorted

form.

Binary search looks for a particular item by comparing the middle most item

of the collection. If a match occurs, then the index of item is returned. If

the middle item is greater than the item, then the item is searched in the

sub-array to the left of the middle item. Otherwise, the item is searched for

in the sub-array to the right of the middle item. This process continues on

the sub-array as well until the size of the subarray reduces to zero.

Heap is a special case of balanced binary tree data structure where the

root-node key is compared with its children and arranged accordingly.

If has child node then

key() key()

generates Max Heap. Based on this criteria, a heap can be of two types

For Input 35 33 42 10 14 19 27 44 26 31

Min-Heap Where the value of the root node is less than or equal to

either of its children.

Max-Heap Where the value of the root node is greater than or equal to

either of its children.

Both trees are constructed using the same input and order of arrival.

Structure Property

A heap is a binary tree that is completely filled, with the possible exception

of the bottom level, which is filled from left to right.

Heap-Order Property

The property that allows operations to be performed quickly is the heap-

order property.

Since we want to be able to find the minimum quickly, it makes sense that

the smallest element should be at the root. If we consider that any subtree

should also be a heap, then any node should be smaller than all of its

descendants.

comparison-based algorithm in which each pair of adjacent elements is

compared and the elements are swapped if they are not in order.

We take an unsorted array for our example. Bubble sort takes (n 2) time so

we're keeping it short and precise.

Bubble sort starts with very first two elements, comparing them to check

which one is greater.

Next, we compare 33 with 27.

We find that 27 is smaller than 33 and these two values must be swapped.

Next we compare 33 and 35. We find that both are in already sorted

positions.

Then we move to the next two values, 35 and 10.

We know then that 10 is smaller 35. Hence they are not sorted.

We swap these values. We find that we have reached the end of the array.

After one iteration, the array should look like this

To be precise, we are now showing how an array should look like after each

iteration. After the second iteration, it should look like this

Notice that after each iteration, at least one value moves at the end.

And when there's no swap required, bubble sorts learns that an array is

completely sorted.

Insertion Sort

The array is searched sequentially and unsorted items are moved and

inserted into the sorted sub-list (in the same array).

We take an unsorted array for our example.

It finds that both 14 and 33 are already in ascending order. For now, 14 is

in sorted sub-list.

It swaps 33 with 27. It also checks with all the elements of sorted sub-list.

Here we see that the sorted sub-list has only one element 14, and 27 is

greater than 14. Hence, the sorted sub-list remains sorted after swapping.

10.

So we swap them.

We swap them again. By the end of third iteration, we have a sorted sub-list

of 4 items.

This process goes on until all the unsorted values are covered in a sorted

sub-list. Now we shall see some programming aspects of insertion sort.

Selection Sort

The smallest element is selected from the unsorted array and swapped with

the leftmost element, and that element becomes a part of the sorted array.

This process continues moving unsorted array boundary by one element to

the right.

This algorithm is not suitable for large data sets as its average and worst

case complexities are of (n2), where n is the number of items.

How Selection Sort Works?

Consider the following depicted array as an example.

For the first position in the sorted list, the whole list is scanned sequentially.

The first position where 14 is stored presently, we search the whole list and

find that 10 is the lowest value.

So we replace 14 with 10. After one iteration 10, which happens to be the

minimum value in the list, appears in the first position of the sorted list.

For the second position, where 33 is residing, we start scanning the rest of

the list in a linear manner.

We find that 14 is the second lowest value in the list and it should appear at

the second place. We swap these values.

After two iterations, two least values are positioned at the beginning in a

sorted manner.

The same process is applied to the rest of the items in the array.

Now, let us learn some programming aspects of selection sort.

With worst-case time complexity being (n log n), it is one of the most

respected algorithms.

Merge sort first divides the array into equal halves and then combines them

in a sorted manner.

How Merge Sort Works?

To understand merge sort, we take an unsorted array as the following

We know that merge sort first divides the whole array iteratively into equal

halves unless the atomic values are achieved. We see here that an array of

8 items is divided into two arrays of size 4.

This does not change the sequence of appearance of items in the original.

Now we divide these two arrays into halves.

We further divide these arrays and we achieve atomic value which can no

more be divided.

Now, we combine them in exactly the same manner as they were broken

down. Please note the color codes given to these lists.

We first compare the element for each list and then combine them into

another list in a sorted manner. We see that 14 and 33 are in sorted

positions. We compare 27 and 10 and in the target list of 2 values we put

10 first, followed by 27. We change the order of 19 and 35 whereas 42 and

44 are placed sequentially.

In the next iteration of the combining phase, we compare lists of two data

values, and merge them into a list of found data values placing all in a

sorted order.

After the final merging, the list should look like this

insertion sort algorithm. This algorithm avoids large shifts as in case of

insertion sort, if the smaller value is to the far right and has to be moved to

the far left.

This algorithm uses insertion sort on a widely spread elements, first to sort

them and then sorts the less widely spaced elements. This spacing is

termed as interval. This interval is calculated based on Knuth's formula as

Knuth's Formula

h=h*3+1

where

h is interval with initial value 1

This algorithm is quite efficient for medium-sized data sets as its average

and worst case complexity are of (n), where n is the number of items.

Let us consider the following example to have an idea of how shell sort

works. We take the same array we have used in our previous examples. For

our example and ease of understanding, we take the interval of 4. Make a

virtual sub-list of all values located at the interval of 4 positions. Here these

values are {35, 14}, {33, 19}, {42, 27} and {10, 14}

We compare values in each sub-list and swap them (if necessary) in the

original array. After this step, the new array should look like this

Then, we take interval of 2 and this gap generates two sub-lists - {14, 27,

35, 42}, {19, 10, 33, 44}

We compare and swap the values, if required, in the original array. After

this step, the array should look like this

Finally, we sort the rest of the array using interval of value 1. Shell sort

uses insertion sort to sort the array.

We see that it required only four swaps to sort the rest of the array.

partitioning of array of data into smaller arrays. A large array is partitioned

into two arrays one of which holds values smaller than the specified value,

say pivot, based on which the partition is made and another array holds

values greater than the pivot value.

Quick sort partitions an array and then calls itself recursively twice to sort

the two resulting subarrays. This algorithm is quite efficient for large-sized

data sets as its average and worst case complexity are of (nlogn),

where n is the number of items.

Following animated representation explains how to find the pivot value in an

array.

The pivot value divides the list into two parts. And recursively, we find the

pivot for each sub-lists until all lists contains only one element.

Initially on receiving an unsorted list, the first step in heap sort is to create a Heap data

structure(Max-Heap or Min-Heap). Once heap is built, the first element of the Heap is either

largest or smallest(depending upon Max-Heap or Min-Heap), so we put the first element of

the heap in our array. Then we again make heap using the remaining elements, to again

pick the first element of the heap and put it into the array. We keep on doing the same

repeatedly untill we have the complete sorted list in our array.

- Data Structures.docxDiunggah olehRitesh Singh
- data stucture and algorithm questionsDiunggah olehAnmol Rajat
- Data Structure Questions BankDiunggah olehnooti
- Syllabus Data StructureDiunggah olehapi-3747330
- Data Structures Cheat SheetDiunggah olehamitgos
- Data Structures VIVA Questions and AnswersDiunggah olehAchyuth Koteswarao
- Data StructuresDiunggah olehMohammed Jeelan
- Q2.Nabil Mohsen Alzeqri.docxDiunggah olehNabil Alzeqri
- Rr210301 Data Structures Through cDiunggah olehSRINIVASA RAO GANTA
- Data Structures Lab ManualDiunggah olehsarika
- DOC-20180527-WA0030.docxDiunggah olehAnonymous 0JjbNf70vQ
- DSA LABDiunggah olehGokulraj Jayaraman
- dsmaterials-vasuDiunggah olehKiran All Iz Well
- sorting algosDiunggah olehsupra474
- Guide to Data StructuresDiunggah olehAbhishek Dixit
- Data Structures and Algorithm QuestionsDiunggah olehMuhammad Saqib
- Quiz QuestionsDiunggah olehHimanshu Aggarwal
- BC0038 DATA STRUCTURE USING C PAPER 2Diunggah olehSeekEducation
- Ds Notes 2011Diunggah olehcaptainclock
- AlgorithmsDiunggah olehkhey
- DSDiunggah olehJimmy Bector
- Data StructureDiunggah olehAnkita Nitin Soni
- Datastructures LabDiunggah olehgmerlingeorge
- Implementation of Data Structures ConceptDiunggah olehMayank Jaiswal
- wipro cDiunggah olehapi-3844691
- Preface Table of ContDiunggah olehSuNny Khan
- data structure notes 1.docDiunggah olehRaja Kushwah
- Team 9 -Phase 1 DocDiunggah olehHazem
- Chap 10Diunggah olehyasinmhd
- DS HandoutDiunggah olehAvinash Singh

- 8. Management-Implimentation of Single Chanel Queuing-Chitrakant SahuDiunggah olehBESTJournals
- ManufacturigCase StudyDiunggah olehshruthicivil
- TemplatesDiunggah olehsandeepcuc
- Article FileDiunggah olehZakiah Abu Kasim
- CL,Ds&Dta QuestionsDiunggah olehMoulikpl
- 2. ZTE RNC Performance Counter RefDiunggah olehBeliever
- International Journal of Mathematics and Statistics Invention (IJMSI)Diunggah olehinventionjournals
- Computer Programming QuestionsDiunggah olehAravind Kumaran
- DS MCQDiunggah olehNitin Sadanand
- Data StructureDiunggah olehRAM
- Chapter 3.4 - Data Representation, Structure and Manipulation (Cambridge AL 9691)Diunggah olehlyceum_fans
- UntitledDiunggah olehVikrant Patil
- J1939 Lib for PIC16 MCP2515.pdfDiunggah olehHector Sanchez
- NOTES ON dsDiunggah olehrameelapradeoth
- Queuing simulationDiunggah olehNurtegin Rysbaev
- ca7 commandsDiunggah olehdhanalekshmiramesh
- ads r16Diunggah olehChristina Robinson
- Rexx TrainingDiunggah olehDeepak Dada
- AgentDiunggah olehGaddam Neeraj
- 9A05101 Programming in C and Data StructuresDiunggah olehsivabharathamurthy
- Build a Super Simple TaskerDiunggah olehKanashimi Kotoba
- VTU 3RD SEM CSE DATA STRUCTURES WITH C NOTES 10CS35Diunggah olehEKTHATIGER633590
- Queuing TheoryDiunggah olehGirish Kumar Nistala
- Data Structure BCA14Diunggah olehapi-3732063
- 131352-LMDiunggah olehsridharanc23
- AdaDiunggah olehsagarkondamudi
- Queuing TheoryDiunggah olehvaibhavmiskeen
- Troubleshoot and Track BDoc Messages[1]Diunggah olehSailaja Reddy
- r 3 ExtractionDiunggah olehgoose
- Data Structures Using CDiunggah olehVikram Rao