Course Teacher: Moona Kanwal

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
Foundation of Computing Systems Lecture 2 Linked Lists.
Data Structures: A Pseudocode Approach with C
HST 952 Computing for Biomedical Scientists Lecture 9.
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.
Main Index Contents 11 Main Index Contents Container Types Container Types Sequence Containers Sequence Containers Associative Containers Associative Containers.
Objectives Learn how to implement the sequential search algorithm Explore how to sort an array using the selection sort algorithm Learn how to implement.
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.
Data Structures Introduction Phil Tayco Slide version 1.0 Jan 26, 2015.
Week 11 Sorting Algorithms. Sorting Sorting Algorithms A sorting algorithm is an algorithm that puts elements of a list in a certain order. We need sorting.
ARRAYS, RECORDS AND POINTER
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.
Computers Data Representation Chapter 3, SA. Data Representation and Processing Data and information processors must be able to: Recognize external data.
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 10 Applications of Arrays and Strings. Chapter Objectives Learn how to implement the sequential search algorithm Explore how to sort an array.
Chapter 19: Searching and Sorting Algorithms
DATA STRUCTURES (CS212D) Week # 1: Overview & Review.
Standard Algorithms –search for an item in an array –count items in an array –find the largest (or smallest) item in an array.
Chapter 2 ARRAYS.
Arrays.
DATA STRUCTURE & ALGORITHMS (BCS 1223) CHAPTER 8 : SEARCHING.
Data Strcutures.
1 Introduction to Data Structures. 2 Course Name : Data Structure (CSI 221) Course Teacher : Md. Zakir Hossain Lecturer, Dept. of Computer Science Stamford.
 DATA STRUCTURE DATA STRUCTURE  DATA STRUCTURE OPERATIONS DATA STRUCTURE OPERATIONS  BIG-O NOTATION BIG-O NOTATION  TYPES OF DATA STRUCTURE TYPES.
Data Structures and Algorithms Lecture 1 Instructor: Quratulain Date: 1 st Sep, 2009.
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.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 10: Applications of Arrays (Searching and Sorting) and the vector Type.
Chapter 18: Searching and Sorting Algorithms. Objectives In this chapter, you will: Learn the various search algorithms Implement sequential and binary.
3 Data. Software And Data Data Data element – a single, meaningful unit of data. Name Social Security Number Data structure – a set of related data elements.
Review 1 Selection Sort Selection Sort Algorithm Time Complexity Best case Average case Worst case Examples.
Elementary Data Organization. Outline  Data, Entity and Information  Primitive data types  Non primitive data Types  Data structure  Definition 
Chapter 15 A External Methods. © 2004 Pearson Addison-Wesley. All rights reserved 15 A-2 A Look At External Storage External storage –Exists beyond the.
Introduction to Algorithms Sorting and Order Statistics– Part II Lecture 5 CIS 670.
Review Sorting algorithms Selection Sort Insertion Sort Bubble Sort Merge Sort Quick Sort.
Data Structures & Algorithms CHAPTER 1 Introduction Ms. Manal Al-Asmari.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Elementary Data Structures Array Lists Array Lists Dale.
Lecture 9COMPSCI.220.FS.T Lower Bound for Sorting Complexity Each algorithm that sorts by comparing only pairs of elements must use at least 
Course Code #IDCGRF001-A 5.1: Searching and sorting concepts Programming Techniques.
1 Ch. 2: Getting Started. 2 About this lecture Study a few simple algorithms for sorting – Insertion Sort – Selection Sort (Exercise) – Merge Sort Show.
 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.
© 2006 Pearson Addison-Wesley. All rights reserved15 A-1 Chapter 15 External Methods.
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.
Introduction toData structures and Algorithms
Introduction to Data Structures
Understanding Algorithms and Data Structures
Course Developer/Writer: A. J. Ikuomola
Operation performed by Linear Structure
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.
Algorithms & Arrays.
Introduction to Data Structures
ARRAYS, RECORDS AND POINTER
Linked List and Selection Sort
Applications of Arrays
Presentation transcript:

Course Teacher: Moona Kanwal Lecture#2: Arrays Course Teacher: Moona Kanwal

Linear Data structures Linear form a sequence Linear relationship b/w the elements represented by means of sequential memory location Link list and arrays are linear relationship

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 TraverseArray (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 InsertElement (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 he element to be inserted at given position K Precondition: K≤N where K is a +ve integer

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

DeleteElement (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

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