0% found this document useful (0 votes)
4 views3 pages

Arrays Grade8 Notes

Uploaded by

Yousaf Dua
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)
4 views3 pages

Arrays Grade8 Notes

Uploaded by

Yousaf Dua
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/ 3

CHAPTER 4

PROGRAMMING WITH ARRAYS

Question 1 Which statement from below best describes Arrays?


Option 1 A data structure that shows a hierarchical behavior
Option 2 Container of objects of similar data types
Option 3 Array is not a data structure
Answer: Option 2
Question 2 Which of the following are advantages of arrays?
Option 1 Easier to store elements of similar data type
Option 2 Elements stored in an array cannot be sorted
Answer: Option 1
Question 3 Which of the following are disadvantages of arrays?
Option 1 There are chances of wastage of memory space if elements
inserted
Option 2 in an array
Index valueare
of lesser than
an array canthe
beallocated
negative size
Option 3 Elements are sequentially accessed
Answer: Option 1
Standard Questions
1. What are arrays in programming?
Ans. Arrays are collection of similar data type variables. Arrays do not support
different data types in same collection. For example, you can make an Array of
Integers as well as another Array of Strings. However, you cannot make an
Array having Integer and Strings in same Collection.

2. Explain how arrays are indexed in programming.


Ans. The variables in an Array are always ordered sequentially with index
starting with 0(Zero).

3. Explain how you can sort an array {67, 23, 98, 19} using Python?
Ans. Numbers=[67,23,98,19]
Numbers.sort()
print(Numbers)

Output: [19,23,67,98]

4. How do you search a particular value from an array in Python?


Ans. Python uses indexing as a method to search for an element in an array.
Eg:
X=[2,7,6,4,9,5,11]
print(x.index(9))

Output : 4
5. Find the array length, first index and last index of the given integer array.

1 2 3 4 5

Ans. Array length = 5


First Index = 0
Last index = 4
6. Which are the limitations while using Arrays.
Ans.
o You can only store variables with homogenous data types in an Array
o Arrays are always static and fixed in length and size
o The variables in an Array are always ordered sequentially with index
starting with 0
7. What is sorting an array?
Ans. Sorting is the process of ordering items in a collection.It is the process of
arranging the elements in the array in certain order.
Eg: Numbers=[8,3,10,5]
Numbers.sort()
print(Numbers)

Output: 3,5,8,10
8. What is searching in an array?
Ans. Searching in array means to find a particular element in the array. Python
uses indexing as a method to search for an element in an array.
Eg :
X=[“a”, “b”, “c”, “d”, “e”]
print(x.index(“d”))

Output: 3
9. What is bubble sort? write a python program to sort an array.Ans. Bubble sort
is a method of sorting that works by repeatedly swapping adjacent elements if
they are in incorrect order.
Program :

def sort(nums):

for i in range(len(nums)-1,0,-1):

for j in range(i):

if nums[j]>nums[j+1]:

temp=nums[j]

nums[j]=nums[j+1]

nums[j+1]=temp

nums=[8,7,3,10,2,9]

sort(nums)

print(nums)

10.What is the starting index of an array.


Ans. 0
11.___________ method is used to add an element to an array.
Ans. append()
12.________ method is used to remove an element of an array.
Ans. pop() or remove()
13.The _________ method sorts the list ascending by default.
Ans. sort()
14.The values of an array can be accessed by referring to a/an _____number.
Ans. Index

You might also like