Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic concepts and uses of arrays ❏ To be able to define C.

Slides:



Advertisements
Similar presentations
Introduction to Arrays Chapter What is an array? An array is an ordered collection that stores many elements of the same type within one variable.
Advertisements

Chapter 3 Brute Force Brute force is a straightforward approach to solving a problem, usually directly based on the problem’s statement and definitions.
One Dimensional Arrays
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
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.
Topics discussed in this section:
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 9A Sorting (Concepts)
Chapter 9: Searching, Sorting, and Algorithm Analysis
Visual C++ Programming: Concepts and Projects
Chapter 6: Arrays Java Software Solutions for AP* Computer Science
Computer Science: A Structured Programming Approach Using C1 8-4 Array Applications In this section we study two array applications: frequency arrays with.
CS102 A Wide Array of Possibilities CS 102 Java’s Central Casting.
Chapter 11 Sorting and Searching. Topics Searching –Linear –Binary Sorting –Selection Sort –Bubble Sort.
An Introduction to Programming with C++ Fifth Edition
Searches & Sorts V Deena Engel’s class Adapted from W. Savitch’s text An Introduction to Computers & Programming.
Arrays Data Structures - structured data are data organized to show the relationship among the individual elements. It usually requires a collecting mechanism.
Introduction to Programming with C++ Fourth Edition
C++ for Engineers and Scientists Third Edition
CS 106 Introduction to Computer Science I 10 / 16 / 2006 Instructor: Michael Eckmann.
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 l Array Basics l Arrays in Classes and Methods l Programming with Arrays.
Chapter 7: Arrays. In this chapter, you will learn about: One-dimensional arrays Array initialization Declaring and processing two-dimensional arrays.
Scott Marino MSMIS Kean University MSAS5104 Programming with Data Structures and Algorithms Week 10 Scott Marino.
Chapter 16: Searching, Sorting, and the vector Type.
Array Processing Simple Program Design Third Edition A Step-by-Step Approach 7.
Computer Science: A Structured Programming Approach Using C1 8-5 Sorting One of the most common applications in computer science is sorting—the process.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand design concepts for fixed-length and variable- length strings ❏
CHAPTER 09 Compiled by: Dr. Mohammad Omar Alhawarat Sorting & Searching.
Chapter 11 Arrays Continued
Searching and Sorting Chapter Sorting Arrays.
Arrays.
Array Processing.
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
Arrays The concept of arrays Using arrays Arrays as arguments Processing an arrays data Multidimensional arrays Sorting data in an array Searching with.
Chapter 6: Arrays: Lists and Tables
Computer Science: A Structured Programming Approach Using C1 8-7 Two-Dimensional Arrays The arrays we have discussed so far are known as one- dimensional.
Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Modified for use by MSU Dept. of Computer Science.
Introduction to C++ Programming Language Assistant Professor Jeon, Seokhee Assistant Professor Department of Computer Engineering, Kyung Hee University,
1 Section 2.1 Algorithms. 2 Algorithm A finite set of precise instructions for performing a computation or for solving a problem.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To introduce the structure, union, and enumerated types ❏ To use the type definition.
An Introduction to Programming with C++ Fifth Edition Chapter 11 Arrays.
Computer Programming TCP1224 Chapter 11 Arrays. Objectives Using Arrays Declare and initialize a one-dimensional array Manipulate a one-dimensional array.
1 Objectives ❏ To understand the basic concepts and uses of arrays ❏ To be able to define C arrays ❏ To be able to pass arrays and array elements to functions.
Searching Chapter 13 Objectives Upon completion you will be able to:
Chapter 8 Sorting and Searching Goals: 1.Java implementation of sorting algorithms 2.Selection and Insertion Sorts 3.Recursive Sorts: Mergesort and Quicksort.
CS 106 Introduction to Computer Science I 03 / 02 / 2007 Instructor: Michael Eckmann.
Course Code #IDCGRF001-A 5.1: Searching and sorting concepts Programming Techniques.
Computer Science: A Structured Programming Approach Using C1 8-7 Two-Dimensional Arrays The arrays we have discussed so far are known as one- dimensional.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the relationship between arrays and pointers ❏ To understand the.
Chapter 3: Sorting and Searching Algorithms 3.1 Searching Algorithms.
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.
Arrays Department of Computer Science. C provides a derived data type known as ARRAYS that is used when large amounts of data has to be processed. “ an.
Chapter 16: Searching, Sorting, and the vector Type.
Chapter 16: Searching, Sorting, and the vector Type
Chapter 12 Enumerated, Structure, and Union Types Objectives
Introduction to Search Algorithms
Chapter 7 Part 1 Edited by JJ Shepherd
Chapter 8 Arrays Objectives
Chapter 9 Pointers Objectives
Topics discussed in this section:
Sorting Data are arranged according to their values.
Topics discussed in this section:
Using Arrays in C Only fixed-length arrays can be initialized when they are defined. Variable length arrays must be initialized by inputting or assigning.
Chapter 8 Arrays Objectives
Sorting Data are arranged according to their values.
Topics discussed in this section:
Chapter 8 Arrays Objectives
Presentation transcript:

Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic concepts and uses of arrays ❏ To be able to define C arrays ❏ To be able to pass arrays and array elements to functions ❏ To understand the classical approaches to sorting arrays: selection, bubble, and insertion sorting ❏ To write programs that sort data using the three classical algorithms ❏ To be able to analyze the efficiency of a sort algorithm ❏ To understand the two classical search algorithms: sequential and binary ❏ To write programs that search arrays ❏ To be able to design test cases for sorting and searching algorithms ❏ To be able to analyze the efficiency of searching algorithms Chapter 8 Chapter 8 Arrays Arrays

