100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Exam (elaborations)

CS 1332 TOP Study Guide Questions and CORRECT Answers

Rating
-
Sold
-
Pages
29
Grade
A+
Uploaded on
23-05-2024
Written in
2023/2024

ArrayList Constructor() (code) ngArray = (T[]) new Object[INITIAL_CAPACITY]; = 0; ArrayList RemoveAtIndex() (code) BIG O - O(n) Steps: 1. Store element to return 2. edge case - removing from end 3. edge case - list empty 4. shift element to be removed to back of the list and null out { T element = backingArray[index];

Show more Read less
Institution
CS 1332
Module
CS 1332










Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
CS 1332
Module
CS 1332

Document information

Uploaded on
May 23, 2024
Number of pages
29
Written in
2023/2024
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

Content preview

CS 1332 TOP Study Guide Questions and CORRECT Answers ArrayList Constructor() (code) ✔✔✔this.backingArray = (T[]) new Object[INITIAL_CAPACITY]; this.size = 0; ArrayList RemoveAtIndex() (code) ✔✔✔ BIG O - O(n) Steps: 1. Store element to return 2. edge case - removing from end 3. edge case - list empty 4. shift element to be removed to back of the list and null out { T element = backingArray[index]; if (index == size - 1) { backingArray[index] = null; } else if (size == 0) { return null; } else { for(int i = index; i < size - 1; i ++) { backingArra y[i] = backingArray[i + 1]; } backingArray[size - 1] = null; } size -= 1; return element; } ArrayList isEmpty() (code) ✔✔✔ public boolean isEmpty() { return size == 0; } ArrayList removeFromFront() (code) ✔✔✔ BIG O - O(n) Steps: 1. store element to return 2. edge case - if empty 3. shift all elements --> front element is at the back { T element = backingArray[0]; if (size == 0) { return null; } for (i = 0; i < size - 1; i++) { backingArray[i] = backingArray[i + 1]; } back ingArray[size - 1] = null; size -= 1; return element; } ArrayList removeFromBack() (code) ✔✔✔ BIG O - O(1) Steps: 1. store element to return 2. check if empty 3. set the last element to null { T element = backingArray[size - 1]; if (size == 0) { return null; } backingArray[size - 1] = null; size -= 1; return element; } ArrayList get() (code) ✔✔✔ BIG O - O(1) { return backingArray[index]; } ArrayList addAtIndex() (code) ✔✔✔ BIG O - O(n) Steps: 1. does index = size, add to back 2. regrow an d shift
£7.67
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
WIZGrades

Get to know the seller

Seller avatar
WIZGrades Havard School
Follow You need to be logged in order to follow users or courses
Sold
10
Member since
1 year
Number of followers
1
Documents
4644
Last sold
1 week ago

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

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

Didn't get what you expected? Choose another document

No problem! You can straightaway pick a different document that better suits what you're after.

Pay as you like, start learning straight 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 smashed it. It really can be that simple.”

Alisha Student

Frequently asked questions