Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 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 arrays because the data are organized linearly in only one direction. Many applications require that data be stored in more than one dimension. One common example is a table, which is an array that consists of rows and columns. Declaration Passing A Two-Dimensional Array Topics discussed in this section:

2 Computer Science: A Structured Programming Approach Using C2 FIGURE 8-34 Two-dimensional Array

3 Computer Science: A Structured Programming Approach Using C3 FIGURE 8-35 Array Of Arrays

4 Computer Science: A Structured Programming Approach Using C4 PROGRAM 8-15Fill Two-dimensional Array

5 Computer Science: A Structured Programming Approach Using C5 FIGURE 8-36 Memory Layout

6 Computer Science: A Structured Programming Approach Using C6 PROGRAM 8-16Convert Table to One-dimensional Array

7 Computer Science: A Structured Programming Approach Using C7 PROGRAM 8-16Convert Table to One-dimensional Array

8 Computer Science: A Structured Programming Approach Using C8 FIGURE 8-37 Passing a Row

9 Computer Science: A Structured Programming Approach Using C9 FIGURE 8-38 Calculate Average of Integers in Array

10 Computer Science: A Structured Programming Approach Using C10 FIGURE 8-39 Example of Filled Matrix

11 Computer Science: A Structured Programming Approach Using C11 PROGRAM 8-17Fill Matrix

12 Computer Science: A Structured Programming Approach Using C12 PROGRAM 8-17Fill Matrix

13 Computer Science: A Structured Programming Approach Using C13 8-8 Multidimensional Arrays Multidimensional arrays can have three, four, or more dimensions. The first dimension is called a plane, which consists of rows and columns. The C language considers the three-dimensional array to be an array of two-dimensional arrays. Declaring Multidimensional Arrays Topics discussed in this section:

14 Computer Science: A Structured Programming Approach Using C14 FIGURE 8-40 A Three-dimensional Array (3 x 5 x 4)

15 Computer Science: A Structured Programming Approach Using C15 FIGURE 8-41 C View of Three-dimensional Array

16 Computer Science: A Structured Programming Approach Using C16 8-9 Programming Example— Calculate Averages We previously introduced the programming concept known as incremental development. In this chapter we develop an example—calculate average—that contains many of the programming techniques. First Increment: mainYour First C Second Increment: Get Data Third Increment: Calculate Row Averages Fourth Increment: Calculate Column Averages Fifth Increment: Print Tables Topics discussed in this section:

17 Computer Science: A Structured Programming Approach Using C17 FIGURE 8-42 Data Structures For Calculate Row–Column Averages

18 Computer Science: A Structured Programming Approach Using C18 FIGURE 8-43 Calculate Row–Column Average Design

19 Computer Science: A Structured Programming Approach Using C19 PROGRAM 8-18Calculate Row and Column Averages: main

20 Computer Science: A Structured Programming Approach Using C20 PROGRAM 8-19Calculate Row and Column Averages: Get Data

21 Computer Science: A Structured Programming Approach Using C21 PROGRAM 8-19Calculate Row and Column Averages: Get Data

22 Computer Science: A Structured Programming Approach Using C22 PROGRAM 8-19Calculate Row and Column Averages: Get Data

23 Computer Science: A Structured Programming Approach Using C23 PROGRAM 8-19Calculate Row and Column Averages: Get Data

24 Computer Science: A Structured Programming Approach Using C24 PROGRAM 8-20Calculate Row and Column Averages: Row Averages

25 Computer Science: A Structured Programming Approach Using C25 PROGRAM 8-20Calculate Row and Column Averages: Row Averages

26 Computer Science: A Structured Programming Approach Using C26 PROGRAM 8-20Calculate Row and Column Averages: Row Averages

27 Computer Science: A Structured Programming Approach Using C27 PROGRAM 8-20Calculate Row and Column Averages: Row Averages

28 Computer Science: A Structured Programming Approach Using C28 PROGRAM 8-20Calculate Row and Column Averages: Row Averages

29 Computer Science: A Structured Programming Approach Using C29 8-10 Software Engineering In this section, we discuss two basic concepts: testing and algorithm efficiency. To be effective, testing must be clearly thought out. We provide some concepts for testing array algorithms by studying sorting and searching. We then continue the algorithm efficiency discussion started in Chapter 6. Testing Sorts Testing Searches Analyzing Sort Algorithms Analyzing Search Algorithms Topics discussed in this section:

30 Computer Science: A Structured Programming Approach Using C30 Table 8-2Recommended Sort Test Cases

31 Computer Science: A Structured Programming Approach Using C31 When testing an array search, always access the first and last elements. Note

32 Computer Science: A Structured Programming Approach Using C32 Table 8-3Test cases for searches

33 Computer Science: A Structured Programming Approach Using C33 The efficiency of the bubble sort is O(n 2 ). Note

34 Computer Science: A Structured Programming Approach Using C34 The efficiency of the selection sort is O(n 2 ). Note

35 Computer Science: A Structured Programming Approach Using C35 The efficiency of the insertion sort is O(n 2 ). Note

36 Computer Science: A Structured Programming Approach Using C36 The efficiency of the sequential search is O(n). Note

37 Computer Science: A Structured Programming Approach Using C37 The efficiency of the binary search is O(logn). Note

38 Computer Science: A Structured Programming Approach Using C38 Table 8-4 Comparison of binary and sequential searches


Download ppt "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."

Similar presentations


Ads by Google