Operation performed by Linear Structure

Slides:



Advertisements
Similar presentations
Linked Lists Linked Lists Representation Traversing a Linked List
Advertisements

Algorithms (and Datastructures) Lecture 3 MAS 714 part 2 Hartmut Klauck.
One Dimensional Arrays
Lecture # 02 07/02/2013Dr. Muhammad Umair 1. 07/02/2013Dr. Muhammad Umair 2  Numeric  Integer Numbers  0,10,15,4563 etc.  Fractional Number  10.5,
Lecture - 1 on Data Structures. Prepared by, Jesmin Akhter, Lecturer, IIT,JU Data Type and Data Structure Data type Set of possible values for variables.
INTRODUCTION TO DATA STRUCTURE. Topics To Be Discussed………………………. Meaning of Data Structure Classification of Data Structure Data Structure Operations.
C o n f i d e n t i a l Developed By Nitendra NextHome Subject Name: Data Structure Using C Title: Overview of Data Structure.
ARRAYS, RECORDS AND POINTER
Chapter Complexity of Algorithms –Time Complexity –Understanding the complexity of Algorithms 1.
Introduction to Data Structures. Definition Data structure is representation of the logical relationship existing between individual elements of data.
Design and Analysis of Algorithms CSC201 Shahid Hussain 1.
Array.
CSC 211 Data Structures Lecture 7
Lecture DS & Algorithms:09 Abstract Data Types. Lecture DS & Algorithms:09 2 Abstract Data Types Data Type: A data type is a collection of values and.
Chapter 2 ARRAYS.
Course Teacher: Moona Kanwal
Arrays.
Data Strcutures.
 DATA STRUCTURE DATA STRUCTURE  DATA STRUCTURE OPERATIONS DATA STRUCTURE OPERATIONS  BIG-O NOTATION BIG-O NOTATION  TYPES OF DATA STRUCTURE TYPES.
Data Structure Introduction.
Lecture -3 on Data structures Array. Prepared by, Jesmin Akhter, Lecturer, IIT, JU Array Data structures are classified as either linear or nonlinear.
Elementary Data Organization. Outline  Data, Entity and Information  Primitive data types  Non primitive data Types  Data structure  Definition 
Review Sorting algorithms Selection Sort Insertion Sort Bubble Sort Merge Sort Quick Sort.
Data Structures & Algorithms CHAPTER 1 Introduction Ms. Manal Al-Asmari.
 Array is a data structure were elements are stored in consecutive memory location.in the array once the memory is allocated.it cannot be extend any more.
Data Structure and Algorithms
INTRODUCTION OF ARRAY. Topics To Be Discussed………………………. Introduction Types of array One Dimensional Array Internal representation of one-dimensional array.
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
1. Traversing a linear array Here A is a linear array with lower bound LB and upper bound UB. This algorithm traverses A applying an operation PROCESS.
Sorting and Searching Bubble Sort Linear Search Binary Search.
Data Structure and Algorithms - S.S. Deshmukh. Linear Search algorithm 1.[Intialize] Set K:=1, LOC:= 0 2.Repeat Step 3 & 4 while LOC:=0 & K
Chapter 11 (Lafore’s Book) Hash Tables Hwajung Lee.
LINKED LISTS.
Lecture 2. Algorithms and Algorithm Convention 1.
Trees Binary Trees Extended Binary Trees. Tree A Tree consist of Nodes connected by Edges. Node is represented by Circle Edges as Lines or Arrows A Tree.
Introduction toData structures and Algorithms
Sort Algorithm.
Chapter 16: Searching, Sorting, and the vector Type
Introduction to Data Structures
Understanding Algorithms and Data Structures
Course Developer/Writer: A. J. Ikuomola
Data Structures I (CPCS-204)
Fundamentals of Java: AP Computer Science Essentials, 4th Edition
Lectures linked lists Chapter 6 of textbook
Data Structures & File Processing
Computer Programming BCT 1113
Sorting.
Merging Merge. Keep track of smallest element in each sorted half.
GC211Data Structure Lecture2 Sara Alhajjam.
Lecture – 2 on Data structures
Chapter 2 (16M) Sorting and Searching
Data Structures Data Structure is a way of collecting and organising data in such a way that we can perform operations on these data in an effective.
Arrays.
DATA STRUCTURES Introduction: Basic Concepts and Notations
Algorithms & Arrays.
Introduction to Data Structures
Review of Arrays and Pointers
Week # 1: Overview & Review
ARRAYS, RECORDS AND POINTER
24 Searching and Sorting.
Data Structures (CS212D) Week # 2: Arrays.
Linked List and Selection Sort
Introduction to Data Structures
A G L O R H I M S T A Merging Merge.
Ch. 2: Getting Started.
The Generic List<> Collection class
A G L O R H I M S T A Merging Merge.
A G L O R H I M S T A Merging Merge.
Principles of Computing – UFCFA3-30-1
Applications of Arrays
Presentation transcript:

Operation performed by Linear Structure Traversal: Processing each element in the list Search : Find the location of the element with a given value or the record with a given key Insertion : Adding new element to the list Deletion : Removing an element from the list Sorting : Arranging the elements in some type of order Merging :Combining two list into single list

Linear Array List of finite number N of homogenous data elements (i.e. data elements of same type) such that The elements of the array are referenced respectively by an index set consisting of N consecutive number The elements of the array are stored respectively in successive memory location

Length of Array N = length of array Length = UB – LB + 1 UB = Upper Bound or Largest Index LB= Lower Bound or smallest Index

Representation in Memory Address of any element in Array = LOC(LA[k])=Base (LA) + w (k - LB) LOC(LA[k]) =Address of element LA[k] of the Array LA Base (LA) = Base Address of LA w = No. of words per memory cell for the Array LA k = Any element of Array

Operations on Array Traversing a Linear Array Traverse Array (LA, LB, UB) Function: This algorithm traverse LA applying an operation PROCESS to each element of LA Input: LA is a Linear Array with Lower Bound LB and Upper bound UB

Algorithm: [Initialize Counter] Set K:=LB Repeat Steps 3 and 4 while K≤UB [Visit element] Apply PROCESS to LA[K] [Increase counter] Set K:=K+1 [End of Step 2 loop] 5. Exit

Alternative Algorithm: Repeat for K:=LB to UB Apply PROCESS to LA[K] [End of loop] 2. Exit

Example: Home Work Consider the array AUTO which records the number of automobile sold each ear from 1932 through 1984. Find the NUM of years during which more than 300 automobiles were sold Print each year and the number of automobile sold in that year (This is a book example # 4.4)

Operations Cont Insert an element in Linear Array NOTE : This Algorithm consist of minimal steps. For more detail add appropriate steps as discussed in class

Operations Cont Insert Element (LA, ITEM, N, K) Function: This algorithm insert an element in a Linear Array at required position Input: LA is a Linear Array having N elements ITEM is the element to be inserted at given position K Precondition: K≤N where K is a +ve integer

Insertion Algorithm Algorithm: [Initialize Counter] Set J:=N Repeat Steps 3 and 4 while J≥K [Move Jth element downward] Set LA[J+1] := LA[J] [Decrease counter] Set J:=J-1 [End of Step 2 loop] 5. [Insert element] Set LA[K]:=ITEM 6. [Reset N] N:= N+1 7. Exit

Operation Cont Delete an element from a Linear Array NOTE : This Algorithm consist of minimal steps. For more detail add appropriate steps as discussed in class

Deletion algorithm Delete Element (LA, ITEM, N, K) Function: This algorithm delete an element from a given position in Linear Array Input: LA is a Linear Array having N elements K is the position given from which ITEM needs to be deleted Output: ITEM is the element deleted from the given position K Precondition: K≤N where K is a +ve integer

Deletion algorithm Algorithm: Set ITEM:=LA[K] Repeat for J:=K to N-1 [Move Jth element upward] Set LA[J] := LA[J+1] [End of Step 2 loop] 4. [Reset N] N:= N-1 5. Exit