Prog Lang Exam 2 Flashcards

1
Q

Logic Programming

A

A programming paradigm where logic is used to represent both programs and the process of computation.

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

Mathematical Logic

A

Basis for logic programming, involving the first-order predicate calculus, axioms, theorems, and logical interferences.

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

What are the two logic programming languages?

A

Prolag and Curry

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

Logical Statements

A

Etiher true or false; axioms are assumed true statements from which other true statements are derived.

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

Horn Clauses

A

A simplified form of first-order predicate calculus used in logic programming.

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

Resolution

A

A rule for combining Horn Clauses by eliminating matching terms.

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

Unification

A

Process of making staements identical by assigning values to variables, essential in deriving logical conclusions.

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

Core structures of Prolog, where rules and facts are expressed in a logical format.

A

Horn Clauses

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

Prolog’s Search Strategy

A

Prolog employs a depth-first search strategy to resolve goals, which can lead to infinite loops if not carefully managed.

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

Structure of Horn Clauses

A

a1 and a2 and a3 … and an –> b

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

b

A

Head of the clause.

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

a1, …, an

A

Body of the clause

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

Backtracking

A

Allows Prolog to search for multiple solutions, but care must be taken to avoid infinite loops.

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

Negation as Failure

A

A goal fails if it cannot be proven true, representing the closed-world assumption.

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

Problems with Logic Programming

A

Control issues, occur-check problems, and declarative nature.

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

The Curry Language

A

Combines the features of Haskell (functional programming) and Prolog (logic programming).

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

Curry Key Features

A

Nondeterminism, lazy evaluation, and combincation of functional and logic programming.

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

Nondeterminism

A

Allows multiple solutions to be explored without a predefined order.

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

Lazy Evaluation

A

Only computes values when needed, enhancing efficiency.

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

Prolog vs. Curry

A

Prolog focuses on logic programming with backtracking and unification, whereas Curry blends logic and functional programming with features like lazy evaluation and nondeterminism.

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

OOP languages aim to facilitate:

A
  • Reusability of software components.
  • Modification of behavior with minimal code changes.
  • Independence of different components through abstraction, polymorphism, and encapsulation.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Polymorphism

A

Ability to extend the types of data operations can apply to, like method overloading and parameterized types.

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

Manual memory management

A

Developers must manually allocate and deallocate memory using new and delete.

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

Multiple Inheritanc

A

C++ supports multiple inheritance, which is not allowed in Java due to complexity (such as the diamond problem).

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

Templates

A

C++ templates allow for generic programming, enabling compile-time polymorphism without the overhead of virtual functions

26
Q

Encapsulation

A

Use of private instance variables and accessor methods ensures encapsulation.

27
Q

Constructors/destructors

A

C++ objects have constructors for initialization and destructors for deallocation.

28
Q

Static binding

A

Occurs at compile-time, when the compiler determines the method to call based on the declared type of the object.

29
Q

Dynamic binding

A

Occurs at runtime, where the method to be invoked depends on the actual type of the object. This is achieved through virtual functions and is a key feature in C++ for polymorphism.

30
Q

Compile-time polymorphism

A

Achieved through method overloading and operator overloading.

31
Q

Object overhead

A

OOP introduces additional memory overhead due to metadata like virtual tables.

32
Q

Virtual function calls

A

Introduce performance penalties due to the indirection required for resolving method calls at runtime.

33
Q

Garbage collection

A

In languages like Java or C#, memory management is handled by garbage collection. The GC periodically runs to reclaim memory from objects that are no longer in use. This can introduce unpredictable pauses, which may be problematic for real-time applications.

34
Q

Which of the following best describes the structure of a Horn clause?

A

A rule in the form of A1 ∧ A2 ∧ … ∧ An → B

35
Q

What is the primary inference method used in Prolog?

A

Resolution

36
Q

In Prolog, which operator is used to control backtracking?

A

! (cut)

37
Q

Which language is Curry an extension of?

A

Haskell

38
Q

What is the role of the “fail” predicate in Prolog?

A

It forces Prolog to backtrack and look for another solution.

39
Q

Which of the following is a key principle of object-oriented programming?

A

Polymorphism

40
Q

