Computer Science, asked by mavlesmadhu7697, 5 months ago

Explain different paradigms for problem solving

Answers

Answered by Anonymous
0
Introduction:
The Logical Paradigm takes a declarative approach to problem-solving. Various logical assertions about a situation are made, establishing all known facts. Then queries are made. The role of the computer becomes maintaining data and logical deduction.
Logical Paradigm Programming:
A logical program is divided into three sections:
a series of definitions/declarations that define the problem domain
statements of relevant facts
statement of goals in the form of a query

Any deducible solution to a query is returned. The definitions and declarations are constructed entirely from relations. i.e. X is a member of Y or X is in the internal between a and b etc.
Advantages:
The advantages of logic oriented programming are bifold:
The system solves the problem, so the programming steps themselves are kept to a minimum;
Proving the validity of a given program is simple.

Sample Code of Logical Paradigm.
Functional
Introduction
The Functional Programming paradigm views all subprograms as functions in the mathematical sense-informally, they take in arguments and return a single solution. The solution returned is based entirely on the input, and the time at which a function is called has no relevance. The computational model is therefore one of function application and reduction.
Languages
Functional languages are created based on the functional paradigm. Such languages permit functional solutions to problems by permitting a programmer to treat functions as first-class objects(they can be treated as data, assumed to have the value of what they return; therefore, they can be passed to other functions as arguments or returned from functions).
Advantages
The following are desirable properties of a functional language:
The high level of abstraction, especially when functions are used, supresses many of the details of programming and thus removes the possibility of commiting many classes of errors;
The lack of dependence on assignment operations, allowing programs to be evaluated in many different orders. This evaluation order independence makes function-oriented languages good candidates for programming massively parallel computers;
The absence of assignment operations makes the function-oriented programs much more amenable to mathematical proof and analysis than are imperative programs, because functional programs possess referential transparency.
Disadvantages
Perhaps less efficiencey
Problems involving many variables or a lot of sequential activity are sometimes easier to handle imperatively or with object-oriented programming.
Sample Code of Functional Paradigm.
Object-Oriented
Introduction
Object Oriented Programming (OOP) is a paradigm in which real-world objects are each viewed as seperate entities having their own state which is modified only by built in procedures, called methods.

Because objects operate independently, they are encapsulated into modules which contain both local environments and methods. Communication with an object is done by message passing.

Objects are organized into classes, from which they inherit methods and equivalent variables. The object-oriented paradigm provides key benefits of reusable code and code extensibility.
Features & Benefits
A new class (called a derived class or subclass) may be derived from another class (called a base class or superclass) by a mechanism called inheritance. The derived class inherits all the features of the base class: its structure and behavior(response to messages). In addition, the derived class may contain additional state (instance variables), and may exhibit additional behavior (new methods to resond to new messages). Significantly, the derived class can also override behavior corresponding to some of the methods of the base class: there would be a different method to respond to the same message. Also, the inheritance mechanism is allowed even without access to the source code of the base class.

The ability to use inheritance is the single most distinguishing feature of the OOP paradigm. Inheritance gives OOP its chief benefit over other programming paradigms - relatively easy code reuse and extension without the need to change existing source code.

The mechanism of modeling a program as a collection of objects of various classes, and furthermore describing many classes as extensions or modifications of other classes, provides a high degree of modularity.

Ideally, the state of an object is manipulated and accessed only by that object's methods. (Most O-O languages allow direct manipulation of the state, but such access is stylistically discouraged). In this way, a class' interface (how objects of that class are accessed) is separate from the class' implementation (the actual code of the class' methods). Thus encapsulation and information hiding are inherent benefits of OOP.
Sample Code of Object-Oriented Programming Paradigm.
Similar questions