Head Command -n Option Exam Paper PDF

Document Details

Uploaded by Deleted User

Tags

command-line tools sql queries database design computer science

Summary

This document is a past paper covering topics in computer science, including command-line tools, SQL queries, functional dependencies (FD), data manipulation language (DML), and data definition language (DDL), with an in-depth explanation of the concepts.

Full Transcript

Head command -n option Exam 1: predict behavior of cut, grep, cat, sort, uniq with pipes, redirection ( include useful flags for each command) prediction of behavior of SQL queries properties of functional dependence, refactoring difference DDL, DML, scope of each, 1st normal for...

Head command -n option Exam 1: predict behavior of cut, grep, cat, sort, uniq with pipes, redirection ( include useful flags for each command) prediction of behavior of SQL queries properties of functional dependence, refactoring difference DDL, DML, scope of each, 1st normal form foreign key constraints, properties of primary keys tradeoffs for using DMBS, ORM systems, service oriented architecture maybe questions on debugging facts, puzzles about serialization, models.py DDL Exam 2: Hashing for storage, hashing for integrity; hash collisions Symmetric encryption and one-time pads Asymmetric encryption; roles using public-private key pairs; one-way communication, keys for signing Indexing for faster lookup (O(log N)); hash tables for constant-time lookup Imprecise matching: n-grams digests, Jaccard dissimilarity, Levenshtein distance, semantic embeddings Quantifying server-client performance: throughput, latency and bandwidth filesystem: directories, paths, filenames and basic file permissions (chmod) password hashing with salt git as a tool for collaboration: forks, clones, merges, pull requests, and making use of history. Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 1/13 2x2 decision accuracy tables / accuracy statistics Final exam (cumulative) Streaming model of computation lazy evaluation; dask OTAP and OLAP CAP theorem - desiging for resiliancy or consistency Cloud computing: parallelizing workflows; speedup; sharding Proof-of-work, blockchain Tradeoffs: time-space, time-error, money-time we've learned a lot of tricks to try to evade resource limitations Some short-answer questions, none requiring more than a sentence. Virtualization; cloud computing; containerization with docker Not included: SYNTAX - you don't have to remember any magic words No questions will hinge on single letters, or misspellings. Mispellings will not feature in the correctness of any questions. Create details notes on the exam topics Exam 1: Notes on Topics Command-Line Tools with Pipes and Redirection 1. `cut` Purpose: Extract sections of each line of a file or input. Useful Flags: `-f`: Specify fields (e.g., `-f1,3` extracts the 1st and 3rd fields). `-d`: Define a delimiter (default: tab). Pipe Example: `cat file.txt | cut -d',' -f2` extracts the 2nd column from a CSV file. 2. `grep` Purpose: Search for patterns in text. Useful Flags: `-i`: Case-insensitive search. `-v`: Invert match (exclude lines matching the pattern). `-E`: Extended regular expressions. Pipe Example: `cat file.txt | grep -i "error"` finds all lines containing "error". 3. `cat` Purpose: Concatenate and display file contents. Useful Flags: Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 2/13 `-n`: Number lines. Pipe Example: `cat file1.txt file2.txt > combined.txt` concatenates files into `combined.txt`. 4. `sort` Purpose: Sort lines of text. Useful Flags: `-r`: Reverse order. `-n`: Numerical sort. `-u`: Remove duplicates. Pipe Example: `cat file.txt | sort -n` sorts lines numerically. 5. `uniq` Purpose: Filter adjacent duplicate lines. Useful Flags: `-c`: Count occurrences of each line. `-i`: Case-insensitive comparison. Pipe Example: `cat file.txt | sort | uniq -c` counts occurrences of unique lines. SQL Queries and Predictions Behavior: Queries can involve selection (`SELECT`), insertion (`INSERT`), updating (`UPDATE`), and deletion (`DELETE`). Aggregate functions (e.g., `SUM`, `COUNT`, `AVG`) summarize data. Joins (`INNER`, `OUTER`, `LEFT`, `RIGHT`) combine rows from multiple tables. Properties of Functional Dependency Definition: A functional dependency X → Y means attribute Y is determined by X. Key Properties: Reflexivity: If Y ⊆ X , then X → Y. Augmentation: If X → Y , then XZ → Y Z. Transitivity: If X → Y and Y → Z , then X → Z. DDL vs. DML DDL (Data Definition Language): Defines schema (`CREATE`, `ALTER`, `DROP`). Scope: Structural definition and changes. DML (Data Manipulation Language): Modifies data (`INSERT`, `UPDATE`, `DELETE`, `SELECT`). Scope: Manipulating and querying records. Normalization 1st Normal Form (1NF): Eliminate duplicate columns. Ensure atomicity: each cell contains a single value. Keys and Constraints Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 3/13 Primary Key: Uniquely identifies a row. Properties: Non-null, unique. Foreign Key: Ensures referential integrity by linking to a primary key in another table. Tradeoffs: DBMS vs. ORM DBMS: Pros: High performance, query optimization. Cons: Requires SQL knowledge. ORM: Pros: Simplifies database access with programming language objects. Cons: Overhead, less control over queries. Service-Oriented Architecture (SOA) Definition: Software design approach where services communicate over a network. Key Features: Loose coupling, scalability, and interoperability. Debugging Concepts Identifying and fixing logic or syntax errors. Common techniques: Logging, breakpoints, step-through debugging. Exam 2: Notes on Topics Hashing Storage: Maps data to fixed-size values (e.g., hash tables). Integrity: Verifies data (e.g., checksums, cryptographic hashes like SHA-256). Collisions: Occur when different inputs produce the same hash. Encryption Symmetric Encryption: Same key for encryption and decryption. Example: AES, DES. One-time pads are theoretically secure but impractical. Asymmetric Encryption: Public-private key pairs. Roles: Public key: Encrypts or verifies signatures. Private key: Decrypts or signs. Indexing and Lookup Indexing: Speeds up search in sorted data. Complexity: O(log N ). Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 4/13 Hash Tables: Provide O(1) average lookup time. Imprecise Matching Techniques: n-grams: Divide strings into n-length substrings for similarity. Jaccard Dissimilarity: Measures set overlap. Levenshtein Distance: Counts edits needed to transform one string into another. Performance Metrics Throughput: Data processed per unit time. Latency: Time for a single operation. Bandwidth: Maximum data transmission capacity. Filesystem Components: Directories, paths, filenames. Permissions: `chmod` sets permissions using symbolic or octal codes. Password Hashing Use a salt to mitigate rainbow table attacks. Git for Collaboration Key Concepts: Fork: Clone a repository for independent work. Pull Requests: Request changes to the main repository. History: Use `git log` to view commits. Accuracy Statistics 2x2 Tables: Measure outcomes like true positive, false positive, etc. Metrics: Accuracy = TP+TN Total.​ Final Exam: Notes on Topics Streaming Computation Processes data in real-time. Lazy evaluation defers computation until needed. Cloud Computing Parallel Workflows: Divide tasks across nodes. Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 5/13 Speedup = serial time/parallel time. Sharding: Partition data to improve scalability. Proof-of-Work and Blockchain Proof-of-Work: Requires computational effort to add blocks. Blockchain: Decentralized, immutable ledger. Tradeoffs Time-Space: Optimizing memory may slow computations. Time-Error: Approximation algorithms trade precision for speed. Virtualization and Containerization Virtualization: Runs multiple OS instances on a single machine. Containerization: Lightweight alternative (e.g., Docker) for isolated environments. Resource Management Design systems to balance time, cost, and accuracy. These notes cover the core concepts and their practical applications, ensuring you're prepared for all the outlined topics! can you make them more in-depth providing notes and examples for each topic Exam 1: In-Depth Notes with Examples Command-Line Tools with Pipes and Redirection Command-line tools are essential for manipulating data efficiently. Below is an in-depth explanation of key tools: 1. `cut`: Purpose: Extracts sections from lines of input. Examples: Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 6/13 bash # Extract the first column from a tab-separated file cut -f1 file.txt # Extract specific fields from a CSV file cut -d',' -f2,4 data.csv Key Usage with Pipes: bash cat data.txt | cut -d' ' -f3 This extracts the 3rd word from each line. 2. `grep`: Purpose: Searches for patterns using regular expressions. Examples: bash # Find all lines containing 'error' (case-insensitive) grep -i "error" log.txt # Exclude lines containing 'warning' grep -v "warning" log.txt Key Usage with Pipes: bash cat data.txt | grep -E "pattern1|pattern2" This finds lines matching `pattern1` or `pattern2`. 3. `cat`: Purpose: Concatenates and displays file contents. Examples: bash # Concatenate and display two files cat file1.txt file2.txt Key Usage with Pipes: Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 7/13 bash cat file.txt | grep "search term" 4. `sort`: Purpose: Sorts input lines. Examples: bash # Alphabetically sort lines sort file.txt # Numerical sort sort -n numbers.txt Key Usage with Pipes: bash cat data.txt | sort | uniq This removes duplicate lines after sorting. 5. `uniq`: Purpose: Removes adjacent duplicate lines. Examples: bash # Remove duplicate lines uniq sorted.txt # Count occurrences of unique lines uniq -c sorted.txt Key Usage with Pipes: bash cat file.txt | sort | uniq -c Counts occurrences of each unique line. SQL Queries Examples: Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 8/13 sql -- Select query with aggregation SELECT department, COUNT(*) AS total_employees FROM employees GROUP BY department; -- Joining two tables SELECT orders.id, customers.name FROM orders INNER JOIN customers ON orders.customer_id = customers.id; -- Updating rows UPDATE employees SET salary = salary * 1.1 WHERE department = 'Sales'; Behavior: Queries can manipulate or retrieve data. Performance can vary depending on indexes and joins. Properties of Functional Dependency Example: If StudentID → N ame, knowing `StudentID` determines `Name`. Key Properties: Reflexivity: X → X. Augmentation: X → Y ⟹ XZ → Y Z. Transitivity: X → Y and Y → Z ⟹ X → Z. DDL vs. DML Examples: DDL: sql CREATE TABLE students ( id INT PRIMARY KEY, name VARCHAR(50) ); ALTER TABLE students ADD COLUMN age INT; DML: sql INSERT INTO students (id, name, age) VALUES (1, 'Alice', 20); SELECT * FROM students WHERE age > 18; Normalization Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 9/13 1NF Example: Original table (not in 1NF): Student Subjects Alice Math, Bio 1NF-compliant table: Student Subject Alice Math Alice Bio Keys and Constraints Primary Key Example: sql CREATE TABLE orders ( order_id INT PRIMARY KEY, product_name VARCHAR(50) ); Foreign Key Example: sql CREATE TABLE customers ( customer_id INT PRIMARY KEY, name VARCHAR(50) ); CREATE TABLE orders ( order_id INT PRIMARY KEY, customer_id INT, FOREIGN KEY (customer_id) REFERENCES customers(customer_id) ); Tradeoffs: DBMS vs. ORM DBMS: Optimized performance but requires knowledge of SQL. ORM: Example: Using SQLAlchemy in Python simplifies queries: python session.query(User).filter(User.name == 'Alice').all() Service-Oriented Architecture Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 10/13 Example: Services like `user-authentication` and `payment-processing` interact over REST APIs. Advantages: Scalability, modularity. Debugging Concepts Techniques: Use logging frameworks like `Log4j` for error tracking. Example: bash python -m pdb script.py Exam 2: In-Depth Notes with Examples Hashing Example: python import hashlib hash_object = hashlib.sha256(b'example') print(hash_object.hexdigest()) Encryption Symmetric Encryption Example: python from cryptography.fernet import Fernet key = Fernet.generate_key() cipher = Fernet(key) encrypted = cipher.encrypt(b"Secret Data") print(encrypted) Asymmetric Encryption Example: Public-private keys used in tools like OpenSSL. Imprecise Matching Levenshtein Distance: Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 11/13 python from Levenshtein import distance print(distance('kitten', 'sitting')) Performance Metrics Examples: Throughput: 500 requests/second. Latency: Average response time is 200ms. Git Example Commands: bash git clone repository_url git checkout -b new-feature git pull origin main Password Hashing with Salt Example: python import bcrypt salt = bcrypt.gensalt() hashed = bcrypt.hashpw(b'password', salt) print(hashed) Final Exam: In-Depth Notes Streaming Computation Example: Use Python's `dask` for lazy evaluation. python import dask.array as da x = da.ones((10000, 10000), chunks=(1000, 1000)) print(x.mean().compute()) Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 12/13 Blockchain Example: `Proof-of-Work` in Bitcoin requires solving a complex hash puzzle. These comprehensive notes and examples cover the critical aspects of the topics, ensuring you're prepared for detailed questions. Let me know if you'd like further elaboration on any specific section! Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 13/13

Use Quizgecko on...
Browser
Browser