• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/14

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

14 Cards in this Set

  • Front
  • Back

Abstract Class vs Interface

- An interface is not a class


-Abstract classes are meant to be inherited from
-When one class inherits from the other, it
means there is a strong relationship b/w the
two classes
- Relationship between interface and


implementing class is not necessarily strong




-An abstract class may provide some methods


with definitions



- Abstract class can have constructors

- Interface cannot provide any method
definitions.

http://www.programmerinterview.com/index.php/java-questions/interface-vs-abstract-class/



When to use Abstract Classes


vs


When to use Interfaces

- Abstract class is good if you think you will be using inheritance since it provides a common base class implementation to derived classes.



- Abstract class good if you want to declare non-public members

- If you think you will need to add more methods in the future, then abstract class is a better choice because if you add new method headings to an interface, then all the classes that already implemented the interface will have to be changed to implement the new methods - a hassle.

Object-Pointer Model for Graphs (Complexities)

Memory complexity: O(n) where n is the number of objects to represent the graph


(1 node = 1 object)


O(n^2) number of pointers because each node can have an edge to all other nodes

Time complexity: O(n) access, O(1) delete

Object-Pointer Model for Graphs

- Better for directed graphs because with undirected graphs, pointers would need to be maintained in pairs which may become unsynchronized




- Not optimal for weighted-edge graphs because object-pointer model would need to store edge weights in a parallel array which requires synchronization with the pointer array

Matrix Model for Graphs

- Matrix model is beneficial for weighted-edge graphs because edge weight can be stored in matrix entry (i,j) where i,j <=n where n is the number of nodes in the graph

- Matrix model works for either directed or undirected graphs

Matrix Model for Graphs (complexities)

Memory complexity:


O(n^2) because you have n x n entries in the matrix, one entry for each possible edge between node i and j

Time complexity:
O(1) access because you just check entry (i,j) to see if an edge exists between nodes i and j.
O(n) to find all neighbors of a specified node because you have to look at n elements of a row/column to determine neighbors.

Adjacency List Model for Graphs

Collection of unordered lists used to represent a graph.l Each list is associated with a node in the graph. Each link in the list represents the existence of an edge between the node represented by the list and the node represented by the link in the list.

Adjacency List Model for Graphs (complexities)

Memory: uses memory in proportion to the number of edges. Might save a lot of space if graph being represented is sparse (many real-world graphs are sparse. The internet graph model is sparse).




Time: Each list is as long as the degree of a vertex, worse case lookup is O(n).

Function vs Method

Function is a piece of code that is called by name. It can be passed data to operate on and can optionally return data. All data is passed to a function explicitly




Method is a piece of code called by name that is associated with an object. Most cases identical to function except:
1. A method is implicitly passed the object


on which it is called
2. A method is able to operate on data that


is contained in the class

Object vs Class

- Class is a mechanism of binding data members and associated methods in a single unit




- Object is an instance of a class

- Memory space is allocated when an object is created. Not the case with a class

- Class is created once whereas you may have an arbitrary # of instances (objects) of a class

- Class is virtual, object is physical

- Class is a collection of elements with virtual behavior but an object is an element which has physical behavior

Abstract Base Class

A class in C++ is known as an Abstract Base Class if it has at least one pure virtual function

The function

virtual int area() =0




is how you create a pure virtual function (virtual keyword and =0 at the end).

Virtual Function vs. Pure Virtual Function

Virtual functions provide implementation in the base class. Pure virtual functions do not provide an implementation in the base class.

Multiple Inheritance

Note that this is only allowed in C++.

subclass inherits from more than one parent class:

class Animal
class Mammal
class WingedAnimal

class Bat : public Mammal, public WingedAnimal


C++ vs. Java

Main differences between the two languages:




- Java runs in VM
- C++ natively supports unsigned arithmetic
- In Java, parameters are always passed by value. In C++, parameters can be passed by value, pointer, or reference.
- Java has built-in garbage collection
- C++ allows operator overloading
- C++ allows multiple inheritance of classes.