Review Sorting algorithms Selection Sort Insertion Sort Bubble Sort Merge Sort Quick Sort.

Slides:



Advertisements
Similar presentations
Data Structures Through C
Advertisements

Linked Lists Linked Lists Representation Traversing a Linked List
CHP-5 LinkedList.
EC-211 DATA STRUCTURES LECTURE 2. EXISTING DATA STRUCTURES IN C/C++ ARRAYS – A 1-D array is a finite, ordered set of homogeneous elements – E.g. int a[100]
One Dimensional Arrays
Programming and Data Structure
Review Learn about linked lists
Dr. Yang, QingXiong (with slides borrowed from Dr. Yuen, Joe) LT5: Array (1D and 2D) CS2311 Computer Programming.
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.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 17: Linked Lists.
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
Arrays Data Structures - structured data are data organized to show the relationship among the individual elements. It usually requires a collecting mechanism.
C++ for Engineers and Scientists Third Edition
C++ Programming: Program Design Including Data Structures, Fifth Edition Chapter 17: Linked Lists.
Programming Logic and Design Fourth Edition, Comprehensive
Introducing Hashing Chapter 21 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
INTRODUCTION TO DATA STRUCTURE. Topics To Be Discussed………………………. Meaning of Data Structure Classification of Data Structure Data Structure Operations.
 2007 Pearson Education, Inc. All rights reserved C Arrays.
CHP - 9 File Structures. INTRODUCTION In some of the previous chapters, we have discussed representations of and operations on data structures. These.
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
Chapter 7: Arrays. In this chapter, you will learn about: One-dimensional arrays Array initialization Declaring and processing two-dimensional arrays.
Design and Analysis of Algorithms CSC201 Shahid Hussain 1.
Array Processing Simple Program Design Third Edition A Step-by-Step Approach 7.
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.
The basics of the array data structure. Storing information Computer programs (and humans) cannot operate without information. Example: The array data.
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
 DATA STRUCTURE DATA STRUCTURE  DATA STRUCTURE OPERATIONS DATA STRUCTURE OPERATIONS  BIG-O NOTATION BIG-O NOTATION  TYPES OF DATA STRUCTURE TYPES.
Lists II. List ADT When using an array-based implementation of the List ADT we encounter two problems; 1. Overflow 2. Wasted Space These limitations are.
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.
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, Second Edition Chapter 17: Linked Lists.
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.
Elementary Data Organization. Outline  Data, Entity and Information  Primitive data types  Non primitive data Types  Data structure  Definition 
 2007 Pearson Education, Inc. All rights reserved C Arrays.
CPSC 252 Hashing Page 1 Hashing We have already seen that we can search for a key item in an array using either linear or binary search. It would be better.
1 Algorithms Queues, Stacks and Records stored in Linked Lists or Arrays.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Chapter Lists Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2010.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Elementary Data Structures Array Lists Array Lists Dale.
 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.
Chapter 17: Linked Lists. Objectives In this chapter, you will: – Learn about linked lists – Learn the basic properties of linked lists – Explore insertion.
Data Structure and Algorithms
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
1 Linked List. 2 List A list refers to a sequence of data items  Example: An array The array index is used for accessing and manipulation of array elements.
1 CSC103: Introduction to Computer and Programming Lecture No 17.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 17: Linked Lists.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 18: Linked Lists.
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.
Consultation Hours. Mubashir: – Tuesday from 12:30 to 1:30 with ease of Students. Zohaib – Wedneday b/w 9:30 -10:30 Location: TA Room (next to HOD Office)
Data Structures and Algorithm Analysis Dr. Ken Cosh Linked Lists.
Data Structure and Algorithm: CIT231 Lecture 6: Linked Lists DeSiaMorewww.desiamore.com/ifm1.
LINKED LISTS.
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
Consultation Hours. Mubashir: – Tuesday from 12:30 to 1:30 with ease of Students. Zohaib – Wednesday b/w 9:30 -10:30 Location: TA Room (next to HOD Office)
Lecture 2. Algorithms and Algorithm Convention 1.
Chapter 16: Linked Lists.
C++ Programming:. Program Design Including
CHP - 9 File Structures.
Arrays in C The c language provides a capability that enables the user to design a set of similar data types called array. Pointers and arrays are.
Operation performed by Linear Structure
Linked lists.
© A+ Computer Science - Arrays and Lists © A+ Computer Science -
Data Structures & Algorithms
Linked lists.
Presentation transcript:

