Chapter 3 Data Structures and Abstract Data Type Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.

Slides:



Advertisements
Similar presentations
Copyright © 2002 Pearson Education, Inc. Slide 1.
Advertisements

CS 141 Computer Programming 1 1 Arrays. Outline  Introduction  Arrays  Declaring Arrays  Examples Using Arrays  Sorting Arrays  Multiple-Subscripted.
EC-111 Algorithms & Computing Lecture #7 Instructor: Jahan Zeb Department of Computer Engineering (DCE) College of E&ME NUST.
1 Chapter 11 Introducing the Class Pages ( )
Structure.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 7- 1 Overview 7.1 Introduction to Arrays 7.2 Arrays in Functions 7.3.
Linked Lists Compiled by Dr. Mohammad Alhawarat CHAPTER 04.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Introduction.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 8 Multidimensional.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Introduction.
Chapter 8. 2 Objectives You should be able to describe: One-Dimensional Arrays Array Initialization Arrays as Arguments Two-Dimensional Arrays Common.
Main Index Contents 11 Main Index Contents Pointer Illustration Pointer Illustration Vertical / Horizontal View. Vertical / Horizontal View. Data Addresses.
Basic Definitions Data Structures: Data Structures: A data structure is a systematic way of organizing and accessing data. Or, It’s the logical relationship.
Chapter 8 Arrays and Strings
1 CSCE 1030 Computer Science 1 Arrays Chapter 7 in Small Java.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Data Structures.
 Pearson Education, Inc. All rights reserved Arrays.
EE Data Structures and Algorithms N Radhakrishnan Assistant Professor Anna University, Chennai.
CPS120: Introduction to Computer Science Arrays. Arrays: A Definition A list of variables accessed using a single identifier May be of any data type Can.
Arrays in C++ Numeric Character. Structured Data Type A structured data type is a type that stores a collection of individual components with one variable.
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.
C Programming n General Information on C n Data Types n Arithmetic Operators n Relational Operators n if, if-else, for, while by Kulapan Waranyuwat.
1 DATA STRUCTURES: LISTS. 2 LISTS ARE USED TO WORK WITH A GROUP OF VALUES IN AN ORGANIZED MANNER. A SERIES OF MEMORY LOCATIONS CAN BE DIRECTLY REFERENCED.
Chapter 7 One-Dimensional Arrays 7.1 Arrays in C One of the more useful features of C is the ability to create arrays for storing a collection of related.
Introduction to Arrays in Java Corresponds with Chapter 6 of textbook.
The basics of the array data structure. Storing information Computer programs (and humans) cannot operate without information. Example: The array data.
 Pearson Education, Inc. All rights reserved Arrays.
 Pearson Education, Inc. All rights reserved Arrays.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 8 Multidimensional Arrays.
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
Course Title Object Oriented Programming with C++ Course instructor ADEEL ANJUM Chapter No: 05 ARRAY 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER) 1.
CPSC 252 Concrete Data Types Page 1 Overview of Concrete Data Types There are two kinds of data types: Simple (or atomic) – represents a single data item.
Computer Programming 12 Mr. Jean April 24, The plan: Video clip of the day Upcoming Quiz Sample arrays Using arrays More about arrays.
© Copyright 2013 by Pearson Education, Inc. All Rights Reserved. 1 Chapter 8 Multidimensional Arrays.
Data Structures and Algorithms Lecture 3 Instructor: Quratulain Date: 8 th September, 2009.
Arrays  Array is a collection of same type elements under the same variable identifier referenced by index number.  Arrays are widely used within programming.
CHAPTER 7 arrays I NTRODUCTION T O C OMPUTER P ROGRAMMING (CSC425)
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.
Chapter 7 Selection Dept of Computer Engineering Khon Kaen University.
Section 5 - Arrays. Problem solving often requires information be viewed as a “list” List may be one-dimensional or multidimensional List is implemented.
Lecture 3 Abstract Data Type Sandy Ardianto & Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
CS 139-Programming Fundamentals Lecture 11B - Arrays Adapted from a presentation by Dr. Rahman Fall 2014.
1 One Dimensional Arrays Chapter 11 2 "All students to receive arrays!" reports Dr. Austin. Declaring arrays scores :
Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010.
1 Chapter 12 Arrays. 2 C++ Data Types structured array struct union class address pointer reference simple integral enum char short int long bool floating.
Chapter 8 Arrays. A First Book of ANSI C, Fourth Edition2 Introduction Atomic variable: variable whose value cannot be further subdivided into a built-in.
Chapter Lists Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2010.
Data Structure and Algorithm: CIT231 Lecture 3: Arrays and ADT DeSiaMore DeSiaMorewww.desiamore.com/ifm1.
C++ Array 1. C++ provides a data structure, the array, which stores a fixed-size sequential collection of elements of the same type. An array is used.
A FIRST BOOK OF C++ CHAPTER 8 ARRAYS AND POINTERS.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Arrays Outline 6.1Introduction 6.2Arrays 6.3Declaring.
Arrays. C++ Style Data Structures: Arrays(1) An ordered set (sequence) with a fixed number of elements, all of the same type, where the basic operation.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Lecture.
 2005 Pearson Education, Inc. All rights reserved Arrays.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
