CS210 - Data Structures and Algorithms 1
INTRODUCTION
- Instructor: Dr. Natalie Culligan
- Research Areas:
- Behavioral Data
- Education
- Virtual Reality
- Video Games
TEXTBOOKS
- Introduction to Algorithms by Cormen, Leiserson, Rivest, and Stein
- Data Structures and Algorithms in Java by Goodrich, Tamassia, and Goldwasser
COURSE TOPICS
- Object-Oriented Programming (OOP) - revision
- Array Algorithms
- Algorithm Notation (Big-O, Small-O, Omega, Theta)
- Sorting Algorithms
- Recursion
- Stacks, Queues, Linked Lists
ASSESSMENT
- Labs: 10%
- Final Exam: 90%
CONTACT INFORMATION
- Office: 128, Eolas Building
- Office Hours: TBD
- Email: Natalie.Culligan@mu.ie
PROGRAMMING LANGUAGE
- Java will be used for representing data structures and algorithms
- Other popular languages (e.g., C++) can also be utilized
JAVA PROGRAMMING
- Java was first released in 1995, developed by James Gosling at Sun Microsystems
- Platform independent; runs on any hardware/OS via the Java Virtual Machine (JVM)
- Compilation Process:
- Source code (.java file) is converted into bytecode (.class file)
COMPILATION AND EXECUTION
- Java programs must be compiled before running, changes necessitate recompilation
VARIABLES & DATA TYPES
- Variables: Named storage in memory
- Two types: Primitive (int, double) and Reference (objects)
- Cannot be reserved keywords
- Can be initialized during declaration; undefined if not initialized
SCOPE & GARBAGE COLLECTION
- Local variables exist within functions and are destroyed after
- Automatic memory management in Java (garbage collection)
ASSIGNMENT
- Assignment operator '=' modifies the variable’s value (e.g., total = 55)
- Type consistency required when assigning values
PRIMITIVE DATA TYPES
- Eight Primitive Types:
- Integers: byte, short, int, long
- Floating Points: float, double
- Character: char
- Boolean: boolean
BITS AND BYTES
- 1 byte = 8 bits, kilobyte = 1024 bytes, megabyte = 1024^2 bytes
PRIMITIVE TYPE DESCRIPTIONS
| Type | Description | Size |
|---|---|---|
| int | Integer type, range: -2,147,483,648 to 2,147,483,647 | 4 bytes |
| byte | Single byte type, range: -128 to 127 | 1 byte |
| short | Short integer type, range: -32,768 to 32,767 | 2 bytes |
| long | Long integer type, range: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 | 8 bytes |
| double | Double-precision floating-point, ~±10308, ~15 decimal digits | 8 bytes |
| float | Single-precision floating-point, ~±103838, ~7 decimal digits | 4 bytes |
| char | Character type (Unicode) | 2 bytes |
| boolean | Boolean values (true/false) | 1 bit |
NUMBER TYPES
- Floats cannot be assigned to integers without casting: use (int)value to convert
- Use Math.round to convert floats to nearest integers
ARITHMETIC EXPRESSIONS
- Basic arithmetic operators: +, -, *, /, % (modulus)
OPERATOR PRECEDENCE
- BOMDAS (Brackets, Orders, Multiplication and Division, Addition and Subtraction)
INCREMENT AND DECREMENT
- Increment:
++, Decrement:-- - Example:
count++is equivalent tocount = count + 1
RELATIONAL OPERATORS
| Operator | Description |
|---|---|
| > | Greater than |
| >= | Greater than or equal to |
| < | Less than |
| <= | Less than or equal to |
| == | Equal to |
| != | Not equal to |
COMPARING STRINGS
- Use
.equals()method for string equality check instead of==
READING INPUT
- Use
Scannerclass for input- Syntax Example:
```java
Scanner in = new Scanner(System.in);
int quantity = in.nextInt();
- Syntax Example:
## CONTROL STRUCTURES
### 1. Sequence
- Execution of statements in order
### 2. Selection
- Use `if`, `if-else`, and `else if` for branching
### 3. Iteration
- Use loops: `while`, `do-while`, `for`
### 4. WRITE YOUR own loops
- Nested loops and conditional statements possible
## EXAMPLES
- **While Loop:**
java
while(condition){
// statements
}
- **For Loop:**
java
for(int i = 0; i < 5; i++) {
// statements
}
- **If-Else Example:**
java
if(condition)
// statement
else
// statement
```
FINAL NOTES
- Understand operator precedence
- Pay attention to scope, local variables, and object references
- Practice coding exercises regularly to strengthen understanding.