Cambridge AS Computer science

ARRAYS

An array is a fundamental data structure used to store multiple values of the same data type under a single variable name. This is as an efficient way to manage and process collections of related data, such as lists of numbers, names, or records. Each value in an array is stored at a specific position called an index, which allows individual elements to be accessed, modified, or processed using loops and algorithms.
In other words Array can be defined as a list of items (numbers, strings, etc) of same type accessed by a single name (Array name) along with an index. ARRAY LINEAR SEARCH – PSEUDOCODE QUESTION #1 Write pseudocode to: declare a 1D array Values[ ] of 20 integer elements input 20 integers in to the array search the array for a number input by the user.
DECLARE values : ARRAY[1:20] OF INTEGER DECLARE search: INTEGER FOR x ← 1 TO 20 OUTPUT “Enter a number:” INPUT num Values[x] ← num NEXT x OUTPUT “Enter an item to search for:” INPUT search FOR x ← 1 TO 20 IF values[x] = search THEN OUTPUT “Element”, search, “is found at index “,x ENDIF NEXT x
============================ BUBBLE SORT – Pseudocode DECLARE Values : ARRAY[1:10] OF INTEGER ECLARE Swap: BOOLEAN DECLARE Len: INTEGER #User inputting elements into the array FOR ind ← 1 TO 10 OUTPUT "Enter a number:" INPUT Values[ind] NEXT ind #Sorting the array Len ← 10 REPEAT Swap ← FALSE FOR x ← 1 To Len - 1 # For loop to do one pass through the array IF Values[x] > Values[x+1] THEN Temp ← Values[x] Values[x] ← Values[x+1] Values[x+1] ← Temp Swap ← TRUE # True if any swapping happened in a pass ENDIF Len ← Len - 1 UNTIL Len <= 2 OR Swap = FALSE

Get In Touch

123 Street, New York, USA

info@ictmadesimple.com

+012 345 67890

Newsletter

Follow Us

© www.ictmadesimple.com. All Rights Reserved.