Lists and arrays for a test

Understanding lists and arrays is crucial for organizing data in programming. This study material covers key concepts and differences between the two.

CharlotteBrown·15 schede·12 domande·1 visualizzazioni
high schoolcomputer_scienceprogramming
0
Lo so
1 / 15
0
Sto imparando
Fronte

What is a list?

Tocca per girare
Retro

A collection of ordered items. Lists can hold different data types.

Tocca per girare
Lo so
Sto imparando

Quiz(12 domande)

Domanda 1 di 12

1. What is the main characteristic of an array?

Termini in questo set(15)

What is a list?

A collection of ordered items. Lists can hold different data types.

What is an array?

A collection of items of the same data type stored in contiguous memory.

Difference between lists and arrays

Lists can hold varied data types; arrays are type-specific.

True or false: Lists are mutable.

True, because you can change a list after it's created.

True or false: Arrays can resize dynamically.

False, because arrays have a fixed size once defined.

Fill in the blank: In Python, a list is created using ____.

square brackets: []

What is indexing in lists?

Accessing elements by their position, starting from 0.

Define a two-dimensional array.

An array containing arrays, representing a grid structure.

What method adds an item to a list in Python?

The append() method adds an item at the end of the list.

Example of an array declaration in Java.

int[] nums = {1, 2, 3};

What does slicing a list mean?

Extracting a part of the list using a range of indices.

True or false: Arrays can store different data types.

False, because all elements must be of the same type.

Which is faster: list or array?

Arrays are generally faster due to fixed sizes and type consistency.

What does 'length' return for an array?

The number of elements in the array.

How to access the first element of a list?

Use index 0 like: listName[0].

Domande in questo set(12)

1. What is the main characteristic of an array?

A.Fixed size
B.Dynamic size
C.Heterogeneous types
D.Unordered

2. Which of the following is NOT a property of a list?

A.Ordered
B.Heterogeneous
C.Fixed size
D.Mutable

3. How do you add an element to an array?

A.Append
B.Push
C.Update
D.Not possible

4. Which data structure is more memory efficient?

A.List
B.Array
C.Both
D.Depends on the data

5. In Python, how do you access the second item in a list?

A.list[1]
B.list[2]
C.list.first()
D.list.get(1)

6. Which is typically faster for accessing elements?

A.Lists
B.Arrays
C.Both are equal
D.Depends on language

7. What is the result of slicing a list?

A.An error
B.A single element
C.A new list
D.The original list

8. Which structure can contain different data types?

A.List
B.Array
C.Both
D.Neither

9. Which method removes the last item from a list?

A.pop()
B.remove()
C.delete()
D.discard()

10. What does an index out of range error indicate?

A.Correct access
B.Invalid index
C.Exceeds array size
D.Both B and C

11. Which programming language uses lists as a fundamental data type?

A.Java
B.C
C.Python
D.Assembly

12. Which operation would generally be slower on a list?

A.Appending
B.Inserting at start
C.Accessing last element
D.Removing last element

Set correlati

Crea il tuo set di studio

Carica un PDF, incolla le tue note o descrivi un argomento – l'IA genera schede, quiz e altro in pochi secondi.