Computer Science Final Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What are the four pillars of OOP?

A

1) Abstraction
2) Encapsulation
3) Inheritance
4) Polymorphism

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Define Abstraction

A

The process of identifying relevant classes, including their data members/values and methods, to solve a problem.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Define Encapsulation

A

Effective information hiding

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Define Inheritance

A

Organization of relevant classes into a hierarchy of super-classes and sub-classes such that the sub-classes can inherit the data members and methods of the super class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Define Polymorphism

A

Execution of different implementations of the exact same method call.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the benefits of polymorphism?

A

Smooth and easy extension and modification of a program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the benefits of inheritance?

A
  • Code Reuse
  • Code Maintenance
  • Extensibility
  • Polymorphism
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Can an abstract class be instantiated?

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Does a sub-class have to implement the abstract methods of the parent class?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Does a sub-class have to implement all of the methods in an abstract class?

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Create an abstract method called “mystery” that returns a String and can only be used by a sub-class.

A

protected abstract String mystery( );

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the benefits of an abstract class?

A

An abstract class is a prototype class that allows the programmer control the base functionality a sub-class must have.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the benefits of an abstract method?

A

They allow the programmer to ensure that every sub-class will implement that method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How is an interface different than an abstract class?

A

An interface only has constants and abstract methods

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the access levels if the “private” specifier is used?

A

Class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are the access levels if no specifier is used?

A

Class and Package

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What are the access levels if the “protected” specifier is used?

A

Class, Package, and Subclass

18
Q

What are the access levels if the “public” specifier is used?

A

Class, Package, Subclass, World

19
Q

What is the difference between overloading and overriding a method?

A

Overloading a method is when different instances of a method expect different parameters.

Overriding a method is when a subclass has the same method name as the parent class, but with a different implementation.

20
Q

When should we use an abstract class as opposed to one that is instantiable?

A

An abstract class should be used if the sub-classes cover all possible forms of the superclass

21
Q

Is the constructor method of a super-class inherited by its subclass?

A

No

22
Q

What are the four components of recursion?

A

1) Stopping Condition
2) End Case
3) Recursive Step
4) Integration Step

23
Q

What is a class?

A

A class is a template for how objects are created/deployed

24
Q

What does a class have?

A

A class has both characteristics (data members) and behavior (methods).

25
Q

What is an object?

A

An object is an instance of a class

26
Q

What are the stages of the software development cycle?

A

Analysis

Design

Coding

Testing

Operation

Maintenance

27
Q

Draw and explain the event-driven programming diagram

A

In java there are numerous event sources, including JButton, JTextField, JCheckBox, etc. When the user interacts with these event sources, they fire off events. In order for these events to affect anything, we must attach event listeners to the event sources. Java then automatically attaches event handlers to the event listeners through the use of interface classes. Thus, when an event source fires off an event, the attached event listener will be triggered, which will call the event handler.

28
Q

What are the main purposes of exception handling?

A
  • Improves the reliability (robustness) of our programs
  • Provides useful information to client programmers (notifies them if they misuse our program)
29
Q

What are the two types of exceptions?

A
  • Checked
  • Unchecked
30
Q

What are the three basic search methods?

A
  • Bubble Sort
  • Insertion Sort
  • Selection Sort
31
Q

What is the difference between checked and unchecked exceptions?

A

Checked exceptions are checked at compilation and must be caught or propagated, while unchecked exceptions are not checked at compilation and do not need to be caught.

32
Q

Describe the heapsort algrorithm

A

1) Construction Phase
- Create a heap (binary tree)
- Make sure the heap meets two constraints:
1) Structural Constraint: Heap is orgranized in a top-down, left-to-right fashion
2) Value-Relationship Constraint: Heap is organized so that the value of each parent node is greater than its children’s values
- Start with the bottom-most, right-most parent node - Make sure its value is greater than that of its children
- If its value is not greater, swap it with the child node that has the greater value and propagate it down. - Repeat for each parent node, moving in a leftward / upward motion
2) Extraction Phase
1) Extraction Step
- Extract the largest value (top-most node) and put it in the output area
2) Reconstruction Step
- Replace the top-most node with the bottom-most, right-most node.
- Reevaluate the necessary parts of the heap
- Compare the top-most node with its children. If it is smaller than its children, swap it with the larger child.
- Keep comparing the node with its children until it is no longer smaller than its children or no longer has children.

Repeat the extraction step until there are no more nodes remaining in the heap

33
Q

What are the benefits of an interface class?

A

Allows for flexibility and customization

Allows Java to provide services for us

34
Q

What is the difference between a sentinel-controlled loop and a count-controlled loop?

A

A sentinel-controlled loop continues as long as the given condition is true.

A count-controlled loop continues for a certain number of iterations.

35
Q

Show how to solve the Towers of Hanoi

A

/* Meaning of variables:

from : pole from which to move disc

to : pole disc is being moved to

spare : pole not involved in disc transfer

n : number of discs on pole/disc number

*/

public long counter = 0;

public void play(int n, int from, int to, int spare) {

       if (n == 1)  {   

                moveOne( from, to );

      } else {    

                play( n-1, from, spare, to);

                moveOne( from, to);

                play( n-1, spare, to, from);

       }

}

private void moveOne (int from, int to) {

      System.out.println( from + " --\> " + to );

       counter++;

}

public static void main(String[] args) {

      TOH game1 = new TOH();

      game1.play(4, 1, 3, 2);

      System.out.println(game1.counter);

}

36
Q

What is the difference between side-by-side problem decomposition and outside-to-inside decomposition?

A

Side-by-side: Different modules applied to different sub-problems

Outside-to-inside: Same module applied to smaller and smaller sub-problems

37
Q

Explain Merge Sort

A

Divide the unsorted list into 2 sub-lists recursively until each sub-list contains one element

Then, merge sub-lists to produce new sorted sub-lists until there is only one list remaining

38
Q

Explain Quick Sort

A
  • Select a pivot (first of the list)
  • Create 2 sub-lists
    - All #’s less than the pivot in list 1
    - All #’s greater than the pivot in list 2
  • Call quick sort on list 1 and list 2
  • Concatenate the result of quicksort(list1), the pivot, and quicksort(list2)
39
Q

State the complexity of the basic sort methods, advanced sort methods, basic search method, and binary search method

A

Basic Sort: O(n^2)

Advanced Sort: O(nlogn)

Basic Search: O(n)

Binary Search: O(logn)

40
Q

Are all public methods of a parent class inherited by a subclass?

A

No (Constructor)