Review Sorting algorithms Selection Sort Insertion Sort Bubble Sort Merge Sort Quick Sort

List Using Array 2 Introduction Representation of Linear Array In Memory Operations on linear Arrays Traverse Insert Delete Example

Introduction 3 Suppose we wish to arrange the percentage marks obtained by 100 students in ascending order In such a case we have two options to store these marks in memory: (a) Construct 100 variables to store percentage marks obtained by 100 different students, i.e. each variable containing one student’s marks (b) Construct one variable (called array or subscripted variable) capable of storing or holding all the hundred values

4 Obviously, the second alternative is better. A simple reason for this is, it would be much easier to handle one variable than handling 100 different variables Moreover, there are certain logics that cannot be dealt with, without the use of an array Based on the above facts, we can define array as: “A collective name given to a group of ‘similar quantities’”

5 These similar quantities could be percentage marks of 100 students, or salaries of 300 employees, or ages of 50 employees What is important is that the quantities must be ‘similar’ These similar elements could be all int, or all float, or all char Each member in the group is referred to by its position in the group

For Example 6 Assume the following group of numbers, which represent percentage marks obtained by five students per = { 48, 88, 34, 23, 96 } In C, the fourth number is referred as per[3] Because in C the counting of elements begins with 0 and not with 1 Thus, in this example per[3] refers to 23 and per[4] refers to 96 In general, the notation would be per[i], where, i can take a value 0, 1, 2, 3, or 4, depending on the position of the element being referred

Representation of Linear Array In Memory An array occupies a continuous block of memory Each element of the array also has unique memory address Starting address of the array called base address If base address of the array is known, the address of any element of the array can be found L(X[K])= L 0 + C * (K-1) 7

Array X has 5 elements Each of 2 bytes length To find out the address of third element of X when the base address of the array is L 0 =200 L(X[3]) = * (3-1) = = 204 8

Operations on linear Arrays A linear array is a list of a finite number n of homogenous data elements (data elements of the same type) Traversal: Processing each element in the list Search: Finding the location of the element with a given value or the record with a given key Insertion: Adding a new element from the list Sorting: Arranging the elements in some type of order Merging: Combining two lists into a single list 9

Traversing Operation Each element of an array is accessed exactly once for processing. Also called visiting of the array Example Sum of values of each element of an array Print value of each element of array 10

Algorithm to compute the sum of values of a linear array having ten elements Input values in array ABC SUM = 0 [Compute sum of array ABC] REPEAT FOR C = 0 to 9 SUM = SUM + ABC[C] [End of the loop] [Print the calculated sum] PRINT SUM EXIT 11

Inserting Operation In inserting operation, new items are added into an array At the end of an array without disturbing other elements of the array if there is an empty element. At some specified location within the array 12

Write an algorithm to add 6 values into elements at the end of the array ‘temp’ that has only four items stored in its first four elements 1- REPEAT Step-2 TO 3 FOR I = 4 to 9 2-INPUT value in N 3-Temp [I] = N [End of Step-2 Loop] 4-EXIST 13

Inserting value at specified location To insert new value, the value of all the existing elements are moved one step forward or backward to make space for the new value Write an algorithm to insert a value M at location pos in array ABC having N element. 14

1- Input value in M 2- Input position in POS [Move elements one step forward] 3- REPEAT step – 4 TO 5 WHILE N>=POS 4- ABC[N+1]=ABC[N] // from where you need to insert value 5- N=N-1 [End of step-3 Loop] [Insert value M at Position POS] 6- ABC[POS]=M 7- Exit 15

Deleting operations One Like insertion, deletion can be performed at the end or at any position in the array. To remove the last element from the array, the last element is accessed and deleted by placing null value or by decreasing the size of array by one element if it is the last element of the array. 16

Write an algorithm to delete the value at location K of an array ‘country’ having N elements 1- Input location K 2- IF K > N then PRINT “Invalid location” return END IF [Move each element from the specified location one step towards the beginning. The item at the specified location is automatically deleted] 3- REPEAT FOR C = K TO N-1 Country[C]= Country[C+1] [End of the loop] 4- EXIT 17

Summary 18 Introduction Representation of Linear Array In Memory Operations on linear Arrays Traverse Insert Delete Example