Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

HND in computing for software engineers, Study notes of Programming Paradigms

very helpful for any student to search this in one thing.

Typology: Study notes

2019/2020

Uploaded on 11/17/2021

thamindu-sharitha
thamindu-sharitha 🇮🇳

11 documents

1 / 20

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Table Of Content
Table of Contents
Part 2 ...................................................................................................................................... 3
2.1. Write an imperative definition for the above-described ADT using the example of software
stack. ...................................................................................................................................... 3
2.1 What is Abstract data types............................................................................................. 3
2.1.2 Stack ADT .................................................................................................................. 4
2.1.3 Software Stack ............................................................................................................ 5
2.1.3.1 Example for Stack ADT............................................................................................ 5
2.2. Explain in detail the advantages of encapsulation and information hiding when using an
ADT. (Max 300 words)............................................................................................................ 6
2.2.1 Advantages of encapsulation........................................................................................ 6
2.2.2 Information hiding ...................................................................................................... 7
2.2.2.1 Example for information hiding. ............................................................................... 7
Part 3 ...................................................................................................................................... 9
3.1. The core module of the required software must perform creation and management of a single
container stack. Write the algorithm for this using the complex ADT you designed above using
java or C++ code. (Core function is adequate. Mention the language). ....................................... 9
Part 4 .................................................................................................................................... 11
4.1. Briefly explain in general terms how asymptotic analysis can help to measure the success of
algorithms like above in a practical scenario. .......................................................................... 11
4.1.2 Why perform an asymmetric analysis. ........................................................................ 11
4.2. Briefly explain with examples and illustrations on 2 methods to measure the efficiency of
algorithms. ............................................................................................................................ 13
4.2.1 Measure the efficiency of algorithms.......................................................................... 13
4.3. Considering the implemented ADT above, explain what a trade-off option for this would be.
An example is compulsory. .................................................................................................... 15
4.3.1 ADT and Trade-Off ................................................................................................... 15
4.4. Describe 3 advantages of using implementation independent Data Structure specifications.17
4.4.1 Some advantages of using implementation independent Data Structure specifications. . 17
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14

Partial preview of the text

Download HND in computing for software engineers and more Study notes Programming Paradigms in PDF only on Docsity!

Table Of Content

Table of Contents

Part 2 ...................................................................................................................................... 3 2.1. Write an imperative definition for the above-described ADT using the example of software stack. ...................................................................................................................................... 3 2.1 What is Abstract data types............................................................................................. 3 2.1.2 Stack ADT .................................................................................................................. 4 2.1.3 Software Stack ............................................................................................................ 5 2.1.3.1 Example for Stack ADT............................................................................................ 5 2.2. Explain in detail the advantages of encapsulation and information hiding when using an ADT. (Max 300 words)............................................................................................................ 6 2.2.1 Advantages of encapsulation........................................................................................ 6 2.2.2 Information hiding ...................................................................................................... 7 2.2.2.1 Example for information hiding. ............................................................................... 7 Part 3 ...................................................................................................................................... 9 3.1. The core module of the required software must perform creation and management of a single container stack. Write the algorithm for this using the complex ADT you designed above using java or C++ code. (Core function is adequate. Mention the language). ....................................... 9 Part 4 .................................................................................................................................... 11 4.1. Briefly explain in general terms how asymptotic analysis can help to measure the success of algorithms like above in a practical scenario. .......................................................................... 11 4.1.2 Why perform an asymmetric analysis. ........................................................................ 11 4.2. Briefly explain with examples and illustrations on 2 methods to measure the efficiency of algorithms. ............................................................................................................................ 13 4.2.1 Measure the efficiency of algorithms.......................................................................... 13 4.3. Considering the implemented ADT above, explain what a trade-off option for this would be. An example is compulsory. .................................................................................................... 15 4.3.1 ADT and Trade-Off ................................................................................................... 15 4.4. Describe 3 advantages of using implementation independent Data Structure specifications. 17 4.4.1 Some advantages of using implementation independent Data Structure specifications.. 17

2.1. 2 Stack ADT

The stack abstraction data type is we defined by the following structure and operations. A stack is structured as depicted above, as an arranged assortment of items where items are added to and removed from the end called the "top." Stacks are ordered LIFO. The stack operations we are given bottom. push() – Insert an element at one end of the stack called top. pop() – Remove and return the element at the top of the stack, if it is not empty. peek() – Return the element at the top of the stack without removing it, if the stack is not empty. size() – Return the number of elements in the stack. isEmpty() – Return true if the stack is empty, otherwise return false. isFull() – Return true if the stack is full, otherwise return false.

