Data Structures - MLN
Data Structures - MLN
NAGARAJU M L
ASSISTANT PROFESSOR
DEPARTMENT OF MCA
ACHARYA INSTITUTE OF GRADUATE
STUDIES
SOLADEVANAHALLI, BANGALORE
DATA STRUCTURE
Operations:
1. Create: int x;
2. Select: cout<<x;
3. Update: x = x + 10;
4. Destroy: delete x;
NON-PRIMITIVE DATA STRUCTURE
Array:
Liked List:
Stacks:
Queues:
NON-LINEAR DATA STRUCTURE
Types:
1. One-Dimensional Array or Linear Array
2. Two-Dimensional Array
3. Multi-Dimensional Array
TYPES OF ARRAYS
One-Dimensional Array or Linear Array: The array in
which the elements are accessed by using only one index.
1. Traversing
2. Insertion
3. Deletion
4. Searching
5. Sorting
6. Merging
TRAVERSING
Traversal in a Linear Array is the process of
visiting each element once.
Traversal is done by starting with the first
TRAVERSAL(A, N)
Step1: FOR I = 0 to N-1
PROCESS(A[I])
[ end of FOR ]
Step2: Stop
INSERTION
Adding new element into the array
Initially
After Insertion
INSERTION
ALGORITHM:
INSERTION(A, N, ELE, POS)
Step1: FOR I = N-1 DOWNTO POS
A[I+1] = A[I]
[end of FOR]
Step2: A[POS] = ELE
Step3: N = N + 1
Step4: Stop
DELETION
Removing an element from the array
Initially
After Deletion
Methods:
1. Linear Search or Sequential Search
2. Binary Search
LINEAR SEARCH
It is also called Sequential Search.
It can be applied on unsorted array.
Algorithm:
LINEARSEARCH(A, N, KEY)
Step1: LOC = -1
Step2: FOR I = 1 TO N
IF (KEY == A[I])
LOC = I
goto Step3
[end of IF]
[end of FOR]
Step3: IF (LOC == – 1)
Print “ Element not found”
ELSE
Print “Element found at “, LOC
Step4: Stop
BINARY SEARCH
It can be applied only on sorted array.
It is based on Divide and Conquer Technique.
Algorithm:
BINARYSEARCH(A, N, KEY)
Step1: LOC = -1, BEG = 0, END = N–1
Step2: Repeat WHILE (BEG <= END)
MID = (BEG + END)/2
IF ( KEY == A[MID] )
LOC = MID
goto Step3
ELSE IF (KEY < A[MID])
END = MID – 1
ELSE
BEG = MID + 1
[ end of IF ]
[ end of WHILE ]
Step3: IF (LOC == – 1)
Print “ Element not found”
BINARY SEARCH
Step3: IF (LOC == – 1)
Print “ Element not found”
ELSE
Print “Element found at “, LOC
[ end of IF ]
Step4: Stop
SORTING
Definition: Arranging the elements in a
particular order is called sorting.
Methods:
1. Bubble Sort
2. Selection Sort
3. Insertion Sort
4. Merge Sort
5. Quick Sort
6. Radix Sort
7. Heap Sort
BUBBLE SORT
Algorithm:
BUBBLESORT(A, N)
Sept1. FOR I = 1 to N – 1
FOR J = 1 to N–I–1
IF ( A[J] > A[J+1]
TEMP = A[J]
A[J] = A[J+1]
A[J+1] = TEMP
[ end of IF ]
[ end of FOR ]
[ end of FOR ]
THANK YOU