Which scenario best describes when you should choose an array over other data structures?
Think about how arrays store elements and how you access them.
Arrays provide fast access by index and are best when the size is known and fixed. Other structures like linked lists or trees are better for frequent insertions or sorted data.
What is the output of this Rust code snippet?
let arr = [10, 20, 30]; let vec = vec![10, 20, 30]; println!("{} {}", arr[1], vec[1]);
Remember that both arrays and vectors support indexing in Rust.
Both the array and vector have the element 20 at index 1, so the output is '20 20'.
Consider this Rust code. What happens when you try to compile and run it?
let mut arr = [1, 2, 3]; arr.push(4); println!("{:?}", arr);
Think about whether arrays in Rust can change size.
Arrays in Rust have fixed size and do not have a 'push' method. Only vectors can be resized dynamically.
Which of the following is a key advantage of arrays compared to linked lists?
Think about memory layout and access speed.
Arrays store elements contiguously, which uses less memory and allows fast access by index. Linked lists use extra memory for pointers and have slower access.
You need to store a fixed number of sensor readings that will be read many times but never changed after initialization. Which data structure is best?
Consider the need for fixed size and frequent reads.
Arrays are ideal for fixed-size collections with frequent reads because they provide fast access and minimal overhead.
