1 / 17

Mastering Linear Arrays: Storing and Manipulating Data Effectively

In this guide, we explore the fundamentals of linear data structures, specifically arrays. Learn how to create, initialize, and manipulate arrays in various programming languages. Understand the characteristics of arrays, including memory allocation and indexing, and how to utilize them for effective data management. Through practical examples, like analyzing Qatar's population from 2000-2007, discover how arrays enable us to find maximums, averages, and trends in data. Join us in class for hands-on exercises and deepen your understanding of array operations.

odele
Télécharger la présentation

Mastering Linear Arrays: Storing and Manipulating Data Effectively

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Structuring Data in a Linear Array

  2. Learning Objectives • When processing lots of data • We learn how to store data in linear structures • We learn how to • Create these linear structures called Arrays • Initialize the elements in the structure • Manipulate the elements in the array • Read into and write from the structure • And more……

  3. Suppose you have to remember 10 things • So you write • String first = new String(“me1”); • String second = new String(“me2”); • String third = new String(“me3”); • String fourth = new String(“me4”); • String fifth = new String(“me5”); • String sixth = new String(“me6”); • String seventh = new String(“me7”); • ….

  4. There is a lot of typing is there a better way to store these variables?Yes

  5. Most Programming Languages provide ways to store many things in a contiguous listlike ….

  6. An array Characteristics - A contiguous block of memory spaces - Each one is referred by an index - indices start from 0 and go to n-1 - a “homogeneous” structure

  7. Defining an array int[ ] A; A= new int[10]; /* initialize elements */ A[0] = 10; A[1] = 20; …..

  8. Can you have an array of any type?

  9. Define an array of any type int[ ] A = new int[10]; String[ ] A = new String[100]; double[ ] A = new double[8858]; boolean[ ] A = new boolean[n]; ….

  10. Length of an array A is given byA.lengthlength is an attribute of A So anytime we need the length it is available

  11. How can I use an array?

  12. An Application Qatar population from 2000-2007 Store in an array What can I do with this?

  13. Pretty much anything… • Find the year of the maximum population • Find the average population per year 2000-2007 • Find the year of the minimum population • Find the median population between 2000-2007 • Find the years where the population increased the most We will look at these questions in Classwork

  14. More examples of Arrays Slide courtesy of Tom Cortina

  15. Examples /* Assume highTemp is an array of ints Slide courtesy of Tom Cortina

  16. Be careful with Array index out of bounds errors Slide courtesy of Tom Cortina

  17. Do Some examples in Class

More Related