2.1.3 Software Stack

A computer software stack that has verified itself helpful or preferred for delivering a selected style of application could often be adopted by alternative developers. A computer software stack that has become in style could wrestle associate identity of its own as a growing range of software companies adopt an equivalent set of Softwares parts to deliver associate application. Softwares companies could bundle specific parts along and market them single stack for a specific purpose.

2.1.3.1 Example for Stack ADT

Shipment in a Cargo o Plates on a tray o Stack of Coins o Stack of Drawers o Shunting of Trains in Railway Yard o Follows the Last-In First Out (LIFO) strategy

2.2.2 Information hiding

Information hiding for programmers is executed to prevent system design change. If design decisions are hidden, certain program code cannot be modified or changed. Information hiding is usually done for internally changeable code, which is sometimes especially designed not to be exposed. Such stored and derived data is not expounded upon, most generally. Change resilience of classes and ease of use by client objects are two byproducts of hidden data. Information hiding for programmers is executed to prevent system design change. If design decisions are hidden, certain program code cannot be modified or changed. Information hiding is usually done for internally changeable code, which is sometimes especially designed not to be exposed. Such stored and derived data is not expounded upon, most generally. Change resilience of classes and ease of use by client objects are two byproducts of hidden data. One advantage of information hiding is yielding flexibility, such as allowing a programmer to more readily modify a program.

2.2.2.1 Example for information hiding.

Outside world cannot see hidden data and methods

2.3 “Imperative ADTs are viewed as a basis for object orientation”. Discuss this concept and provide justification whether you agree on this or not (Max. 300 words). An object is essentially defined by the names of the messages it receives the names of its methods in the Simula version and the values it encapsulates. The behavior of those methods is changeable; you don’t know what is actually going to be done in response to a message a method call, although it’s reasonable to expect a returned value of a given type in Simula-style OOP, that at least can be guaranteed. An abstract data type is defined by the values that it can operate on and the operations that can be performed on them. Inheritance is not part of the concept. Parametric polymorphism is required. Encapsulation is required but there is no concept of an object containing its own operations; the semantics of the operations are an essential part of the definition of an ADT and not alterable in Smalltalk and its descendants, you can model ADTs dynamically but there’s no way to define them. One type of operator which is often provided as part of an ADT is called a constructor. This constructor creates a new instance of the ADT. In object-oriented programming languages, the ADT is modelled using a class and the instance is called an object. A construction operator and a destructor operator which destroy the object is provided for each class and objects created in this paradigm is dynamically created and destroyed.

Part 4

4.1. Briefly explain in general terms how asymptotic analysis can help to

measure the success of algorithms like above in a practical scenario.

4.1.1 Asymptotic Analysis. An asymptotic analysis of the algorithm refers to the determination of the mathematical limit / performance criterion of the runtime. By using asymptotic analysis, we can infer the best case, the average case and the worst case in one algorithm. The asymptotic analysis is bound to the input that, in the absence of input to the algorithm, concludes that the operation is permanent. Other than "input", all other factors are considered constant. Asymptotic analysis refers to the calculation of the time taken for any activity in a mathematical computation unit. For example, the running time of an activity is calculated as f (n) and can give other operations, it is calculated as g (n 2). This means that the first elapsed time becomes linear with increasing n and the second operating time increases exponentially as n increases. Similarly, the running time of both operations will be very similar if n is very small.

4.1.2 Why perform an asymmetric analysis.

There are many important things to take care of, such as user-friendly, modular, security, maintenance, and more. Why worry about performance? The answer is very simple; we can have all of the above only when we have performance. So, performance is like the currency you can buy above. Another reason to study performance is, speed is fun. To summarize, performance is on a scale. Imagine a text editor can download 1000 pages but can spell a 1-page check per minute OR the image editor takes 1 hour to rotate your image 90 degrees left OR you get it. If the software feature can't accommodate the scale of tasks that a user has to perform - it's like dead. Given the two algorithms for the task, how do you know which one is better? An easy way to do this is - do both algorithms and run two programs on your computer for different inputs and see which ones take less time. There are many problems with this approach for analyzing algorithms.

  1. Probably for some inputs, the first algorithm works better than the second. And for a couple of second inputs, it's done better.
  2. It is also possible for some inputs, the first algorithm works better on one machine and the second works better for some other inputs.

4.2. Briefly explain with examples and illustrations on 2 methods to

measure the efficiency of algorithms.

