{"id":45306,"date":"2024-02-17T06:37:26","date_gmt":"2024-02-17T01:07:26","guid":{"rendered":"https:\/\/www.aplustopper.com\/?p=45306"},"modified":"2024-02-17T15:35:08","modified_gmt":"2024-02-17T10:05:08","slug":"plus-one-computer-science-notes-chapter-8","status":"publish","type":"post","link":"https:\/\/www.aplustopper.com\/plus-one-computer-science-notes-chapter-8\/","title":{"rendered":"Plus One Computer Science Notes Chapter 8 Arrays"},"content":{"rendered":"
Summary<\/span> Declaring arrays:<\/span> Memory allocation for arrays:<\/span> Array initialization:<\/span> Accessing elements of arrays:<\/span> Array operations:<\/span> Sorting:<\/span> 2. Selection sort: Searching:<\/span> 2. Binary search: The second possibility is the element is less than the middle value so the upper bound is the middle element. The third possibility is the element is greater than the middle value so the lower bound is the middle element. Repeat this process.<\/p>\n Two dimensional (2D) arrays:<\/span> Declaring 2D arrays:<\/span> Matrices as 2D arrays:<\/span> Multi-dimensional arrays:<\/span> Kerala Plus One Computer Science Notes Chapter 8 Arrays Summary An array is a collection of elements with same data type Or with the same name we can store many elements, the first or second or third, etc can be distinguished by using the index(subscript). The first element\u2019s index is 0, the second element’s index […]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[42728],"tags":[],"yoast_head":"\n
\nAn array is a collection of elements with same data type Or with the same name we can store many elements, the first or second or third, etc can be distinguished by using the index(subscript). The first element\u2019s index is 0, the second element’s index is 1, and so on.<\/p>\n
\nSuppose we want to find the sum of 100 numbers then we have to declare 100 variables to store the values. It is laborious work. Hence the need for array arises.
\nSyntax: data_type array_name[size];
\nTo store 100 numbers the array declaration is as follows
\nint n[100]; By this we store 100 numbers. The index of the first element is 0 and the index of last element is 99.<\/p>\n
\nThe amount of memory requirement is directly related to its type and size,<\/p>\n\n
\nArray can be initialized in the time of declaration. eg: int age[4] = {16, 17, 15, 18};<\/p>\n
\nNormally loops are used to store and access elements in an array.
\neg:
\nint mark[50], i;
\nfor(i=0;i<50;i++)
\n{
\ncout<<\u201cEnter value for mark\u201d<<i+1;
\ncin>>mark[i];
\n}
\ncout<<\u201cThe marks are given below:\u201d;
\nfor(i=0;i<50;i++)
\ncout<<mark[i];<\/p>\n
\nTraversal:
\nAccessing all the elements of an array is called traversal.<\/p>\n
\nArranging elements of an array in an order(ascending or descending)
\n1. Bubble sort:
\nIt is a simple sorting method. In this sorting considering two adjascent elements if it is out of order, the elements are interchanged. After the first iteration the largest(in the case of ascending sorting) or smallest(in the case of descending sorting) will be the end of the array. This process continues.<\/p>\n
\nIn selection sort the array is divided into two parts, the sorted part and unsorted part. first smallest element in the unsorted part is searched and exchanged with the first element. Now there is 2 parts sorted part and unsorted part. This process continues.<\/p>\n
\nIt is the process of finding the position of the given element.
\n1. Linear search:
\nIn this method each element of the array is compared with the element to be searched starting from the first element. If it finds the position of the element in the array is returned.<\/p>\n
\nIt uses a technique called divide and conquer method. It can be performed only on sorted arrays. First we check the element with the middle element. There are 3 possibilities. The first possibility is the searched element is the middle element then search can be finished.<\/p>\n
\nSome occasions we have to store 6 different marks of 50 students. For this we use 2D arrays. An array with two subscripts is used.
\neg: int mark[r][c]; Here r is the row and c is the column.<\/p>\n
\nSyntax: datatype array_name[rows][columns];
\nThe elements of this array is referred as mark[0][0], mark[0][1], mark[r – 1][c – 1].
\neg: int m[5][5]; This array can store 5 \u00d7 5 = 25 elements.<\/p>\n
\nMatrix is a concept in mathematics that can be represented by 2D array with rows and columns. A nested loop(a loop contains another loop) is used to store and access elements in an array.<\/p>\n
\n3 Dimensional(3D) array is an example of this.
\nSyntax: data_type array_name[size1 ][size2][size3];
\neg: int m[5][5][5]; This array can store 5 \u00d7 5 \u00d7 5 = 125 elements.<\/p>\nPlus One Computer Science Notes<\/a><\/h4>\n","protected":false},"excerpt":{"rendered":"