vault backup: 2025-03-16 18:59:42

This commit is contained in:
boris
2025-03-16 18:59:42 +00:00
parent 6befcc90d4
commit ae837183f1
188 changed files with 17794 additions and 409 deletions

View File

@@ -5,6 +5,7 @@ This study guide provides an in-depth overview of the Abstract Data Type (ADT) L
## 1. Overview of Linear Lists
A linear list is a sequential collection of elements where each element can be accessed via an index. For instance, an instance of a linear list is represented as (e0, e1, e2, …, en-1), where:
- $e_i$ denotes the i-th element.
- $n$ is the finite size of the list, with n >= 0.
- $e_0$ is the first element and en-1 is the last.
@@ -54,6 +55,7 @@ Element[0], Element[1], Element[2], ...
### 5.1 Array-Based Implementation
The array-based implementation is straightforward:
- **Class Declaration**: Define a class for the ArrayLinearList.
- **Data Members**: Utilize a protected array (Object[]) for storing elements and a variable to track size.
- **Constructor Example**: Create constructors to initiate the list with a default or user-defined size.
@@ -68,6 +70,7 @@ A linked list version of the linear list provides dynamic memory allocation, whe
## 6. Method Implementations in ADT Linear List
Each method associated with the ADT Linear List is essential for its functionality:
- **isEmpty()**: Returns true if the size is 0.
- **size()**: Simply returns the count of elements.
- **get(int index)**: Requires validating the index with *checkIndex()* before accessing the array.

View File

@@ -11,13 +11,12 @@ A **data structure** is defined as an arrangement or organization of data in a c
An **abstract data type (ADT)** is a model that defines the high-level operations and characteristics of a data structure without delving into its implementation details. Before actually implementing a data structure, it is imperative to establish what operations the ADT should support. For instance, when creating a linked list ADT, one might specify operations such as:
- Inserting an item into the linked list.
- Deleting an item from the linked list.
- Searching for an item in the linked list.
- Checking if the linked list is empty.
This abstraction helps programmers focus on what functionalities the data structure must provide, rather than how those functionalities will be executed.
@@ -26,9 +25,8 @@ This abstraction helps programmers focus on what functionalities the data struct
Two significant programming principles are reviewed: **abstraction** and **modularization**. Abstraction allows programmers to handle complex systems by focusing on high-level functionalities rather than implementation specifics, while modularization aids in breaking down a problem into manageable components.
1. **Abstraction:** This concept helps in reducing complexity by allowing programmers to concentrate on essential aspects and ignore unnecessary details.
2. **Modularization:** By dividing problems into smaller sub-problems, programmers can tackle complex issues more efficiently.
**Encapsulation** works closely with these concepts by bundling data and methods that operate on that data into a single entity, such as a class in Java, thus hiding the internal state and requiring interaction only through specified methods.
@@ -37,21 +35,20 @@ Two significant programming principles are reviewed: **abstraction** and **modul
Several fundamental data structures form the backbone of programming:
- **Primitive Data Types:** These include Integers, Floats, Characters, and Booleans, which represent basic data values.
- **Composite Data Types:** These include essential data structures such as:
- **Arrays:** Collections of elements identified by indices, commonly used in mathematical contexts.
- **Linked Lists:** Data elements structured as nodes, each containing information and a link to the next node.
- **Stacks:** Last-in-First-out (LIFO) structures that allow insertion and deletion at one end, termed the top.
- **Queues:** First-in-First-out (FIFO) structures where insertion occurs at the rear and deletion at the front.
- **Trees:** Non-linear structures representing hierarchical relationships, ideal for organizing data hierarchically.
- **Graphs:** These consist of nodes and edges, representing pairwise relationships among elements.
## Concrete Implementations of ADTs
@@ -61,4 +58,4 @@ Within programming languages, data structures can act as concrete implementation
In software development, the foundation of a solution begins with the specification of a problem, followed by the formulation of an **algorithm**. An algorithm is a defined sequence of operations that transforms inputs into outputs, effectively addressing the problem. As programmers develop algorithms, they gain insights into which data structures may best suit their needs, leading to efficient solutions.
Ultimately, the understanding and application of data structures and ADTs are paramount in achieving effective software design and development, making them a cornerstone of efficient programming practices.
Ultimately, the understanding and application of data structures and ADTs are paramount in achieving effective software design and development, making them a cornerstone of efficient programming practices.

