Arrays.

Slides:



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

© 2004 Goodrich, Tamassia Hash Tables1  
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.
Search and Recursion CS221 – 2/23/09. List Search Algorithms Linear Search: Simple search through unsorted data. Time complexity = O(n) Binary Search:
Hash Tables1 Part E Hash Tables  
Objectives Learn how to implement the sequential search algorithm Explore how to sort an array using the selection sort algorithm Learn how to implement.
CHAPTER 11 Searching. 2 Introduction Searching is the process of finding a target element among a group of items (the search pool), or determining that.
 2007 Pearson Education, Inc. All rights reserved C Arrays.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic concepts and uses of arrays ❏ To be able to define C.
Data Structures Introduction Phil Tayco Slide version 1.0 Jan 26, 2015.
February 17, 2015Applied Discrete Mathematics Week 3: Algorithms 1 Double Summations Table 2 in 4 th Edition: Section th Edition: Section th.
C o n f i d e n t i a l Developed By Nitendra HOME NEXT Subject Name: Data Structure Using C Unit Title: Searching Methods.
CHAPTER 71 TREE. Binary Tree A binary tree T is a finite set of one or more nodes such that: (a) T is empty or (b) There is a specially designated node.
ARRAYS, RECORDS AND POINTER
Chapter 16: Searching, Sorting, and the vector Type.
Array.
CSC 211 Data Structures Lecture 7
CHAPTER 09 Compiled by: Dr. Mohammad Omar Alhawarat Sorting & Searching.
Chapter 10 Applications of Arrays and Strings. Chapter Objectives Learn how to implement the sequential search algorithm Explore how to sort an array.
1 Searching. 2 Searching Searching refers to the operation of finding an item from a list of items based on some key value. Two Searching Methods (1)
Chapter 2 ARRAYS.
Course Teacher: Moona Kanwal
Lecture 4 on Data Structure Array. Prepared by, Jesmin Akhter, Lecturer, IIT, JU Searching : Linear search Searching refers to the operation of finding.
PRESENTATION ON SEARCHING SEARCHING Searching is the method to find element from the list of the elements. If element is found then it.
DATA STRUCTURE & ALGORITHMS (BCS 1223) CHAPTER 8 : SEARCHING.
Data Strcutures.
Advance Data Structure 1 College Of Mathematic & Computer Sciences 1 Computer Sciences Department م. م علي عبد الكريم حبيب.
CS 162 Intro to Programming II Searching 1. Data is stored in various structures – Typically it is organized on the type of data – Optimized for retrieval.
SEARCHING. Vocabulary List A collection of heterogeneous data (values can be different types) Dynamic in size Array A collection of homogenous data (values.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Searching Course Lecture Slides 28 May 2010 “ Some things Man was never.
ARRAYS 1 Week 2. Data Structures  Data structure  A particular way of storing and organising data in a computer so that it can be used efficiently 
CSC 211 Data Structures Lecture 13
A first look an ADTs Solving a problem involves processing data, and an important part of the solution is the careful organization of the data In order.
Lecture -3 on Data structures Array. Prepared by, Jesmin Akhter, Lecturer, IIT, JU Array Data structures are classified as either linear or nonlinear.
Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 2.
HASHING PROJECT 1. SEARCHING DATA STRUCTURES Consider a set of data with N data items stored in some data structure We must be able to insert, delete.
CS201: Data Structures and Discrete Mathematics I Hash Table.
Week # 2: Arrays.  Data structure  A particular way of storing and organising data in a computer so that it can be used efficiently  Types of data.
CHAPTER 8 SEARCHING CSEB324 DATA STRUCTURES & ALGORITHM.
The List ADT A sequence of zero or more elements A 1, A 2, A 3, … A N-1 N: length of the list A 1 : first element A N-1 : last element A i : position i.
Review 1 Arrays & Strings Array Array Elements Accessing array elements Declaring an array Initializing an array Two-dimensional Array Array of Structure.
1 Sorting (Bubble Sort, Insertion Sort, Selection Sort)
 2007 Pearson Education, Inc. All rights reserved C Arrays.
CS 106 Introduction to Computer Science I 03 / 02 / 2007 Instructor: Michael Eckmann.
Review Sorting algorithms Selection Sort Insertion Sort Bubble Sort Merge Sort Quick Sort.
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. Searching The basic characteristics of any searching algorithm is that searching should be efficient, it should have less number of computations involved.
Searching Topics Sequential Search Binary Search.
 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.
Circular linked list A circular linked list is a linear linked list accept that last element points to the first element.
Data Structure and Algorithms
Sorting & Searching Geletaw S (MSC, MCITP). Objectives At the end of this session the students should be able to: – Design and implement the following.
INTRODUCTION OF ARRAY. Topics To Be Discussed………………………. Introduction Types of array One Dimensional Array Internal representation of one-dimensional array.
CHAPTER 51 LINKED LISTS. Introduction link list is a linear array collection of data elements called nodes, where the linear order is given by means of.
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.
Chapter 16: Searching, Sorting, and the vector Type.
Code: BCA302 Data Structures with C Prof. (Dr.) Monalisa Banerjee By.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Arrays + Functions Outline 6.5Passing Arrays to Functions.
Applied Discrete Mathematics Week 2: Functions and Sequences
Operation performed by Linear Structure
Lecture – 2 on Data structures
Arrays.
Chapter 8 Arrays Objectives
ARRAYS, RECORDS AND POINTER
Data Structures: Searching
Chapter 8 Arrays Objectives
Applications of Arrays
Presentation transcript:

Arrays

Linear Arrays A linear array is a list of a finite number n of homogeneous data elements (i.e., data elements of the same type) such that: The elements of the array are referenced respectively by an index set consisting of n consecutive numbers. The elements of the array are stored respectively in successive memory locations. The length or the number of data elements of the array can be obtained from the index set by the following formula: Length = UB - LB + 1

Representation of Linear Arrays in Memory Let LA be a linear array in the memory of the computer. The computer calculates the address of kth Element of the array by the following formula: LOC(LA[K]) = Base(LA) + w(K – LB) Here, W is the number of words per memory cell for the array LA. 1000 1001 1002 . LA[1] LA[2] LA[3] .

Traversing a linear array Algorithm 4.1: Set K := LB Repeat step 3 and 4 while K <= UB Apply PROCESS to LA[K] Set K := K + 1 Exit

Inserting into a linear array Algorithm 4.2: INSERT( LA, N, K, ITEM) Set J := N Repeat Steps 3 and 4 while J >= K Set LA[J+1] := LA[J] Set J := J – 1 Set LA[K] := ITEM Set N := N + 1 Exit

Deleting From a Linear Array Algorithm 4.3: DELETE( LA, N, K, ITEM) Set ITEM := LA[K] Repeat for J := K to N – 1 Set LA[J] := LA[J+1] 3. Set N := N - 1 4. Exit

Searching Searching refers to the operation of finding an item from a list of items based on some key value. Two Searching Methods Linear Search Binary Search

Algorithm: Linear-Search (LA, N, Key) A linear search is a technique for finding a particular value in a unsorted or sorted list. Search each item of list using key value, one at a time, until finding the item from the list. Algorithm: Linear-Search (LA, N, Key) Set k := 1 and Loc := 0 Repeat Steps 3 and 4 while k <= N If Key = LA[k], then Set Loc := k, print: Loc and exit. Set k := k+1 If Loc = 0 then Write: Item is not in List Exit Here L - The list of data items N – Total no. of items in L Key – Item to be searched.

Example of Linear Search List : 10, 6, 222, 44, 55, 77, 24 Key: 55 Steps: 6 222 44 55 77 24 K=1 10 222 44 55 77 24 K=2 10 6 44 55 77 24 K=3 10 6 222 55 77 24 K=4 10 6 222 44 77 24 K=5 So, Item 55 is in position 5. 55 10 6 222 44

Complexity Analysis of Linear Search Worst Case The worst case occurs when Item is the last element in the List or is not in the List. So, C(n) = n = O(n). (2) Average Case The average case occurs when the availability of the Item in the List is equally likely to occur at any position in the List. So, C(n) = = = 0(n)