Download Abstract Data Types and Software Stacks in Computer Science and more Study Guides, Projects, Research Computer Science in PDF only on Docsity!
ASSIGNMENT 1 FRONT SHEET
Qualification BTEC Level 5 HND Diploma in Computing Unit number and title Unit 19 : Data Structures and Algorithms Submission date Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Student ID Class Assessor name Student declaration I certify that the assignment submission is entirely my own work and I fully understand the consequences of plagiarism. I understand that making a false declaration is a form of malpractice. Student’s signature Grading grid P1 P2 P3 M1 M2 M3 D1 D
Summative Feedback: Resubmission Feedback:
Grade: Assessor Signature: Date: Internal Verifier’s Comments: IV Signature:
Figure 12: Software stack ...................................................................................................................................... 14
I. CREATE A DESIGN SPECIFICATION FOR DATA
STRUCTURES EXPLAINING THE VALID OPERATIONS
THAT CAN BE CARRIED OUT ON THE STRUCTURES (P1):
1. Data Structures:
In the field of computer science, an Abstract Data Type (ADT) is a category of data structure that derives its definition from how it functions, rather than the specific way it is constructed. It provides a mechanism for bundling both the data and the operations that can be executed on that data.
2. Type of Data:
List, stack, and queue stand out as a handful of typical ADTs, demonstrating their value across an extensive spectrum of practical uses.
2.1 List:
- Within the realm of Abstract Data Types, the concept of a list comprises interconnected elements following a linear sequence. This linear structure indicates that each variable in the list, except the initial one, possesses a unique successor. Additionally, lists inherently possess a property known as size, denoting the count of elements they contain.
- Manipulation of this list is feasible through an abstraction called List, whereby other classes handle the specific data structure details. Among these supporting classes are LinkedList, employing the construction of linked nodes, and ArrayList, utilizing array-based implementation.
- The following functions are associated with the List ADT: get() – Retrieves an element from any specified position within the list. insert() – Adds an element at a designated location within the list. remove() – Eliminates the first occurrence of an element in a non-empty list. removeAt() – Deletes the element situated at a given position within a non-empty list. replace() – Substitutes an element at any position with another element. size() – Provides the quantity of elements in the list. isEmpty() – Indicates whether the list is devoid of elements (returns true) or not (returns false). isFull() – Determines if the list has reached its capacity (returns true) or not (returns false).
a. Example:
Illustration: Linked List:
- A linked list, a widely used data structure, comprises a sequence of nodes. Each node possesses both a value and a pointer indicating the subsequent node in the sequence. The terminal node points to null, and the head pointer is directed to the initial node. When the list is devoid of elements, the head pointer is null. Figure 1 : Linked List
- Four variations of linked lists are prevalent: Singly linked lists: In this variation, each node contains a reference to the subsequent node in the sequence. These linked lists provide a straightforward structure suitable for various applications. Figure 2 : Singly linked lists. Doubly linked lists: These linked lists extend the concept of singly linked lists by incorporating an additional pointer within each node. This extra pointer establishes a connection with the preceding node, enabling navigation in both forward and backward directions. Figure 3 : Doubly linked lists Circular linked lists: Circular linked lists form a closed loop, where the terminal node's pointer is directed back to the initial node. This configuration allows for continuous cycling through the list, often proving useful in scenarios where looping behavior is required. Figure 4 : Circular linked lists
Database Management Systems: Linked lists are employed to store collections of records in database management systems. They facilitate the structured storage and retrieval of data, forming a core component of data organization. Network Routing Algorithms: Linked lists serve as containers for storing routing information in network algorithms like Dijkstra's algorithm. They assist in determining optimal paths for data transmission within complex network topologies. Graph Algorithms: Linked lists are pivotal in graph theory and algorithms, housing essential information for operations like depth-first search and breadth-first search. They provide a flexible framework for representing graph structures. Diverse Applications: Linked lists extend their utility to various domains, including managing the undo/redo stack in text editors and web browsers. They enable efficient tracking of changes in version control systems, aiding collaborative software development. Moreover, they find usage in representing polynomials within computer algebra systems, contributing to mathematical computations.
- In essence, linked lists prove to be versatile tools in computer science, fostering efficient data organization, manipulation, and optimization across an array of applications.
2.2 Stack:
- A stack represents an abstract data type defined by a predetermined limit. It stands as a foundational data structure designed to facilitate the orderly addition and removal of elements based on specific requests. In this structure, newly added elements consistently ascend to the top, reminiscent of stacking objects on top of each other, where the uppermost element holds significance as the primary candidate for removal.
- Elements of identical nature are sequentially arranged within the stack. All interactions occur at a single extremity, known as the "top" of the stack. The following essential operations define its behavior: push(): This operation involves inserting an element onto the stack's topmost end. pop(): The "pop" operation entails extracting and returning the element positioned at the top of the stack, contingent upon the stack not being empty. peek(): In the "peek" operation, the element situated at the stack's top is returned without removal, assuming the stack isn't empty. size(): This operation provides the count of elements contained within the stack. isEmpty(): By invoking the "isEmpty" operation, a determination is made whether the stack holds no elements (returning true) or has elements (returning false). isFull(): The "isFull" operation assesses whether the stack has reached its defined capacity (returning true) or remains capable of accepting more elements (returning false).
- In summary, a stack exemplifies a bounded abstract data type offering a streamlined approach to element management. Its core characteristics of orderly insertion, removal, and access at the top position make it an essential tool in various computing contexts.
a. Example:
Figure 6 : Illustration for push a element onto stack and after push Figure 7 : Illustration for pop operation the topmost element and stack after pop
b. Application:
- Function Call Management: Stacks play a pivotal role in managing information related to dynamic functions or subroutines. When functions are called within a program, their respective details are stored on the stack, allowing for organized and efficient execution.
- String Reversal: Stacks offer a straightforward mechanism for reversing strings. Each character of the string is individually pushed onto the stack, and then retrieved in reverse order, resulting in the reversal of the original string. This process demonstrates the versatile nature of stacks in handling various data manipulation tasks.
2.3 Queue:
- A queue represents a fundamental abstract data type (ADT) employed for the organized storage and retrieval of data elements following a specific order. In essence, a queue operates on the principle of "first-in, first-out" (FIFO), ensuring that the element added earliest is the one to be
Figure 9 : Dequeue
b. Application:
- Queues find practical utility across diverse scenarios, showcasing their versatility in managing various tasks and processes: Resource Allocation: Queues serve as a robust tool for managing requests on a shared resource, a prime example being CPU scheduling and disk scheduling. By orderly handling incoming requests, queues contribute to effective resource utilization and fair allocation. Interrupt Handling: In the realm of hardware or real-time systems, queues play a pivotal role in managing interrupts. They facilitate the organized handling of interrupts, allowing critical tasks to be processed without disruption. Website Traffic: The dynamic nature of website traffic management benefits from the queue structure. Queues aid in orderly processing of incoming user requests, ensuring responsive and efficient interactions with web services. Networking Infrastructure: Routers and switches in networking systems leverage queues for seamless data transmission. By adhering to the FIFO principle, queues contribute to optimized data routing and delivery within network architectures. Media Players Playlist: Queues are employed in media players to maintain playlists. This ensures a structured sequence of media playback, enhancing the user experience by adhering to the desired order of content presentation.
- In essence, queues showcase their significance in managing tasks, requests, and data flows across a spectrum of applications. Their orderly and systematic approach contributes to efficient resource utilization, responsive system behavior, and enhanced user experiences.
II. DETERMINE THE OPERATIONS OF A MEMORY STACK
AND HOW IT IS USED TO IMPLEMENT FUNCTION CALLS
IN A COMPUTER (P2):
1. Memory Stack:
- A crucial data structure, the memory stack, assumes responsibility for the allocation and regulation of a program's memory resources. Operating on the principle of Last In First Out (LIFO), the memory stack operates such that the most recently added item is the first to be removed.
- When a program is initiated, a dedicated segment of memory, aptly named the stack, is established. This stack serves as a repository for the program's vital components, including data, function parameters, and return addresses. Each time a function is invoked, the system meticulously records the function's parameters and return address on the stack. It's important to note that the stack size remains fixed and predetermined.
- As functions execute, their parameters and return addresses are methodically maintained on the stack. Upon the conclusion of a function's execution, the associated data is purged from the stack, and control is seamlessly restored to the original application.
- In essence, the memory stack functions as a cornerstone of memory management, orchestrating the organization and retrieval of essential program elements in a structured and controlled manner. Figure 10 : Memory Stack
1.1 How the memory is organized:
- The stack, a vital component of memory management, orchestrates the arrangement of data in a Last-In-First-Out (LIFO) manner. This distinctive pattern ensures that the most recently inserted item into the stack is the first to be extracted.
- In the realm of memory management, the stack serves as a powerful tool for regulating memory allocation. When a program is in execution, the memory management system allocates a portion of
- Operations: Push Operation: The fundamental purpose of the push operation is to insert data objects onto the stack. A relatable analogy is that of a restaurant plate dispenser. In this analogy, the push action corresponds to replenishing the plate dispenser with plates, akin to how data items are added to a stack. As with plates, the first to be pushed is positioned at the bottom, and successive additions follow suit. The newest data is placed on top, mirroring the LIFO principle where the last addition takes precedence. Pop Operation: The pop operation involves removing data elements from the top of a populated stack. Drawing inspiration from the plate dispenser example, the most recently added plate (data item) occupies the top position. Following the LIFO pattern, this top item is the first to be removed, mimicking the action of taking the uppermost plate from the stack. This removal creates a cascade effect, with subsequent items shifting downward, aligning with the LIFO principle. Peek Operation: The peek operation, distinct from push and pop, solely involves querying the topmost data item within the stack. This action doesn't alter the stack's contents; it merely retrieves the most recent addition, adhering to the LIFO sequence. Search Operation: Similarly, the search operation operates without introducing or removing data items. It involves identifying the location of a specific data item within the stack based on its address. This operation establishes the relative placement of the desired item concerning the topmost element, underscoring the LIFO concept.
- In essence, the LIFO principle finds its embodiment in the memory stack, where the orderly arrangement and management of data elements adhere to a Last-In, First-Out structure. This synergy between LIFO and the memory stack yields efficient data handling and retrieval mechanisms in various computing applications. 2. Function call in memory stack:
- Function calls, a cornerstone of memory management, intertwine with the memory stack to orchestrate the dynamic execution of programs. This symbiotic relationship is crucial in managing program flow and resource allocation. Stack-Based Storage of Function Calls: The memory stack serves as an integral mechanism for storing and managing function calls during program execution. Each time a method or function is invoked, a new entry, known as an activation record or stack frame, is appended to the stack. This activation record encapsulates vital details, including the originating instruction's location, the received arguments, and a return address guiding the program back to the calling point upon completion. Method Invocation and Stack Manipulation: As the program advances, the stack grows with each method invocation. When a function concludes its execution and returns, the topmost entry is systematically removed. This process signifies the completion of the function's task, and control reverts to the calling instruction, guided by the stored return address. This orchestration guarantees a structured execution flow and enables smooth transitions between functions. Termination and Stack Unwinding: The interplay between function calls and the stack continues until the program ultimately navigates back to the main function, which initiated the program's execution. Upon this return, the stack undergoes a comprehensive unwinding process, systematically eliminating each activation record. This unwinding symbolizes the culmination of the program's runtime, ensuring efficient resource management and proper deallocation of memory.
- For example, consider the program's initiation with the main() function. This triggers the creation of an activation record at the stack's summit. Subsequent function calls, such as invoking foo() and bar(), sequentially add their respective activation records atop the stack. Upon these functions' completion, their activation records are methodically removed, reflecting the LIFO (Last-In, First-Out) nature of the stack.
- This intricate interplay between function calls and the memory stack epitomizes an essential aspect of program execution. The stack, acting as a dynamic repository, guides the program's course, manages resources, and ensures methodical memory allocation and deallocation. Such orchestrated interactions facilitate the smooth progression and culmination of program tasks.
III. USING AN IMPERATIVE DEFINITION, SPECIFY THE
ABSTRACT DATA TYPE FOR A SOFTWARE STACK (P3):
1. Software stack:
- The operation of an application relies on a composition of self-contained software components
collaborating in what is known as a software stack. These components are organized in a structured hierarchy, encompassing a range of elements such as the operating system, architectural layers, protocols, runtime environments, databases, and function calls. This arrangement facilitates a harmonious interplay between different levels of functionality and expertise. Figure 12 : Software stack
- Hierarchical Structure: The software stack assumes a layered structure, with each tier serving a distinct purpose while seamlessly interacting with adjacent layers. This stratified organization allows for a methodical approach to software design and development.
- Diverse Roles and Interfaces: The individual components within the stack play diverse roles. At the higher echelons, upper-level components specialize in catering to specific functions, providing tailored services directly to end users. Conversely, lower-level counterparts often engage in
challenges such as unfamiliarity, customization constraints, vendor dependence, and security vulnerabilities. Successful adoption requires a careful evaluation of the trade-offs and a thoughtful consideration of the specific needs and goals of the development project.
3. The Abstract Data Type for a Software Stack:
- The abstract data type (ADT) known as a "software stack" represents a cohesive assembly of software components aimed at facilitating the creation, deployment, and management of diverse programs. Within this ADT, various standard elements converge, fostering an environment conducive to streamlined development and efficient application operation.
- At its core, the "software stack" ADT encompasses a collection of integral software constituents that collectively empower the lifecycle of applications. These components include an operating system, a web server, a database management system, a scripting language, and a web framework. Additionally, the stack may encompass an array of supplementary libraries and tools, each contributing to the holistic functioning of the software ecosystem.
- The "software stack" ADT enables a synergistic interplay among its constituent parts, enabling developers to conceive, deploy, and maintain applications seamlessly. For instance, a typical software stack might encompass a Linux distribution, a Windows Server installation, or a cloud computing platform. These integrated packages exemplify how the elements within the software stack are thoughtfully harmonized, underscoring the efficiency and convenience offered by this abstract data type.
- In the realm of contemporary software development, the "software stack" ADT plays a pivotal role. It serves as a standardized toolkit, expediting the process of designing and delivering applications with reliability and precision. This ADT empowers developers to swiftly adapt their applications to diverse settings, catering to specific requirements with ease. By encapsulating a cohesive array of components, the "software stack" ADT exemplifies the essence of modern software development, promoting agility, consistency, and accelerated innovation. 4. Examples of Software Stacks:
- Software stacks come in various forms, each tailored to specific needs and objectives. Here are a few notable examples that illustrate the versatility and utility of these stacks in diverse domains: LAMP (Linux, Apache, MySQL, and PHP): Primarily employed in web development, the LAMP stack constitutes a foundational framework. Anchored by the Linux operating system, it seamlessly interacts with the Apache web server. The components of this stack have organically found synergy, even though not originally designed as an integrated package. MySQL serves as the database layer, while PHP caters to dynamic scripting. This stack has become ubiquitous across Linux distributions. Variants like LAPP (substituting PostgreSQL for MySQL) and LEAP (Linux, Eucalyptus, AppScale, Python) further exemplify its adaptability. MEAN (MongoDB, Express, Angular, Node.js): Overcoming language barriers, the MEAN stack is a beacon in software development. MongoDB, a NoSQL document datastore, forms its core. Express operates as the HTTP server, Angular serves as the JavaScript front-end framework, and Node.js drives the server-side scripting. A distinguishing feature of MEAN is its use of JavaScript throughout, granting developers exceptional flexibility across operating systems. Evolving
versions like MEEN (Ember instead of Angular) and MEVN (Vue.js for front-end development) showcase the stack's adaptability to varied toolsets. Apache CloudStack: Catering to both enterprises and service providers, Apache CloudStack stands as an open-source IaaS (Infrastructure as a Service) cloud management stack. This comprehensive stack facilitates the provisioning of cloud-based infrastructure. Supporting a multitude of application program interfaces (APIs) and hypervisors, CloudStack accommodates a range of requirements. Beyond core functionality, the stack offers tiers of supplementary services, enriching the developer experience and enhancing the potential for innovation.
- These examples vividly demonstrate the spectrum of software stacks' capabilities, from empowering web development with LAMP, transcending language boundaries with MEAN, to facilitating cloud infrastructure management with Apache CloudStack. Software stacks exemplify the art of harmonizing distinct software components to achieve comprehensive, efficient, and purpose-driven solutions in modern software development.
IV. REFERENCES:
- SearchDataManagement.2021. What are Data Structures? - Definition from WhatIs.com. [online] Available at: https://www.techtarget.com/searchdatamanagement/definition/data- structure.[Accessed 24 February 2023]
- Javapoint.2020. Doubly Linked List - javatpoint. [online] Available at: https://www.javatpoint.com/doubly-linked-list. [Accessed 24 February 2023]
- Javapoint.2020. Abstract data type in data structure - javatpoint. [online] Availableat: https://www.javatpoint.com/abstract-data-type-in-data-structure. [Accessed 24 February 2023]
- GeeksforGeeks.2014. Circular Linked List | Set 1 (Introduction and Applications). [online] Available at: https://www.geeksforgeeks.org/circular-linked-list/. [Accessed 24 February 2023]
- Javapoint.2020. DS Stack - javatpoint. [online] Available at: https://www.javatpoint.com/data-structure-stack. [Accessed 26 February 2023]
- GeeksforGeeks.2018. LIFO (Last-In-First-Out) approach in Programming. [online] Available at: https://www.geeksforgeeks.org/lifo-last-in-first-out-approach-in- programming/. [Accessed 26 February 2023]
- Smith, T.2022. Last In, First Out - LIFO. [online] Investopedia. Available at: https://www.investopedia.com/terms/l/lifo.asp. [Accessed 24 February 2023]
- afteracademy.2020. Stack and its basic Operations. [online] Available at: https://afteracademy.com/blog/stack-and-its-basic-operations/. [Accessed 26 February 2023]