Pemodelan Untuk Komputasi : Array Satu Dimensi dan Contoh Soal ( Bahasa Inggris )

Pemodelan Untuk Komputasi : Array Satu Dimensi dan Contoh Soal ( Bahasa Inggris )



Introduction of Array and Data Organization

Have you ever had trouble finding an important item in your room because the room was cluttered and disorganized ?

Have you ever had trouble finding a file on your computer because you could not remember what it was named ?

Computing systems commonly manage billions of items with every passing moment. A computing system must keep precise account of this data as it flows through the system and this requires close attention to every small detail. In particular, this chapter explains that all data must be well organized and properly identified in order to be usable.



The Importance of Names

The following is the opening stanza of this short story, “Too Many Daves” by Dr. Seuss :

Did I ever tell you that Mrs. McCave 
Had twenty-three sons and she named them all Dave? 
Well, she did. And that wasn’t a smart thing to do. 
You see, when she wants one and calls out, “Yoo-Hoo! 
Come into the house, Dave!” she doesn’t get one. 
All twenty-three Daves of hers come on the run! 
This makes things quite difficult at the McCaves’ 
As you can imagine, with so many Daves.

The same thing is true of computing. 

When computational data is inappropriately or confusingly named it becomes very difficult to access or reason about the data. This same principle is not only true in the context of computation but is equally true in real life. 

Although it can be very difficult to determine the correct name for at item, if we inappropriately name something in the real world, some degree of confusion and difficulty will inevitably follow. If, for example, we mistakenly identify a coral snake (a venomous variety) as a scarlet snake (a nonvenomous variety) we are likely to endure much more difficulty than Mrs. McCave !



Guidelines of Naming


  1. Names should be unique.
    • If a name only refers to a single item, then whenever that name is used there is no confusion about what item is being referred to. 
  2. One item should not have more than one name. 
  3. A name should be descriptive 
    • What if we decided to give random names to all of the MP3 music files on our computer: zqiy.mp3, gzpu.mp3, and gaep.mp3.


List

Are you the type of person that makes a list of everything? 

Perhaps you have a list of your: 
  • favorite friends 
  • a shopping list 
  • a list of your favorite movies or favorite foods 
  • a to-do list 
  • a pet-peeve list 
  • a reading list, 
  • a wish list, 
  • or even a list of all of your lists. 

Much of the world’s data is best organized in list form.



A list is a sequence of items that are arranged in a particular order. Consider the following list of the top five most expensive paintings of all time. 
  1. The Card Players by Paul Cezanne 
  2. No. 5, 1948 by Jackson Pollock 
  3. Woman III by Willem de Kooning 
  4. Portrait of Adele Bloch-Bauer I by Gustav Klimt 
  5. Portrait of Dr. Gachet by Vincent van Gogh 

Any item on the list can be identified by its position in the list. Example: 
  • The Card Players is the number one most expensive 
  • Portrait of Dr. Gachet is the fifth (or number five) most expensive painting of all time.



Array

An array is perhaps the simplest way of storing a list in memory. Also, array stores each item at the memory address corresponding to the items position in the list. If we store the list of the top five most expensive paintings, for example, we would store the information as shown in figure below :



Indexing

When we use numbers to identify the things in a list we are using a technique known as indexing. Indexing associates a unique number with every item in a set of data and therefore allows the items to be identified by their index. Since indices are used to identify data within a list; an index can be understood as a unique name for one of the items in a list.

We will denote an item in a list by using brackets. For example, if Paintings is the name of a list, we denote the i-th painting as Paintings[i]. Most computing systems assume the first item in a list has an index of 0. We denote the first item in the list as Paintings[0] and the second item in the list as Paintings[1].



Creating an Array

  • To create an array, we must give a name for the array. 
    • Example: Paintings, Movies, Courses, Students, etc. 
  • We also need to determine the size of array. 
  • Remember that an array has a static size. 
  • Thus, if you create an array with size of 6, you can only store 0-6 data in that array.

  • Example : 
    • Paintings is an array with size 5 
    • Students is an array with size 32.



Example 1

We have the list of students in a class. We want to print the name of students in that class. To do so, we need to access all the element of the array. 

Here is the algorithm.



Example 2

We have an array of integers and we want to calculate the sum of all element of the array.



Example 3


We have students’ grade in a class. We want to find the highest grade in that class.



Example 4

You have a list of number. You want to check if the list is ordered increasingly. 



Example 5

Every student in the class has 2 assignments (assignment1 and assignment2). You want to calculate and store the average of grade for assignment 1 and assignment 2 for every student.


Post a Comment

Lebih baru Lebih lama