4.2.1 Measure the efficiency of algorithms.

The efficiency of the algorithms can be estimated by deciding the quantity of source algorithms used. Components influencing calculation proficiency incorporate speed, timing and info size. The main sources utilized by the calculation are as per the following.

**1. Space complexity - The measure of memory utilized by the algorithm during execution.

  1. Time complexity - The time taken by the CPU for program execution.** To compute algorithm proficiency, clients can compose programs dependent on calculations or pseudo codes, execute and measure time. Time Complexity The complexity of time is the relation of the computation time and the amount of input.This is normally about the size of a array or an object. The complexity of time is additionally not helpful for straightforward capacities, for example, recovering a username from the database, combining a string or scrambling a secret key. It is utilized more to put together capacities, recursive estimations and things that frequently take more time to compute. The time intricacy of the calculation shows the measure of time it takes to run the program until it is finished. The time intricacy of the most widely recognized calculations is communicated utilizing Big O images. This is an asymptotic image to show the intricacy of time. We will concentrate exhaustively in the following instructional exercise. The intricacy of time is generally assessed by checking the quantity of fundamental stages a calculation takes to finish an execution. For instance, just to comprehend, we give two unique approaches to track down the squared numbers. An answer for this issue can be, run a loop for n times, beginning with n and adding n to it, each time. Can simply use a mathematical operator * to find the square. For the first code, the loop will run n times, so the intricacy of the time will be the most and as the worth of the increments will build the execution time will

also increase. Despite the fact that for the subsequent code, time intricacy is consistent, since it won't rely upon the worth of n, it will consistently deliver one stage. Also, on the grounds that algorithm execution can shift by different types of input data, so for algorithm, we regularly use time complexity in the most pessimistic scenario of the algorithm due to the Maximum time for any input size. Space Complexity. Space complexity is a simple way for experts to see the algorithmic footprint. For instance, engineers can add memory to store program instructions, memory for variable values and different kinds of central memory or help to acquire the aggregate sum of memory used by the program with the number of sources of input provides. It additionally assists experts with arranging asset necessities for activities. It also helps professionals to plan resource requirements for operations Space complexity S(P) of any algorithm P is, S(P) = C + SP (1) Where C is the fixed part and S(I) is the variable part of the algorithm which depends on instance characteristic I. Example: Algorithm: SUM (A, B) Step 1- START Step 2 C A + B + 10 Step 3 - Stop Here we have three variables A, B and C and one constant. Hence S(P) = 1+3. Now space depends on data types of given variables and constant types and it will be multiplied accordingly.

The above Fibonacci problem can be solved faster with DP. This will take O (n) time and house that could be a higher improvement in time and however we need to store the result of previous implementation instead of just asking them to follow request.

4.4. Describe 3 advantages of using implementation independent Data

Structure specifications.

4.4.1 Some advantages of using implementation independent Data Structure

specifications.

01 - Independent representation. Most programs become freelance of abstract data representation, so representation can be improved without breaking the entire program. 02 - Modularity With representative independence, totally different parts of the program become less dependent on other parts and on how other parts are implemented. 03 - Interchangeability of Parts. Different implementations of an abstract data type could have completely different performance characteristics. With abstract data types, its use data types varieties preparation can become easier for the precise a part of the program. For instances, Java's commonplace library provides variety of various ways in which of implementing its data type. Tree Map’s implementation may be a lot of economical once the entire range of orders on keys may be calculated quickly, however sensible hash values are difficult to calculate with efficiency. HashMap implementation may be a lot of economical once hash values may be computed quickly and while not specific order on keys. a part of the Map creation program will decide that deployment to use. The parts of the program associated with the program created Map don't have to be compelled to know how to deploy. once created, it is just a Map. If it's not for abstract data types, then every a part of the program that uses Maps must be written doubly, with a version to handle the deployment Tree Map and another version to handle the Hash Map deployments

Bibliography

Tutorialspoint.com. 2021. Data Structures & Algorithms - Quick Guide - Tutorialspoint. [online] Available at: https://www.tutorialspoint.com/data_structures_algorithms/dsa_quick_guide.htm [Accessed 6 August 2021]. Programiz.com. 2021. Java Program to Implement stack data structure. [online] Available at: https://www.programiz.com/java-programming/examples/stack-implementation [Accessed 6 August 2021]. GeeksforGeeks. 2021. Stack Data Structure - GeeksforGeeks. [online] Available at: https://www.geeksforgeeks.org/stack-data-structure/ [Accessed 6 August 2021].