{"id":188,"date":"2022-05-20T20:15:37","date_gmt":"2022-05-20T19:15:37","guid":{"rendered":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phshighercomputingscience\/?page_id=188"},"modified":"2025-11-18T12:21:32","modified_gmt":"2025-11-18T12:21:32","slug":"data-types-and-structures","status":"publish","type":"page","link":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phshighercomputingscience\/data-types-and-structures\/","title":{"rendered":"Data Types and Structures"},"content":{"rendered":"<h2 style=\"color: red\"><strong>Simple Data Types<\/strong><\/h2>\n<p>Data is stored in computer memory and the translation program has to decide where to store the data and how much space to reserve, so the program code must indicate what type of data is to be stored.<\/p>\n<h2 style=\"color: red\"><span style=\"color: #ff0000\">Structures<\/span><\/h2>\n<p>A <strong>data structure<\/strong> is a means of organising and storing <strong>a collection<\/strong> of related data so that it can be retrieved and manipulated within a program. Data structures like <strong>arrays<\/strong>, <strong>records<\/strong> and <strong>files<\/strong> are <strong>composite data objects <\/strong>made up of <strong>simple data types<\/strong>.<\/p>\n<h2 style=\"color: red\">Arrays<\/h2>\n<p>Arrays are used for storing lists of items typically of the same <strong>data type<\/strong>.\u00a0 They are known as <strong>indexed lists<\/strong> because every item in the array is referenced (accessed) by its index position.<\/p>\n<h2 style=\"color: red\">Parallel Arrays<\/h2>\n<p>So far in National 5 and Higher, you have handled tables of data using parallel arrays. This is exemplified by the storage of some qualifying race heats data shown below in 3 separate parallel arrays.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-194\" src=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/20202627\/Screenshot-2022-05-20-202611-300x62.png\" alt=\"\" width=\"629\" height=\"130\" srcset=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/20202627\/Screenshot-2022-05-20-202611-300x62.png 300w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/20202627\/Screenshot-2022-05-20-202611-1024x211.png 1024w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/20202627\/Screenshot-2022-05-20-202611-768x158.png 768w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/20202627\/Screenshot-2022-05-20-202611-624x129.png 624w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/20202627\/Screenshot-2022-05-20-202611.png 1202w\" sizes=\"auto, (max-width: 629px) 100vw, 629px\" \/><\/p>\n<h2 style=\"color: red\">Python Example<\/h2>\n<h2 style=\"color: red\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-195\" src=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/20205541\/Screenshot-2022-05-20-203223-300x117.png\" alt=\"\" width=\"823\" height=\"321\" srcset=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/20205541\/Screenshot-2022-05-20-203223-300x117.png 300w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/20205541\/Screenshot-2022-05-20-203223-1024x398.png 1024w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/20205541\/Screenshot-2022-05-20-203223-768x299.png 768w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/20205541\/Screenshot-2022-05-20-203223-624x243.png 624w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/20205541\/Screenshot-2022-05-20-203223.png 1260w\" sizes=\"auto, (max-width: 823px) 100vw, 823px\" \/><\/h2>\n<h2 style=\"color: red\">Records<\/h2>\n<p>Records in databases are used to <strong>store all the details <\/strong>on one person or thing. In programming, we create a <strong>Record structure <\/strong>to do the same. Records allow us to <strong>store different data types <\/strong>within the one data structure.<\/p>\n<p><strong>An example of a record using Pseudocode is:<\/strong><\/p>\n<h1><span style=\"color: #339966\"><strong>RECORD student IS {name: STRING, surname: STRING, age: INTEGER, height: FLOAT}<\/strong><\/span><\/h1>\n<p><strong>An example of a record using python is:<\/strong><\/p>\n<h2 style=\"color: red\">Array of Records<\/h2>\n<p>A more intuitive way of storing the information would be to use an <strong>array of records<\/strong>. This means having just one array, but each array entry is actually a record.\u00a0 This method keeps all related data together and organised in a way which is more familiar to us. It also removes those difficulties of adding and deleting records.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-207\" src=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/23164821\/Screenshot-2022-05-23-164751-300x109.png\" alt=\"\" width=\"641\" height=\"233\" srcset=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/23164821\/Screenshot-2022-05-23-164751-300x109.png 300w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/23164821\/Screenshot-2022-05-23-164751-768x278.png 768w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/23164821\/Screenshot-2022-05-23-164751-624x226.png 624w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/23164821\/Screenshot-2022-05-23-164751.png 844w\" sizes=\"auto, (max-width: 641px) 100vw, 641px\" \/><\/p>\n<p><strong>An example of an array record using Pseudocode is:<\/strong><\/p>\n<h1><span style=\"color: #339966\"><strong>student_array=[student(&#8220;&#8221;,&#8221;&#8221;,0,0.0)] * 5<\/strong><\/span><\/h1>\n<h2 style=\"color: red\">Advantages of Array of Records<\/h2>\n<ul style=\"font-weight: 400\">\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"18\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:360,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"1\" data-aria-level=\"1\"><span data-contrast=\"auto\">An array of records stores related data together within the same data structure.\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:200,&quot;335559740&quot;:276}\">\u00a0<\/span><\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"18\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:360,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"2\" data-aria-level=\"1\"><span data-contrast=\"auto\">Passing data to sub-programs is easier with an array of records as only one data structure (rather than multiple) need be passed.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:200,&quot;335559740&quot;:276}\">\u00a0<\/span><\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"18\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:360,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"3\" data-aria-level=\"1\"><span data-contrast=\"auto\">There is a raised potential for errors when working with parallel arrays as all must be manipulated consistently.\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:200,&quot;335559740&quot;:276}\">\u00a0<\/span><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Simple Data Types Data is stored in computer memory and the translation program has to decide where to store the data and how much space to reserve, so the program code must indicate what type of data is to be stored. Structures A data structure is a means of organising and storing a collection of [&hellip;]<\/p>\n","protected":false},"author":79984,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-188","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phshighercomputingscience\/wp-json\/wp\/v2\/pages\/188","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phshighercomputingscience\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phshighercomputingscience\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phshighercomputingscience\/wp-json\/wp\/v2\/users\/79984"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phshighercomputingscience\/wp-json\/wp\/v2\/comments?post=188"}],"version-history":[{"count":15,"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phshighercomputingscience\/wp-json\/wp\/v2\/pages\/188\/revisions"}],"predecessor-version":[{"id":357,"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phshighercomputingscience\/wp-json\/wp\/v2\/pages\/188\/revisions\/357"}],"wp:attachment":[{"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phshighercomputingscience\/wp-json\/wp\/v2\/media?parent=188"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}