Computer Science: A Structured Programming Approach Using C2 FIGURE 8-1 Derived Types

Computer Science: A Structured Programming Approach Using C3 8-1 Concepts Imagine we have a problem that requires us to read, process, and print a large number of integers. We must also keep the integers in memory for the duration of the program. To process large amounts of data we need a powerful data structure, the array. An array is a collection of elements of the same data type. To process large amounts of data we need a powerful data structure, the array. An array is a collection of elements of the same data type. Since an array is a sequenced collection, we can refer to the elements in the array as the first element, the second element, and so forth until we get to the last element. Since an array is a sequenced collection, we can refer to the elements in the array as the first element, the second element, and so forth until we get to the last element.

Computer Science: A Structured Programming Approach Using C4 FIGURE 8-2 Ten Variables

Computer Science: A Structured Programming Approach Using C5 FIGURE 8-3 Process 10 variables

Computer Science: A Structured Programming Approach Using C6 FIGURE 8-4 An Array of Scores

Computer Science: A Structured Programming Approach Using C7 FIGURE 8-5 Loop for 10 Scores

Computer Science: A Structured Programming Approach Using C8 8-2 Using Arrays in C In this section, we first show how to declare and define arrays. Then we present several typical applications using arrays including reading values into arrays, accessing and exchanging elements in arrays, and printing arrays. Declaration and Definition Accessing Elements in Arrays Storing Values in Arrays Index Range Checking Topics discussed in this section:

Computer Science: A Structured Programming Approach Using C9 FIGURE 8-6 The Scores Array

Computer Science: A Structured Programming Approach Using C10 FIGURE 8-7 Declaring and Defining Arrays

Computer Science: A Structured Programming Approach Using C11 Only fixed-length arrays can be initialized when they are defined. Variable length arrays must be initialized by inputting or assigning the values. Note

Computer Science: A Structured Programming Approach Using C12 FIGURE 8-8 Initializing Arrays

Computer Science: A Structured Programming Approach Using C13 One array cannot be copied to another using assignment. Note

Computer Science: A Structured Programming Approach Using C14 FIGURE 8-9 Exchanging Scores—the Wrong Way

Computer Science: A Structured Programming Approach Using C15 FIGURE 8-10 Exchanging Scores with Temporary Variable

Computer Science: A Structured Programming Approach Using C16 PROGRAM 8-1Print Ten Numbers per Line

Computer Science: A Structured Programming Approach Using C17 PROGRAM 8-2Squares Array

Computer Science: A Structured Programming Approach Using C18 PROGRAM 8-2Squares Array

Computer Science: A Structured Programming Approach Using C19 PROGRAM 8-3Print Input Reversed

Computer Science: A Structured Programming Approach Using C20 PROGRAM 8-2 Print Input Reversed

Computer Science: A Structured Programming Approach Using C21 PROGRAM 8-2 Print Input Reversed

Computer Science: A Structured Programming Approach Using C Inter-function Communication To process arrays in a large program, we have to be able to pass them to functions. We can pass arrays in two ways: pass individual elements or pass the whole array. In this section we discuss first how to pass individual elements and then how to pass the whole array. Passing Individual Elements Passing the Whole Array Topics discussed in this section:

Computer Science: A Structured Programming Approach Using C23 FIGURE 8-11 Passing Array Elements

Computer Science: A Structured Programming Approach Using C24 FIGURE 8-12 Passing the Address of an Array Element

Computer Science: A Structured Programming Approach Using C25 FIGURE 8-13 Passing the Whole Array

Computer Science: A Structured Programming Approach Using C26 PROGRAM 8-4Calculate Array Average

Computer Science: A Structured Programming Approach Using C27 PROGRAM 8-4Calculate Array Average

Computer Science: A Structured Programming Approach Using C28 PROGRAM 8-5Average Elements in Variable-length Array

Computer Science: A Structured Programming Approach Using C29 PROGRAM 8-5Average Elements in Variable-length Array

Computer Science: A Structured Programming Approach Using C30 PROGRAM 8-5Average Elements in Variable-length Array

Computer Science: A Structured Programming Approach Using C31 PROGRAM 8-5Average Elements in Variable-length Array

Computer Science: A Structured Programming Approach Using C32 PROGRAM 8-6Change Values in an Array

Computer Science: A Structured Programming Approach Using C33 PROGRAM 8-6Change Values in an Array