{"id":231,"date":"2016-12-30T20:03:43","date_gmt":"2016-12-30T20:03:43","guid":{"rendered":"http:\/\/teachcomputerscience.com\/?p=231"},"modified":"2024-07-24T13:04:42","modified_gmt":"2024-07-24T13:04:42","slug":"handling-data-in-algorithms","status":"publish","type":"post","link":"https:\/\/teachcomputerscience.com\/handling-data-in-algorithms\/","title":{"rendered":"Handling Data in Algorithms"},"content":{"rendered":"<div class=\"gb-container gb-container-9f311aa2 upsell-block\"><div class=\"gb-inside-container\">\n<div class=\"gb-grid-wrapper gb-grid-wrapper-9cdcbc0b\">\n<div class=\"gb-grid-column gb-grid-column-7fce4816\"><div class=\"gb-container gb-container-7fce4816\"><div class=\"gb-inside-container\">\n\n<h2 class=\"gb-headline gb-headline-c3072afa gb-headline-text\">GCSE Algorithms Resources (14-16 years)<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>An editable PowerPoint lesson presentation<\/li><li>Editable revision handouts<\/li><li>A glossary which covers the key terminologies of the module<\/li><li>Topic mindmaps for visualising the key concepts<\/li><li>Printable flashcards to help students engage active recall and confidence-based repetition<\/li><li>A quiz with accompanying answer key to test knowledge and understanding of the module<\/li><\/ul>\n\n\n<div class=\"gb-button-wrapper gb-button-wrapper-cfebaaf7\">\n\n<a class=\"gb-button gb-button-bb267066 gb-button-text\" href=\"https:\/\/teachcomputerscience.com\/gcse\/algorithms\/\">View GCSE Algorithms Resources<\/a>\n\n<\/div>\n<\/div><\/div><\/div>\n\n<div class=\"gb-grid-column gb-grid-column-a29e373d\"><div class=\"gb-container gb-container-a29e373d\"><div class=\"gb-inside-container\">\n\n<h2 class=\"gb-headline gb-headline-75276ac9 gb-headline-text\">A-Level Introduction to Algorithms (16-18 years)<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>An editable PowerPoint lesson presentation<\/li><li>Editable revision handouts<\/li><li>A glossary which covers the key terminologies of the module<\/li><li>Topic mindmaps for visualising the key concepts<\/li><li>Printable flashcards to help students engage active recall and confidence-based repetition<\/li><li>A quiz with accompanying answer key to test knowledge and understanding of the module<\/li><\/ul>\n\n\n<div class=\"gb-button-wrapper gb-button-wrapper-2ebdaca2\">\n\n<a class=\"gb-button gb-button-5f16780b gb-button-text\" href=\"https:\/\/teachcomputerscience.com\/a-level\/software\/introduction-to-algorithms\/\">View A-Level Introduction to Algorithms Resources<\/a>\n\n<\/div>\n<\/div><\/div><\/div>\n<\/div>\n<\/div><\/div>\n\n\n\n\n<p>Candidates should be able to:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>define the terms variable and constant as used in an imperative language<\/li><li>use variables and constants<\/li><li>describe the data types integer, real, Boolean, character and string<\/li><li>select and justify appropriate data types for a given program<\/li><li>perform common operations on numeric and Boolean data<\/li><li>use one-dimensional arrays.<\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">What are constants and variables?<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Constants<\/h4>\n\n\n\n<p><strong>Constants<\/strong> are <strong>symbolic names<\/strong> given to data where the value of the data <strong>cannot change<\/strong> during the execution of the program. Many constants such as PI are built into programming languages.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Variables<\/h4>\n\n\n\n<p>Variables are symbolic names given to data where the value of the data stored <strong>may change<\/strong> during the execution of the program. In effect, a variable is a <strong>named area of memory used to store data<\/strong>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Declaring constants and variables<\/h4>\n\n\n\n<p>Many programming languages require constants and variables to be &#8216;declared&#8217; at the start of the program, this defines the variable type (text, integer etc.) and sets the value of any constants.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>The value of a constant is set when it is declared and cannot change when the program is executed.<\/li><li>A variable has no value when it is declared but it&#8217;s value can change when the program is executed.<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">Naming constants and variables<\/h4>\n\n\n\n<p>The name used to label a variable or a constant can be a single letter but many programming languages allow meaningful names to be used which make a program far easier to understand. In almost all languages, variable names cannot start with a digit (0\u20139) and cannot contain whitespace characters.<\/p>\n\n\n\n<p>An example of a statement using <strong>constants<\/strong> and <strong>variables<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>The value of PI would be very tedious to have to keep entering in a program if it was used repeatedly in calculations. If a named constant is used to store the value of PI then this can be used instead.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">CONSTANT PI = 3.142\nINPUT circle_radius\ncircle_area = PI * circle_radius * circle_radius<\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>Here the constant PI is used in a statement that calculates the area of a circle. The variable circle_radius is used to store the radius of the circle and the variable circle_area is used to store the result of the calculation.<\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">What data types are used in programming?<\/h3>\n\n\n\n<p>Most programming languages require the user to declare the type of data stored in the variable or constant. Some of the most common examples are described below:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Character\/string<\/h4>\n\n\n\n<p>A character is a single letter, number or symbol and is treated as a text, even if it is a number.<\/p>\n\n\n\n<p>A string is made up of two or more characters.<\/p>\n\n\n\n<p><strong>Example 1:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">name = \u201cJames\u201d\nPRINT name + name<\/pre>\n\n\n\n<p>The output would be JamesJames<\/p>\n\n\n\n<p><strong>Example 2:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">number = \u201c7\u201d\nPRINT number + number<\/pre>\n\n\n\n<p>The output would be 77<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Real number<\/h4>\n\n\n\n<p>This data type is used to store real numbers i.e. values that might have decimal places.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">number = 7.42\nPRINT number + number<\/pre>\n\n\n\n<p>The output would be: 14.84<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Integer number<\/h4>\n\n\n\n<p>This data type is used to store whole numbers. i.e. values with no decimal places.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">number = 7\nPRINT number + number<\/pre>\n\n\n\n<p>The output would be: 14<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Boolean<\/h4>\n\n\n\n<p>This data type is used to store the logical data TRUE\/FALSE<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">open = TRUE\nPRINT open<\/pre>\n\n\n\n<p>The output would be: TRUE<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">What is an array?<\/h3>\n\n\n\n<p><strong>An array is a variable that can be indexed<\/strong>. The variables in the array have a common name and each one has an <strong>index<\/strong> to identify it within the array. As with normal variables, arrays can be text, real number, integer etc. An index is typically an <strong>integer number<\/strong> or <strong>integer variable<\/strong>.<\/p>\n\n\n\n<p>The example below uses a text array named colour to store a series of named colours. The numbers 1-5 are the array index:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">colour[1] = \u201cRed\u201d\ncolour[2] = \u201cBlue\u201d\ncolour[3] = \u201cGreen\u201d\ncolour[4] = \u201cOrange\u201d\ncolour[5] = \u201cYellow\u201d<\/pre>\n\n\n\n<p>The statements:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">FOR count = 5 TO 1 STEP -1\nOUTPUT colour[count]\nENDFOR<\/pre>\n\n\n\n<p>Would produce the following output:<\/p>\n\n\n\n<p>Yellow<br>Orange<br>Green<br>Blue<br>Red<\/p>\n\n\n\n<p>The advantage of using a <strong>numerical index<\/strong> in an array is that if the index is a variable it is easy to input and output data using an iteration loop as in the use of the variable count in the example above.<\/p>\n\n\n\n<p>Some programming languages also allow the use of a <strong>text index<\/strong> as in the examples below:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">contact[name] = \"James\"\ncontact[age] = \"27\"\ncontact[phone] = \"07654852816\"<\/pre>\n\n\n\n<p>The following statement would produce the output of 27<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">OUTPUT contact[age]<\/pre>\n\n\n\n<h3 class=\"gb-headline gb-headline-4abcacb4 gb-headline-text\">Further Readings: <\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/en.wikipedia.org\/wiki\/Algorithm\" target=\"_blank\" rel=\"noopener\">Algorithm<\/a><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Candidates should be able to: define the terms variable and constant as used in an imperative language use variables and constants describe the data types integer, real, Boolean, character and string select and justify appropriate data types for a given program perform common operations on numeric and Boolean data use one-dimensional arrays. What are constants &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Handling Data in Algorithms\" class=\"read-more button\" href=\"https:\/\/teachcomputerscience.com\/handling-data-in-algorithms\/\" aria-label=\"More on Handling Data in Algorithms\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_generate-full-width-content":"","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[14],"tags":[204,47],"class_list":["post-231","post","type-post","status-publish","format-standard","hentry","category-programming","tag-article","tag-hide-old-upsell","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50"],"acf":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/posts\/231","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/comments?post=231"}],"version-history":[{"count":1,"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/posts\/231\/revisions"}],"predecessor-version":[{"id":605732,"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/posts\/231\/revisions\/605732"}],"wp:attachment":[{"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/media?parent=231"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/categories?post=231"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/tags?post=231"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}