In Java, which keyword is used to prevent a method from being overridden in a subclass?

A

final

41
Q

What is the purpose of the virtual table (vtable) in C++?

A

To resolve dynamically bound methods at runtime

42
Q

What is the main difference between compile-time polymorphism and runtime polymorphism?

A

Compile-time polymorphism is resolved at compile time, while runtime polymorphism is resolved at runtime.

43
Q

T/F Unification is the process of matching variables with terms to make logical statements identical.

A

True

44
Q

T/F In Prolog, changing the order of Horn clauses can never lead to infinite loops.

A

False

45
Q

T/F The occur-check problem refers to Prolog’s failure to check whether a variable appears in the term it’s being unified with.

A

True

46
Q

T/F Curry supports both deterministic and non-deterministic computations.

A

True

47
Q

T/F The depth-first search strategy in Prolog is more efficient than breadth-first search and avoids all infinite loops.

A

False

48
Q

T/F Dynamic binding is used when a method call is resolved at runtime.

A

True

49
Q

T/F C++ supports both multiple inheritance and operator overloading, while Java does not.

A

True

50
Q

T/F In Java, all objects are allocated on the heap and garbage collected automatically.

A

True

51
Q

T/F The friend keyword in C++ allows one class to access private members of another class.

A

True

52
Q

T/F Garbage collection in Java introduces predictable pauses, making it ideal for real-time systems.

A

False

53
Q

Explain the difference between resolution and unification in logic programming.

A

Resolution is the process of deriving new logical statements by combining Horn clauses, while unification is the process of making two logical expressions identical by assigning values to variables.

54
Q

What is the closed-world assumption in logic programming?

A

The closed-world assumption in logic programming means that anything that cannot be proven to be true is assumed to be false. This assumption underlies the “negation as failure” concept, where if a statement fails to be proven true, it is treated as false.

55
Q

Describe the purpose of the cut operator (!) in Prolog.

A

The cut operator in Prolog is used to prevent further backtracking by pruning parts of the search tree. Once a cut is encountered, Prolog will not try other alternatives for that goal, effectively fixing the choices made up to that point.

56
Q

How does Curry combine functional and logic programming paradigms?

A

Curry combines functional and logic programming by supporting both higher-order functions, lazy evaluation, and logic-based constructs like nondeterminism and unification. It allows programmers to use functional programming constructs alongside logic programming techniques to solve problems.

57
Q

What is negation as failure in Prolog, and what are its limitations?

A

Negation as failure is a rule in Prolog where a goal is assumed false if it cannot be proven true. Its limitation lies in the fact that it depends on the closed-world assumption, meaning it might not work well in cases where knowledge is incomplete or unknown facts exist outside the system.

58
Q

Explain the difference between static binding and dynamic binding in C++.

A

Static binding occurs at compile time and resolves method calls based on the declared type of the object. Dynamic binding occurs at runtime, where the actual method invoked depends on the object’s runtime type. Dynamic binding is achieved in C++ using virtual functions and a virtual table (vtable).

59
Q

What is the significance of the final keyword in Java, and how does it impact performance?

A

In Java, marking a method or class as final means it cannot be overridden. This allows the compiler to optimize method calls by avoiding dynamic dispatch and potentially inlining the method, thus improving performance.

60
Q

How does C++ handle memory management, and what are the risks associated with it?

A

C++ uses manual memory management through new for allocation and delete for deallocation. If developers forget to deallocate memory, it can result in memory leaks. Other risks include dangling pointers, where memory is deallocated but still referenced by a pointer, leading to undefined behavior.

61
Q

Describe how garbage collection works in Java and its potential drawbacks in performance-critical applications.

A

Java uses automatic garbage collection to manage memory, periodically freeing up memory from objects that are no longer referenced. While it simplifies memory management, it can introduce unpredictable pauses (garbage collection pauses), which may negatively impact the performance of real-time or performance-critical applications.

62
Q

Why does Java not support multiple inheritance of classes, and how does it achieve similar functionality?

A

Java does not support multiple inheritance of classes to avoid the complexity and ambiguity of the “diamond problem.” However, it allows classes to implement multiple interfaces, which provides a form of multiple inheritance by allowing objects to inherit behavior from multiple sources.