Discussion Section: HW1 and Programming Tips GS540.

Slides:



Advertisements
Similar presentations
Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
Advertisements

Introducing JavaScript
INSTRUCTION SET ARCHITECTURES
CSCE 145: Algorithmic Design I Chapter 1 Intro to Computers and Java Muhammad Nazmus Sakib.
ECE 353: Lab C Pointers and Structs. Basics A pointer holds an address to some variable Notation: – Dereferencing operator: * int *x is a declaration.
CIS 101: Computer Programming and Problem Solving Lecture 8 Usman Roshan Department of Computer Science NJIT.
COMP171 Data Structure & Algorithm Tutorial 1 TA: M.Y.Chan.
1 Homework Turn in HW2 at start of next class. Starting Chapter 2 K&R. Read ahead. HW3 is on line. –Due: class 9, but a lot to do! –You may want to get.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
Differences between Java and C CS-2303, C-Term Differences between Java and C CS-2303, System Programming Concepts (Slides include materials from.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Introduction.
CSCE 121, Sec 200, 507, 508 Fall 2010 Prof. Jennifer L. Welch.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Introduction.
Chapter 2: Impact of Machine Architectures What is the Relationship Between Programs, Programming Languages, and Computers.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic concepts and uses of arrays ❏ To be able to define C.
Computer Science 210 Computer Organization Introduction to C.
Pointers (Continuation) 1. Data Pointer A pointer is a programming language data type whose value refers directly to ("points to") another value stored.
CIS Computer Programming Logic
Pointers CS362. Pointers A Pointer is a variable that can hold a memory address Pointers can be used to: Indirectly reference existing variables (sometimes.
MIPS coding. SPIM Some links can be found such as:
Foundations of Computer Science Computing …it is all about Data Representation, Storage, Processing, and Communication of Data 10/4/20151CS 112 – Foundations.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
Chapter 12 Recursion, Complexity, and Searching and Sorting
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 12: Pointers continued, C strings.
Comp 245 Data Structures Linked Lists. An Array Based List Usually is statically allocated; may not use memory efficiently Direct access to data; faster.
Stack and Heap Memory Stack resident variables include:
Basics of Java IMPORTANT: Read Chap 1-6 of How to think like a… Lecture 3.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Pointers OVERVIEW.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
Execution of an instruction
COP 3530 Data Structures & Algorithms Discussion Session 3.
These notes were originally developed for CpSc 210 (C version) by Dr. Mike Westall in the Department of Computer Science at Clemson.
C++ REVIEW – POINTERS AND TEST DRIVEN DEVELOPMENT.
Introduction to Programming
Computer Graphics 3 Lecture 1: Introduction to C/C++ Programming Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora.
Pointers in C++. Topics Covered  Introduction to Pointers  Pointers and arrays  Character Pointers, Arrays and Strings  Examples.
STL CSSE 250 Susan Reeder. What is the STL? Standard Template Library Standard C++ Library is an extensible framework which contains components for Language.
Lecture 01a: C++ review Topics: Setting up projects, main program Memory Diagrams Variables / Types (some of) the many-types-of-const's Input / Output.
Announcements Assignment 1 due Wednesday at 11:59PM Quiz 1 on Thursday 1.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the relationship between arrays and pointers ❏ To understand the.
Scott Marino MSMIS Kean University MSAS5104 Programming with Data Structures and Algorithms Week 1 Scott Marino.
Carnegie Mellon 1 Malloc Lab : Introduction to Computer Systems Friday, July 10, 2015 Shen Chen Xu.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 11: Pointers.
Department of Electronic & Electrical Engineering Lecture 3 IO reading and writing variables scanf printf format strings "%d %c %f" Expressions operators.
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 10/11/2006 Lecture 7 – Introduction to C.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
PYTHON FOR HIGH PERFORMANCE COMPUTING. OUTLINE  Compiling for performance  Native ways for performance  Generator  Examples.
PERL SCRIPTING. COMPUTER BASICS CPU, RAM, Hard drive CPU can only use data in the register directly CPU RAM HARD DRIVE.
Computer science C programming language lecture 1.
1 Binghamton University Exam 1 Review CS Binghamton University Birds eye view -- Topics Information Representation Bit-level manipulations Integer.
Lecture 3 Translation.
The Machine Model Memory
Prof: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2017
Computer Science 210 Computer Organization
A bit of C programming Lecture 3 Uli Raich.
Chapter 6: Data Types Lectures # 10.
Programming Tips GS540 January 10, 2011.
CS190/295 Programming in Python for Life Sciences: Lecture 1
Pointers and References
Computer Science 210 Computer Organization
Data Structures and Analysis (COMP 410)
Discussion section #2 HW1 questions?
First discussion section agenda
Introduction to Abstract Data Types
CSCE Fall 2013 Prof. Jennifer L. Welch.
Programming Tips GS540 January 10, 2011.
CSCE Fall 2012 Prof. Jennifer L. Welch.
COP 3330 Object-oriented Programming in C++
Computer Programming (CS101) Lecture-02
Presentation transcript:

Discussion Section: HW1 and Programming Tips GS540

Maxwell Libbrecht ❖ 4 th year Computer Science graduate student ❖ Bill Noble's lab  Functional element discovery from ENCODE data ❖ Programming: Python, R, C/C++ ❖ Dev environment: Vim (Mac / Linux) A bit about me…

Discussion Section Topics? ❖ Programming topics Vector arithmetic in R, MATLAB, python+numpy C++ standard library Reading and writing binary files Managing packages in Unix How to organize a comp-bio project ❖ Data structures ❖ Machine learning ❖ Methods in comp-bio Identifying functional elements Motifs RNA-seq

Outline ❖ General tips / Coding style advice ❖ C Programming Pointers Sorting ❖ Homework 1

Programming languages  Compiled: C, C++, C#, Java  Interpreted: Python, R, Perl, Ruby, MATLAB  Interpreted languages are usually slower.  Interpreted languages are fast when you can use premade packages written in C.  Please do not use packages that implement the meat of your algorithm.

Debugging tips ❖ Validate using test cases with a small amount of data: HEY_YOU_UOY ❖ Solve test cases by hand to verify program ❖ Consider pathological / “edge” cases ❖ Print intermediate output ❖ Write test cases before you start coding ❖ Write incrementally, test as you go Use assertions to avoid bugs ❖ Compare to a slow-but-correct version

Coding style advice ❖ Your audience is people as well as the computer ❖ Break large functions into small, simple functions ❖ Functions for repeated code (initialize data, etc) ❖ Use descriptive names for variables and files "exons.txt" rather than "data", "position_index" rather than "i"

Performance ❖ Avoid unnecessary optimization!  Simplicity over speed (at least at first)  Big performance gains from small changes (e.g. within loops) ❖ Move unnecessary code out of loops ❖ Avoid frequent memory allocation Allocate memory in large blocks (e.g. array of structs, not one at a time) Re-use the same piece of memory ❖ Avoid slow comparison routines when sorting ❖ Use a profiler (gprof for C; dprofpp for perl)

Numerical issues  Floating point numbers are stored in the format:  * 2^  Do not compare floats with "x==y".  Use abs(x-y < ) instead  Beware subtracting large, similar numbers.  Beware integer casts:  1/2 == 0, but 1.0/2 == 0.5  Consider using log space to avoid overflow or underflow.

C++ help ❖ ❖ ++-tutorial.html ++-tutorial.html ❖ C++ How to Program, Deitel and Deitel C++ How to Program, Deitel and Deitel

Pointers in C ❖ Pointers are memory addresses (they point to other variables) ❖ The address-of operator (&) obtains the memory address of a variable ❖ The dereference operator (*) accesses the value stored at the pointed-to mem location

Pointers in C 10 x: int_ptr:

Pointers in C ❖ Arrays are pointers to blocks of memory ❖ Pointers “know” the data size they point to ❖ Array indices are just pointer arithmetic and dereferencing combined: a[12] is the same as *(a+12) &a[3] is the same as a+3 From The C Programming Language by B. Kernighan & D. Ritchie

Pointers in C ❖ Large arrays should be dynamically allocated (on the heap) From The C Programming Language by B. Kernighan & D. Ritchie CC++

Pointers in C (cont’d) ❖ Attributes of pointed-to structures can be derefenced with “arrow notation”: a->elem is equivalent to (*a).elem

Sorting (in C)

HW1 Tips ❖ Start with pseudocode / [python] ❖ Get comfortable with pointers Saves memory without copying strings Pointer arithmetic ❖ Think about how to store inputs Declare large arrays on heap not stack ❖ Think about how to store results ❖ Output in template format directly Avoid copy-pasting results into a template

HW1 pseudocode ❖ Read in a sequence What form? How do I store it? ❖ Find its reverse complement ❖ Concatenate ❖ Make suffix array ❖ Sort suffix array ❖ Find ALL longest common substrings Adjacent in list? From different genomes? How do I store it?