[go: up one dir, main page]

0% found this document useful (0 votes)
14 views13 pages

32 Arrays Tuples and Records SAMPLE A Level

Teach Computer Science offers affordable resources for teaching computer science to students aged 11 and above, suitable for various curricula. The document provides an overview of data structures, specifically arrays, including their types, characteristics, and practical activities for classroom use. It also includes quizzes, flashcards, and a Creative Commons license for sharing and adapting the material.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views13 pages

32 Arrays Tuples and Records SAMPLE A Level

Teach Computer Science offers affordable resources for teaching computer science to students aged 11 and above, suitable for various curricula. The document provides an overview of data structures, specifically arrays, including their types, characteristics, and practical activities for classroom use. It also includes quizzes, flashcards, and a Creative Commons license for sharing and adapting the material.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Teach Computer Science

Free Sample
THANK YOU FOR DOWNLOADING THIS FREE SAMPLE RESOURCE!
Here, you’ll find a snippet of the module, which you can use to gauge the quality
of our offering, but will also find super useful in the classroom.

Teach Computer Science is an affordable, high-quality offering for teachers and


students alike whether that’s in the classroom, online, or homeschool
environment. You’ll find everything you need to learn or teach a computer
science subject for students aged 11-14, 14-16, and 16+ following any of the UK
examination boards, or any other curriculum from around the world.

If you want the complete module, which contains classroom presentation,


revision notes, quizzes, mind maps, flashcards, activities and answer keys, then
please upgrade to one of our Premium plans and support our quest to make
education affordable for all.

The Teach Computer Science Team

teachcomputerscience.com
Teach Computer Science
A-Level

Arrays, Tuples and


Records

teachcomputerscience.com
1.

Revision notes

teachcomputerscience.com
Introduction
The primary purpose of a computer system is to process data. The
data can be of any type. If a computer program needs to process one
piece of data, then that data can be stored in a variable, and the
resultant data can be stored in another variable. In this case, a couple
of variables are sufficient to write a program. But real-life programs
need to handle tens of thousands of pieces of data. When handling
large amounts of data, it is impossible to store each piece data in a
separate variable. Therefore, data is grouped together or, more
precisely, structured in a specific format. The collection of data
structured together is called a data structure. In this article, types of
data structures and implementation of some data structures in
computer programs are discussed.

Types of data structure


Data structures are classified based on how the data is organised. In
this article, arrays are explained in detail.

Characteristic Description Examples


In linear data structures, the data items are
Linear Array
arranged in a linear sequence.
In non-Linear data structures, the data items Tree,
Non-Linear
are not in sequence. Graph
In homogeneous data structures, all the
Homogeneous Array
elements are of the same type.
Non- In non-homogeneous data structures, the
Structures
Homogeneous elements may or may not be of the same type.
Static data structures are those whose size-
Static and structure-associated memory locations Array
are fixed, at compile time.
Dynamic structures are that which expand or
shrink depending upon the program’s need
Dynamic Linked List
and its execution. Also, their associated
memory locations change.
teachcomputerscience.com
Arrays
Arrays are a form of data structure used to store a set of data
elements in a certain order. All the data elements should be of the
same data type. An array can store a set of integer values or a set of
character strings. Each element of an array is stored in memory as per
their order. The following figure illustrates parts of an array.

Country
name
Array name
Data elements
Afghanista Index
1
n
Albania 2
Algeria 3
USA 4
Andorra 5

Figure 1: Elements of an array


The above figure shows a one-dimensional array, as the array has only
one list. If the minimum, maximum and average temperature for each
nation needs to be included, then there will be another list for each
data element. Then, the resultant array is called a two-dimensional
array. Figure 2 illustrates a two-dimensional array.

teachcomputerscience.com
2.

Activities

teachcomputerscience.com
Activity-1
Duration: 10 minutes

1. Write a Python program to create an array holding 10 elements.


Ask the user to enter a number into the array. Use two different
arrays to store even and odd numbers separately and print them.

teachcomputerscience.com
Activity-1
Duration: 10 minutes

1. Write a Python program to create an array holding 10 elements.


Ask the user to enter a number into the array. Use two different
arrays to store even and odd numbers separately and print them.

#declaring an array
import array
a=array.array('i',range(10))
#entering data into array
i=0
while(i<10):
a[i]=int(input("Enter element:"))
i=i+1
even=array.array('i',range(10))
odd=array.array('i',range(10))
j=0
k=0
l=0
#separating even and odd numbers into separate list
while (j<10):
if(a[j]%2==0):
even[k]=a[j]
k=k+1
else:
odd[l]=a[j]
l=l+1
j=j+1
#printing both the lists
print("The even list")
x=0
while (x<k):
print(even[x],end=" ")
x=x+1
print("\nThe odd list")
y=0
while (y<l):
print(odd[y],end=" ")
y=y+1

teachcomputerscience.com
Flashcards

A collection of data
What is a data structured together in a
structure? specific format is called a
data structure.

Real-life programs need to


handle tens of thousands of
Why are variables pieces of data. When
not enough for real- handling large amounts of
data, it is impossible to store
life programming? each piece of data in a
separate variable.

teachcomputerscience.com
Glossary

A form of data structure used to store a set of


Array data elements of the same data type in a certain
order.

A collection of data structured together in a


Data Structure
specific format.

A language construct that allocates space for


Declaration
variables and constants during compilation.

Data structures whose memory can expand or


Dynamic shrink depending upon the program’s need and
its execution.

teachcomputerscience.com
Quiz
1. Complete this sentence: Arrays are ……………… data structures.
A. Linear, homogenous and static
B. Linear, homogenous and dynamic
C. Non-linear, homogenous and static
D. Non-linear, non-homogenous and dynamic

2. Which of the following is TRUE about arrays?


A. Arrays store data in a certain order
B. All data in an array are of the same data type
C. Each element has a corresponding index value
D. All of the above

3. Complete this sentence: ……………… module is initiated from


Python library to work with arrays.
A. array
B. data structures
C. index
D. none of the above

3. Complete this sentence: Index of an array starts with ………………


A. 0
B. 1
C. -1
D. 2

teachcomputerscience.com
Teach Computer Science

This resource is licensed under the Creative Commons Attribution-


NonCommercial 4.0 International license.

You are free to:

● Share — copy and redistribute the material in any medium or


format
● Adapt — remix, transform, and build upon the material

Under the following terms:

● Attribution — You must give appropriate credit, provide a link to


the license, and indicate if changes were made. You may do so
in any reasonable manner, but not in any way that suggests the
licensor endorses you or your use.
● NonCommercial — You may not use the material for
commercial purposes.

For more information on this license, visit the following link:

http://creativecommons.org/licenses/by-nc/4.0/

Thank you!

teachcomputerscience.com
Teach Computer Science

Thank you so much for downloading this resource!

We hope it has been useful for you in the classroom and that your
students enjoy the activities.

For more teaching resources like this, don’t forget to come back
and download the new material we add every week!

Thanks for supporting Teach Computer Science. We can provide


teachers with low-cost, high-quality teaching resources because
of our loyal subscribers and hope to serve you for many years to
come.

- The Teach Computer Science Team :)

teachcomputerscience.com

You might also like