View File

@@ -1,27 +1,23 @@
## Advantages
- This has the advantage of making certain actions easier to perform but at the cost of increased maintenance of the code overall.
- Allows traversal of nodes in both direction which is not possible in singly linked list.
- Can allocate or de-allocate memory easily when required during its execution.
- It is one of most efficient data structure to implement when traversing in both direction is required.
## Disadvantages
## Disadvantages
- Using extra memory when compared to array and singly linked list.
- Slow in search as its elements are stored randomly in memory, hence elements are accessed sequentially (no direct access is allowed).
## ADT Liner list could be implemented by two ways:
## ADT Liner List Could Be Implemented by Two Ways:
- Array
- Used when you search is the highest priority
- Linked list
- Singly linked list
- Used when you addition/deletion is the highest priority
- Doubly linked list
- Used when you addition/deletion is the highest priority
- Navigate next and pervious
- Navigate next and previous

View File

@@ -28,37 +28,34 @@ For example, a constructor header like `public PrintWriter(String fileName) thro
At the core of Java's exception handling is the **Throwable** class, which serves as the superclass for all exceptions and errors. It has two key subclasses:
- **Error**: Indicates serious problems that a user application should not catch.
- **Exception**: Represents conditions that a user application might want to catch.
Within the Exception hierarchy, we find numerous subclasses such as **IOException** and **RuntimeException**, which themselves have numerous subclasses. For example:
- **IOException** can lead to specific exceptions like:
- **FileNotFoundException**
- **EOFException**
- **RuntimeException** encompasses:
- **ArithmeticException**
- **IndexOutOfBoundsException**
- **NullPointerException**
- **IllegalArgumentException**
## Dealing with Exceptions
Handling exceptions can be approached in two primary ways:
- **Catching the Exception**: This involves writing code to handle the exception immediately where it occurs. To achieve this, any potentially exception-generating code must reside within a **try** block, followed by one or more **catch** blocks that process the exception.
- **Propagating the Exception**: Alternatively, the method can propagate the exception, allowing higher levels of the program to handle it. This is done by throwing the exception again after catching it or not catching it at all.
### Catch Blocks Example
@@ -73,7 +70,7 @@ A fundamental aspect of handling exceptions is the use of a **try** and **catch*
> }
> ```
Here, _XXXException_ can be various types of exceptions, such as **IOException** or **RuntimeException**. When multiple types of exceptions can be thrown, several catch blocks can be utilized, ordered from the most specific to the most general. For instance:
Here, *XXXException* can be various types of exceptions, such as **IOException** or **RuntimeException**. When multiple types of exceptions can be thrown, several catch blocks can be utilized, ordered from the most specific to the most general. For instance:
> ```
> try {
@@ -127,4 +124,4 @@ In a sample application, if the main() method adds **throws IOException**, the m
## Final Thoughts on Exception Handling
Java's exception handling framework is robust and designed to enable developers to write code that can gracefully manage unexpected problems. This system incorporates custom exceptions using the **throw** keyword, enjoyable error messages, and fine-tuned control over program flow. The use of exception handling not only aids in maintaining the reliability of applications but also provides clearer diagnostic messages for debugging. Overall, proper understanding and implementation of Java exceptions are essential for writing resilient Java applications.
Java's exception handling framework is robust and designed to enable developers to write code that can gracefully manage unexpected problems. This system incorporates custom exceptions using the **throw** keyword, enjoyable error messages, and fine-tuned control over program flow. The use of exception handling not only aids in maintaining the reliability of applications but also provides clearer diagnostic messages for debugging. Overall, proper understanding and implementation of Java exceptions are essential for writing resilient Java applications.

View File

@@ -7,9 +7,8 @@ This study material provides a concise overview of the Abstract Data Type (ADT)
The Linear List can be implemented using different structures, including linked lists. The main focus here is on:
- Linear List based on LinkedList
- Doubly-linked list
Each of these implementations has its unique characteristics, advantages, and considerations.
@@ -18,13 +17,12 @@ Each of these implementations has its unique characteristics, advantages, and co
Understanding the size of primitive types is fundamental in memory allocation:
- **boolean & byte** - 1 byte
- **char & short** - 2 bytes
- **int & float** - 4 bytes
- **long & double** - 8 bytes
It's important to note that, in modern 64-bit Java Virtual Machines (JVM), the minimum size of an object is 16 bytes due to the header size and padding requirements.
@@ -33,9 +31,8 @@ It's important to note that, in modern 64-bit Java Virtual Machines (JVM), the m
When comparing Array Lists and Linked Lists:
- **Addition and Removal**: Linked Lists excel in scenarios where frequent addition and removal of elements are required due to their dynamic size and absence of resizing overhead.
- **Memory Overhead**: Linked Lists consume more memory because each node contains a reference to both the next and, in doubly-linked lists, the previous node, which increases complexity and size.
## Memory Allocation Concepts
@@ -52,48 +49,43 @@ A linked list is a collection of nodes where each node contains data and a refer
Some common operations performed on linked lists include:
- **Insertion**: Nodes may be inserted at the beginning, middle, or end of the list, requiring adjustments of pointers accordingly.
- **Removal**: Similar to insertion, removal requires accessing the right node and adjusting pointers to maintain list integrity.
### Algorithm Visualizations
Visual representations can help understand operations such as inserting or deleting nodes. For example, to insert a node in a linked list, one must:
1. Create the new node.
2. Adjust the pointers of the surrounding nodes to include the new node.
## Doubly-Linked Lists
Doubly-linked lists add an extra pointer, allowing traversal in both forward and backward directions, enhancing flexibility:
- **Advantages**: They can traverse in both directions and manage dynamic memory more efficiently.
- **Disadvantages**: They require more memory for pointers and tend to have slower access times due to their random memory allocation.
### Inserting and Deleting in Doubly-Linked Lists
The process of inserting or deleting nodes involves managing the **prev** and **next** pointers to maintain the structure of the list. As illustrated:
1. For insertion, properly link the new node with its neighbors.
2. For deletion, ensure that surrounding nodes bypass the removed node, effectively maintaining list integrity.
## Key Takeaways
In conclusion, choosing between an array and a linked list largely depends on the intended operations:
- **Arrays** are optimal for scenarios where quick search operations are prioritized.
- **Linked Lists** are preferred for scenarios where insertion and deletion operations are frequent, with variations including:
- **Singly Linked List**: Best suited for simple sequential access and minimal memory overhead.
- **Doubly Linked List**: Ideal when navigating both forwards and backwards is necessary.
Understanding these structures and their operations is essential for effective programming and data management.
- **Linked Lists** are preferred for scenarios where insertion and deletion operations are frequent, with variations including:
- **Singly Linked List**: Best suited for simple sequential access and minimal memory overhead.
- **Doubly Linked List**: Ideal when navigating both forwards and backwards is necessary.
Understanding these structures and their operations is essential for effective programming and data management.

View File

@@ -1,4 +1,5 @@
## What is an interface?
## What is an Interface?
- An interface is a device or a system that unrelated entities use to interact.
- A remote control is an interface between you and a television set.
@@ -6,10 +7,7 @@ basically the interface has and abstract method which classes have to implement
Concert realisation of the otherwise abstract method.
## What is a linked list?
## What is a Linked List?
- On the linked list every node is an object.
- Has more memory overhead than an ArrayList.
@@ -17,6 +15,6 @@ Concert realisation of the otherwise abstract method.
- It mainly allows efficient *insertion* and *deletion* operations compared to arrays
- Its dynamic, the size of it changes with every change.
# Protected
prevents the method to be used by anyone but its sub classes.
# Protected
prevents the method to be used by anyone but its sub classes.

View File

@@ -7,41 +7,38 @@ A queue is an important abstract data type (ADT) characterised by its FIFO (Firs
## Key Concepts of Queues
- **Structure:** A queue consists of two primary ends:
- _Front:_ The position from which elements are removed.
- _Rear:_ The position where elements are added.
- *Front:* The position from which elements are removed.
- *Rear:* The position where elements are added.
- **Core Operations:** The basic operations associated with a queue are:
- **isEmpty():** Checks if the queue is empty.
- **peek():** Returns the front element without removing it.
- **put(x):** Adds an element x at the rear of the queue.
- **remove():** Removes and returns the front element.
## Queue Applications
Queues have various applications due to their structure, such as:
- CPU and disk scheduling, where resources are shared among multiple consumers.
- Buffering in asynchronous data transfers like I/O operations, where data may not be received at the same rate as it is sent.
- Handling jobs in a network printer which generally follows a FIFO order.
## Queue Representation
Queues can be implemented in two ways:
- **Linear Array Queue:** Uses a one-dimensional array along with pointers for front and rear.
- **Circular Array Queue:** Employs a circular structure to efficiently utilize array space, preventing the needs of shifting elements when the array is full.
## Linear Queue Representation
@@ -56,20 +53,18 @@ Queue: A B C D (front = 1, rear = 4)
A circular queue, uses the following logic:
- Front points 'anti-clockwise' from the first element while rear points to the last inserted element.
- Utilizes the modulo operator to wrap around the indices as elements are added or removed.
## Implementation of a Circular Queue
The implementation comprises several stages:
1. **Initialization:** Set front and rear to 0.
2. **Insertion:** Update the rear index with a modulo operation. For example, rear=(rear+1)\%queue.length.
3. **Removal:** Increment the front index to remove an element.
## Challenges with Circular Queues
@@ -77,26 +72,25 @@ One of the critical issues with circular queues is distinguishing between a full
## Queue Implementation Using Array
The _ArrayQueue_ class illustrates array-based implementation:
The *ArrayQueue* class illustrates array-based implementation:
``` java
public class ArrayQueue implements Queue { ... }
```
This class defines data members like _front_ and _rear_, along with methods for manipulating the queue.
This class defines data members like *front* and *rear*, along with methods for manipulating the queue.
## Queue Methods Overview
Here are key methods defined in the Queue interface:
1. **isEmpty():** Returns true if the queue is empty.
2. **peek():** Returns the front element or null if the queue is empty.
3. **put(Object theObject):** Adds an element to the queue and may increase array length if the queue is full.
4. **remove():** Removes the front element and updates the front pointer to the next element.
## Queue Implementation Using Linked List
@@ -111,10 +105,9 @@ This structure provides constant time complexity for insertions and deletions, o
## Summarizing Queue Operations
- **Adding Elements:** In a linked implementation, a new node is created and linked appropriately.
- **Removing Elements:** The front element is removed and the front pointer is updated.
## Conclusion
Queues are fundamental data structures in computer science with a range of applications spanning from scheduling tasks to implementing buffers. Their efficient management of elements through well-defined operations supports numerous algorithms and data handling strategies in programming.
Queues are fundamental data structures in computer science with a range of applications spanning from scheduling tasks to implementing buffers. Their efficient management of elements through well-defined operations supports numerous algorithms and data handling strategies in programming.

View File

@@ -7,4 +7,4 @@
| The SLL occupies less memory than DLL as it has only 2 fields. | The DLL occupies more memory than SLL as it has 3 fields. |
| Complexity of deletion with a given node is O(n), because the previous node needs to be known, and traversal takes O(n) | Complexity of deletion with a given node is O(1) because the previous node can be accessed easily |
| A singly linked list consumes less memory as compared to the doubly linked list. | The doubly linked list consumes more memory as compared to the singly linked list. |
| Singly linked list is relatively less used in practice due to limited number of operations | Doubly linked list is implemented more in libraries due to wider number of operations. For example [Java LinkedList](https://www.geeksforgeeks.org/linked-list-in-java/) implements Doubly Linked List. |
| Singly linked list is relatively less used in practice due to limited number of operations | Doubly linked list is implemented more in libraries due to wider number of operations. For example [Java LinkedList](https://www.geeksforgeeks.org/linked-list-in-java/) implements Doubly Linked List. |

View File

@@ -1,35 +1,30 @@
# Overview
- A stack is ta LIFO list. Meaning "last in first out"
- Access is allowed only from one end of the stack
- adding an item is called pulsing the stack
- retrieving an item is called popping the stack
- Access is allowed only from one end of the stack
- adding an item is called pulsing the stack
- retrieving an item is called popping the stack
# Typical uses
# Typical Uses
- Parentheses matching; ()), or (())
- Parentheses matching; ()), or (())
- compiler's syntax check for matching braces is implemented by using stack
- The simplest application of a stack is to reverse a word.
- You push a given word to stack - letter by letter - and then pop letters from the stack.
- Another application is an "undo" mechanism in text editors;
-this operation is accomplished by keeping all text changes in a stack
- The simplest application of a stack is to reverse a word.
• You push a given word to stack - letter by letter - and then pop letters from the stack.
# Parenthesis Count
- Another application is an "undo" mechanism in text editors;
•this operation is accomplished by keeping all text changes in a stack
- Methodology (logical steps to solve the problem):
- scan expression from left to right;
- when a left parenthesis is encountered, add its position to the stack;
- when a right parenthesis is encountered, remove matching position from stack (more example in a moment).
# Parenthesis count
# Try-catch-throw
- Methodology (logical steps to solve the problem):
- scan expression from left to right;
- when a left parenthesis is encountered, add its position to the stack;
- when a right parenthesis is encountered, remove matching position from stack (more example in a moment).
# try-catch-throw
- When you enter a try block, push the address of this block onto a stack.
- When you enter a try block, push the address of this block onto a stack.
\
- When an exception is thrown, pop the try block that is at the top of the stack; if the stack is empty, terminate the program.
- If the popped try block has no matching catch block, go back to the previous step.
- When an exception is thrown, pop the try block that is at the top of the stack; if the stack is empty, terminate the program.
- If the popped try block has no matching catch block, go back to the previous step.
- If the popped try block has a matching catch block, execute the matching catch block.

View File

@@ -9,29 +9,17 @@ Linear lists, which include arrays and linked lists, are ideal for serially orde
### Examples of Hierarchical Data in Trees
- Corporate Structure:
- In a company, positions such as president, vice presidents, managers, etc., can be represented in a tree format.
- Object-Oriented Programming:
- In Java, classes form a hierarchy where the Object class is at the top, followed by subclasses.
## Tree Terminologies
Understanding tree terminologies is crucial for grasping more complex operations and implementations.
- **Depth:** The number of edges from the root node to a specific node. For example, if node G is three levels down from the root, its depth is 3.
- **Height:** The height of a tree is defined as the number of levels it possesses. A tree's maximum depth helps determine its overall height.
- **Degree of a Node:** This refers to the number of child nodes a specific node has. A tree where each node has a maximum of two children is termed a **binary tree**.
### Binary Trees
@@ -42,13 +30,8 @@ A binary tree is defined such that each node has at most two children, known tra
When analyzing binary trees, certain properties can be established:
- A binary tree of height h must have at least h nodes.
- In a full binary tree, each node has either two children or none. It contains the maximum number of nodes defined as 2^h - 1.
- The number of nodes and tree height relationship is succinctly expressed with the inequalities: h \leq n \leq 2^h -1.
## Binary Operations and Traversals
@@ -59,47 +42,31 @@ Performing operations on binary trees is essential to manage and manipulate data
Traversal techniques allow for processing each node in a specified order:
- **Pre-order Traversal:** Process the root, then traverse the left subtree, followed by the right subtree.
- **In-order Traversal:** Visit the left subtree first, then process the root, followed by the right subtree.
- **Post-order Traversal:** Traverse the left subtree, right subtree, and then process the root.
- **Level-order Traversal:** Process nodes level by level from the root down to the leaves.
### Arithmetic Expressions as Trees
Binary trees are particularly useful for representing arithmetic expressions. An _expression tree_ is structured such that:
Binary trees are particularly useful for representing arithmetic expressions. An *expression tree* is structured such that:
- Leaves represent operands.
- Non-leaf nodes denote operators.
- Subtrees represent sub-expressions.
## Conversion Between Expression Formats
Moving between infix, prefix, and postfix expressions requires constructing expression trees first.
1. Infix expression (a + b) can be converted to a postfix expression (a b +) by building the corresponding expression tree and performing a post-order traversal.
## Constructing Binary Trees from Traversals
Creating a binary tree from given traversals (like in-order and pre-order) involves recognizing patterns in the data:
- From in-order and pre-order traversals, one identifies the root and splits left and right subtrees accordingly.
- The process can illustrate various scenarios and result in multiple valid trees for the same traversal combinations.
## Conclusion
Tree data structures are indispensable in computer science, providing efficient methods for data organization, retrieval, and management. Understanding their properties and operations enables clearer problem-solving strategies and effective programming techniques.
Tree data structures are indispensable in computer science, providing efficient methods for data organization, retrieval, and management. Understanding their properties and operations enables clearer problem-solving strategies and effective programming techniques.