Chapter 9 Introduction to Arrays Fundamentals of Java.
Computer Skills2 / Scientific Colleges 1 Arrays Topics to cover: Arrays Data Types One-dimensional Arrays Two-dimensional Arrays.
LESSON 8: INTRODUCTION TO ARRAYS. Lesson 8: Introduction To Arrays Objectives: Write programs that handle collections of similar items. Declare array.
Data Structures and Abstract Data Types
Array Data Structure Chapter 6
Introduction to Abstract Data Types
Array Data Structure B.Ramamurthy 11/21/2018 B.Ramamurthy.
Introduction To Programming Information Technology , 1’st Semester
MSIS 655 Advanced Business Applications Programming
Abstract Data Types, Elementary Data Structures and Arrays
Array Data Structure Chapter 6
CS149D Elements of Computer Science
Presentation transcript:

Chapter 3 Data Structures and Abstract Data Type Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008

Outline Introduction to Abstract Data Types (ADTs) Arrays

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 to do that, we need to identify: 1. The collection of data items 2. Basic operation that must be performed on them Abstract Data Type (ADT): a collection of data items together with the operations on the data

Abstract Data Type (ADT) The word “abstract” refers to the fact that the data and the basic operations defined on it are being studied independently of how they are implemented We think about what can be done with the data, not how it is done

ADT example

Implementation of ADT An implementation of ADT consists of storage structures to store the data items and algorithms for basic operation

Data Structures, Abstract Data Types, and Implementations Consider example of an airplane flight with 10 seats to be assigned Tasks List available seats Reserve a seat How to store, access data?

Data Structures, Abstract Data Types, and Implementations Consider example of an airplane flight with 10 seats to be assigned Tasks List available seats Reserve a seat How to store, access data? 10 individual variables

Use 10 individual variables Algorithm to List available seats 1. If seat1 == ‘ ’: display 1 2. If seat2 == ‘ ’: display If seat10 == ‘ ’: display 10 Algorithm to Reserve a seat 1. Set DONE to false 2. If seat1 ==‘ ’: print “do you want seat #1??” Get answer if answer==‘Y’: set seat1 to ‘X’ set Done to True 3. If seat2 ==‘ ’: print “do you want seat #2??” Get answer if answer==‘Y’: set seat2 to ‘X’ set Done to True.

Data Structures, Abstract Data Types, and Implementations Consider example of an airplane flight with 10 seats to be assigned Tasks List available seats Reserve a seat How to store, access data? 10 individual variables An array of variables

Use Array Algorithm to List available seats For number ranging from 0 to max_seats-1, do: If seat[number] == ‘ ’: Display number Algorithm to Reserve a seat Readin number of seat to be reserved If seat[number] is equal to ‘ ’: set seat[number] to ‘X’ Else Display a message that the seat having this number is occupied

ADTs In this simple example, it does illustrate the concept of an Abstract Data Type ADT consists of 1. The collection of data items 2. Basic operation that must be performed on them In the example, a collection of data is a list of seats The basic operations are (1) Scan the list to determine which seats are occupied (2) change seat’s status

Data Structure and Abstract Data Type The term of Data Structure and Abstract Data Type are often used interchangeably However, we use ADT when data is studied at a logical level The term data structure refers to a construct in programming language that can be used to store data

Outline Introduction to Abstract Data Types (ADTs) Arrays

Array ADT Collection of data elements A fixed-size sequence of elements, all of the same type Basic Operations Direct access to each element in the array by specifying its position so that values can be retrieved from or stored in that position

Different types of Array One-dimensional array: only one index is used Multi-dimensional array: array involving more than one index Static array: the compiler determines how memory will be allocated for the array Dynamic array: memory allocation takes place during execution

One-Dimensional Static Array Syntax: ElementType arrayName [CAPACITY]; ElementType arrayName [CAPACITY] = { initializer_list }; Example: int b [10]; int b [10]={1,2,3,4,5,6,7,8,9,10};

Array and ADT Collection of data elements A fixed-size sequence of elements, all of the same type Basic Operations Direct access to each element in the array by specifying its position so that values can be retrieved from or stored in that position An Array as an ADT C++ Array Fixed size specify the capacity of the array Ordered indices are numbered 0,1,2,…,capacity-1 Same type of elements specify the element type Direct access subscript operator[]

Example of array Consider array a,b,c,d to store collection of 10 integers declared by: int capacity=10 int a[capacity], b[capacity]={1,2,3,4,5,6,7,8,9,10}, c[capacity]={1,2,3}, d[capacity]={0}; char name[capacity]=“John Doe”;

Array Output Function Void display(int array[], int num_values) { for (int I = 0; i<num_values; i++) cout<< array[i] << “ ”; }

Multidimensional Arrays Consider a table of test scores for several different students

Array of Array Declarations An array of arrays An array whose elements are other arrays

Array of Array Declarations Each of the rows is itself a one dimensional array of values scoresTable[2] is the whole row numbered 2 scoresTable[2] is the whole row numbered 2 scoresTable [1][3]

Multidimensional Arrays Syntax: ElementType arrayName [num_rows][num_columns]; int scoretable [num_students][num_tests]; int scoretable[2][5]={{80,80,80,80,80},{60,60,60,60,60}}; If you want to change the score of first student’s 3 rd test score to 100, you just need to do: Scoretable[0][2]=100

Multidimensional Arrays Consider multiple pages of the student grade book typedef double ThreeDimArray[NUM_ROWS][NUM_COLS][NUM_RANKS];...