• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 2 out of 5 pages
Exam (elaborations)

Dsa Exam 1 Questions With Correct Answers

Document preview thumbnail
Preview 2 out of 5 pages

DSA EXAM 1 QUESTIONS WITH CORRECT ANSWERS

Content preview

DSA EXAM 1 QUESTIONS WITH
CORRECT ANSWERS

1. What differentiates an array from anArrayList?

A. Arrays can hold primitives,ArrayLists cannot.
B. Array elements are accessedby index, ArrayList elementsare not.
C. Arrays can hold objects,ArrayLists cannot.
D. Arrays are a set size, whereasArrayLists expand.
E. A & D - Correct Answers -E

2. When we talk about Big O notation and worst case complexity, we often refer to 'n'.
What is n?

A. A generic data type
B. A random number
C. The size (amount)of the data
D. One data item - Correct Answers -C

3. Adding a new item to the end of a 500-element ArrayList requires to programmer to
shift how many elements?

A. 1
B. 0
C. 499
D. 500 - Correct Answers -B

4. Which of the following are valid assertionstatements (in terms of syntax)? Assume
allvariables are of type int.

A. AssertTrue(instance.isEmpty());
B. AssertFalse(expectedResult, instance.size());
C. AssertEquals(result, expectedResult);
D. A & C - Correct Answers -D

5. What is the complexity of the following method?

public void myMethod(int x) {
int sum = 0;
for (int i = 0; i < x; i++) {
System.out.println(i);

, sum+= i;
}
System.out.println(sum);
}

A. O(1)
B. O(n)
C. O(n2)
D. O(2n) - Correct Answers -B

6. You can determine complexity of a method thatoperates on a data structure by
looking at the datastructure's interface (ADT).

A. True
B. False - Correct Answers -B

7. Which of the following operations is not O(1)From the perspective of a programmer
usingarrays?

A. Returning the capacity of the array
B. Searching for a specific element in the array
C. Creating a new array
D. Inserting an element at the beginning of an array without capacity
E. B & D - Correct Answers -E

8. Given the following code, what outputwill the last line produce?
ArrayList<Integer> myNums = new ArrayList<>():
myNums.add(5);
myNums.add(2);
myNums.add(1, 7);
System.out.println(myNums);

A. [5, 7, 2]
B. [5, 2, 1, 7]
C. [5, 2, 1]
D. [2, 7, 5] - Correct Answers -A

9. After executing the following line of code, what best describes myClass?
Student[] myClass = new Student[25];

A. A pointer to an array of 25 Student objects
B. A pointer to an array of 25 nulls
C. A null pointer
D. None of the above - Correct Answers -B

17. How many Employee objects are created by the following?

Document information

Uploaded on
March 26, 2026
Number of pages
5
Written in
2025/2026
Type
Exam (elaborations)
Contains
Questions & answers
$12.99

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
millyphilip
3.7
(560)
Sold
2991
Followers
1963
Items
46797
Last sold
4 days ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions