Data Flow Diagrams and Structured Analysis
When constructing data flow diagrams (DFDs), several key principles must be followed:
- Each process requires both input and output data flows. Data flows can only connect to processes—either from a source to a process, or from a process to a sink.
- All data flows and data stores must have definitions in the data dictionary, which documents all elements within each level of the DFD.
- The lowest-level processes must include detailed descriptions of their operations.
- Parent and child diagrams must maintain balance. That is, the inputs and outputs of a process in a parent diagram should match exactly with those in its decomposed child diagram. This consistency does not require identical names or counts but must ensure matching definitions in the data dictionary.
- Process descriptions must align with the data elements involved in the process. Input data flows must specify how they are used; output data flows must describe generation or selection criteria; data stores must indicate usage or modification methods.
- A single diagram should contain no more than seven ± two graphical elements.
Entity-Relationship Model to Relational Schema Conversion
Converting Entities to Relations
Each entity in an E-R diagram maps to a relation schema where the entity name becomes the schema name, attributes become columns, and the primary key identifies the tuple.
Handling Relationships
There are three types of relationships: one-to-one (1:1), one-to-many (1:N), and many-to-many (M:N).
One-to-One Relationship
Option 1: Create a separate relation for the relationship, including both entity keys and relationship attributes, with one of the entity keys serving as the primary key.
Option 2: Merge the relationship into one of the entities by adding the other entity's key and relationship attributes to that entity’s attribute set, keeping the original key intact.
One-to-Many Relationship
Option 1: Define a new relation for the relationship, including both entity keys and relationship attributes, using the many-side entity key as the primary key.
Option 2: Attach the relationship to the many-side entity by incorporating the one-side entity key and relationship attributes into the many-side entity's attribute set, preserving its key.
Many-to-Many Relationship
Always create a distinct relation for the relationship, including both entity keys and relationship attributes. The primary key consists of the combined keys from both entities.
Object-Oriented Analysis and Design
Core Phases
- Functional Modeling: Begin by identifying use cases and building a use case diagram. This involves defining actors, specifying requirements, modeling interactions, and documenting use case descriptions.
- Domain Modeling: Define the core concepts and their relationships within the problem domain.
- Behavioral Modeling: Capture interaction sequences through activity diagrams or state machines.
- Design Class Diagram: Represent classes, interfaces, and relationships between them.
Case Study Example
A typical example would involve analyzing a banking system to model customer accounts, transactions, and account holders using UML tools.
C Language Algorithms and Pointers
Pointer Fundamentals
In C, every variable has a memory address. A pointer variable stores the address of another variable, allowing indirect access to its value. Nested pointers are also suppported.
Array Access via Pointers
One-Dimensional Arrays
A pointer to an array element can be declared as follows:
int arr[10];
int *ptr = &arr[0]; // Equivalent to int *ptr = arr;
Accessing elements: *(ptr + i) refers to arr[i].
Two-Dimensional Arrays
To define a pointer to a row of a 2D array:
int (*ptr)[4]; // Points to an array of 4 integers
Function Interaction
Functions may accept or return pointers:
- Pass address of a variable to modify it in the function.
- Return pointer to dynamically allocated memory or to a static variable.
- Use function pointers to call functions indirectly:
int (*func_ptr)(int, int); // Declares a function pointer
Data Structures Using Pointers
Singly Linked List
Implementation involves creating nodes with data fields and next pointers.
Binary and Multi-way Trees
Trees are represented using node structures containing references to child nodes.
Java Object-Oriented Programming
Interfaces
An interface defines a contract specifying what methods must exist without implementation. Classes implement interfaces using the implements keyword.
interface MyInterface {
void method();
}
class MyClass implements MyInterface {
public void method() { /* implementation */ }
}
Inheritance
Inheritance allows extending existing classes using the extends keyword.
class Parent {
// parent members
}
class Child extends Parent {
// inherits parent members
}
Use super to invoke parent constructors or methods, and this to refer to current instance members.
Class Structure
- Constructors: Default and parameterized versions.
- Getters and setters: Encapsulate access to private fields.
- Access modifiers:
private,public,protected, and package-private (default). - Abstract classes: Can contain abstract methods and concrete implementations.
Object Instantiation
MyClass obj = new MyClass(parameters);
Parent parentRef = new Child(parameters);
Interface List Usage
Common operations on lists include:
- Adding elements at the end:
list.add(element) - Inserting elements at a specific index:
list.addAll(index, collection) - Clearing the list:
list.clear() - Iterating over elements: Using
Iteratoror enhanced for loops.