Shared Flashcard Set

Details

CS 125
CS 125 Final Exam Flashcards
29
Computer Science
Undergraduate 1
05/03/2018

Additional Computer Science Flashcards

 


 

Cards

Term
What's a literal?
Definition
a number or other value that appears directly in the source code.
Term
How are conditionals evaluated?
Definition
Left -> Right

Example: Will stop at 1 > 2
if (3 < 4 || 1 > 2 || doge == null)

1>2 stops.
Term
Initialize an array
Definition
int[] multiple = new int[8];
Term
Convert this to an enchanced loop:

int[] primes = { 2, 3, 5, 7, 11, 13 };
for (int i = 0; i < primes.length; i++) {
System.out.println(primes[i]);
}
Definition
int[] primes = { 2, 3, 5, 7, 11, 13 };
for (int a : primes) {
System.out.println(a);
}
Term
The code that calls the function is referred to as .....
Definition
the caller.
Term
int counter = 0;
for (int index = 0; index < 10; index++) {
if (index > 4) {
continue;
counter--;
}
counter--;
}

What does this return/do?
Definition
Line 5, Column 14: Statement is unreachable
Term
function signature
Definition
function name and the the list of arguments and types
Term
char[][] currentBoard =
{{'X', 'O', 'a'}, {'O', 'X', '.'}, {'O', '.', 'X'}};

how do I print 'a' from that?
Definition
System.out.println(currentBoard[0][2]);
Term
int i = 10;
double d = 34.23;
i = d;

How do I make this work?
Definition
i = (int) d;
Term
Objects combine ___________
Definition
state (like variables) and behavior (like functions).
Term
Java classes _______________ be modified as the program runs

(insert blank)
Definition
cannot
Term
protected
Definition
the variable can read or written by methods defined on that class or its descendants…​ in any package
Term
Java classes can access their parent’s constructor using _____.
Definition
the super keyword.

This must be the first thing done in a child constructor.

Example:
public class Pet {
protected String type;
Pet(String setType) {
this.type = setType;
}
}
public class Dog extends Pet {
private String breed;
Dog(String setBreed) {
super("Dog");
this.breed = setBreed;
}
}
Term
Object a = new Object("a");
Object b = a
Object c = new Object("a");

What does:

a == b result in?
a == c result in?
Definition
a == b is true.
a == c is false.
Term
We can refer to a Java variable that refers to an object as a ______?
Definition
reference variable
Term
References are objects, true or false?
Definition
FALSE.

See https://cs125.cs.illinois.edu/learn/references/#7

They just refer to the object, but are not object.

Kind of like a phone number
Term
Insertion Sort w/ Brief Example

Best/Worst Time
Space
Definition
1) Start at start
2) Sort next value

Example:

8 5 7 1 10
5 8 7 1 10
5 7 8 1 10
1 5 7 8 10
1 5 7 8 10

Worst O(n^2)
Best O(n)
Avg O(n^2)

Space:
O(1)
Term
Write mergesort after having a merge() function.
Definition
if (input.length == 1) {
return input;
}
int mid = input.length /2
int[] first = Arrays.copyOfRange(input, 0, mid);
in[] second = Arrays.copyOfRange(input, mid, input.length);
return merge(mergesort(first), mergesort(second));
Term
Space and time for mergesort
Definition
Always O(nlogn) for time. Always O(n) for space.
Term
Best sort on small array?
Definition
Insertion Sort.
Term
What defines a stable/unstable sort?
Definition
Stable -> two items with the same value cannot switch positions

Unstable -> two items with the same value may switch positions
Term
How many protocols are there limited on the internet?
Definition
Many! Examples include http (web), smtp (email), dns (domain name service), or ynp (your protocol)
Term
How to use query parameter in GET? How does it differ for multiple queries?
Definition
Use the ? sign. Use the & sign for multiple.
Term
What is the World Wide Web?
Definition
A protocol (HTTP), a markup language (html), a styling language (CSS), a programming language (JS)
Term
End to end principle (internet)
Definition
Reliable delivery not guaranteed by core network.
Term
A hash function has ____
Definition
Determinism, Uniformity, Efficiency
Term
Use a hashmap (put/get)
Definition
Map a = new HashMap();
a.put("doge", 3);
sout(a.get("doge"));
// Prints 3
Term
Java exceptions are broken into three distinct categories. What are they?
Definition
Checked exceptions, Unchecked exceptions, errors
Term
main method
Definition
public static void main(String[] unused)
Supporting users have an ad free experience!