GC211 Data Structure Lecture 1 Sara Alhajjam.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Arrays. What is an array An array is used to store a collection of data It is a collection of variables of the same type.
1 G54PRG Programming Lecture 1 Amadeo Ascó Adam Moore 6 Decision Making, Control Structures & Error Handling.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 6 Arrays.
COMP2004 Programming Practice Sam Holden Department of Computer Science University of Sydney.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
Introduction to Information and Computer Science Computer Programming Lecture c This material (Comp4_Unit5c), was developed by Oregon Health and Science.
DAT602 Database Application Development Lecture 5 JAVA Review.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Introduction to Arrays in Java Corresponds with Chapter 6 of textbook.
The basics of the array data structure. Storing information Computer programs (and humans) cannot operate without information. Example: The array data.
Arrays Chapter 8. What if we need to store test scores for all students in our class. We could store each test score as a unique variable: int score1.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 2: Variables & Data Types.
Software Development CSCI-1302 Lakshmish Ramaswamy.
SE-1010 Dr. Mark L. Hornick 1 Variables & Datatypes.
Component 4: Introduction to Information and Computer Science Unit 5: Overview of Programming Languages, Including Basic Programming Concepts Lecture 3.
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X 1 Chapter Array Basics.
Lab 8. Declaring and Creating Arrays in One Step datatype[] arrayRefVar = new datatype[arraySize]; double[] myList = new double[10];
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Fundamentals 2 1. Programs and Data Most programs require the temporary storage of data. The data to be processed is stored in a temporary storage in.
IAS 1313: OBJECT ORIENTED PROGRAMMING Week 3: Data Type, Control Structure and Array Prepared by: Mrs Sivabalan1.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Chapter 5 Arrays F Introducing Arrays F Declaring Array Variables, Creating Arrays, and Initializing Arrays F Passing Arrays to Methods F Copying Arrays.
Chapter 5 Arrays F Introducing Arrays F Declaring Array Variables, Creating Arrays, and Initializing Arrays F Passing Arrays to Methods F Copying Arrays.
Lecture 7: Arrays Michael Hsu CSULA 3 Opening Problem Read one hundred numbers, compute their average, and find out how many numbers are above the average.
Fundamentals 2.
Single Dimensional Arrays
Chapter 4 Assignment Statement
Elementary Programming
BASIC ELEMENTS OF A COMPUTER PROGRAM
GC101 Introduction to computers and programs
Lecture 2: Data Types, Variables, Operators, and Expressions
Data Types, Identifiers, and Expressions
BY GAWARE S.R. COMPUTER SCI. DEPARTMENT
Student Book An Introduction
A290 TOOLS IN COMPUTING: JAVASCRIPT
Java Programming: From Problem Analysis to Program Design, 4e
Primitive Types Vs. Reference Types, Strings, Enumerations
Chapter 6 Arrays.
Statements, Comments & Simple Arithmetic
Chapter 6 Arrays Solution Opening Problem
Starting JavaProgramming
5 Variables, Data Types.
مساق: خوارزميات ومبادئ البرمجة الفصل الدراسي الثاني 2016/2015
Chapter 2: Basic Elements of Java
Introducing Arrays Array is a data structure that represents a collection of the same types of data.
Java so far Week 7.
Fundamentals 2.
Java Arrays & Strings.
Chapter 2: Java Fundamentals
Classes and Objects.
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
elementary programming
Review for Final Exam.
Chapter 6 Arrays.
Single-Dimensional Arrays chapter6
Lecture Notes - Week 2 Lecture-1. Lecture Notes - Week 2 Lecture-1.
Dr. Sampath Jayarathna Cal Poly Pomona
CS 240 – Lecture 7 Boolean Operations, Increment and Decrement Operators, Constant Types, enum Types, Precedence.
By Yogesh Neopaney Assistant Professor Department of Computer Science
Chapter 6 Arrays.
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
In this class, we will cover:
Primitive Types and Expressions
Chapter 9: Pointers and String
Arrays Introduction to Arrays Reading for this Lecture:
Presentation transcript:

GC211 Data Structure Lecture 1 Sara Alhajjam

Course Syllabus OFFICE: Room 2 OFFICE HOURS: 10-11 TUE; 10-11 THR E-MAIL ADDRESS: salhajjam@ksu.edu.sa WEB PAGE: http://fac.ksu.edu.sa/salhajjam CLASS HOURS: 8-10 TUE & WED Credit Hours: 3

Course Description: Students are introduced to: Fundamental concepts of data structures. Performance measurement of algorithms. Implementation and use of lists, stacks, queues, priority queues, trees, heaps and graphs. Students will do programming assignments.

Assessment Instruments Grading Mark Day Due Assessment Instruments 20% 4/2 Midterm 1 3/3 Midterm 2 Random Assignments 40% Last Week Final 100   Total

Course Policies: No late homework will be accepted. Homework assignments are considered individual efforts. However, students are encouraged to share thoughts with others. Absolutely no copying and no plagiarism. Copyright should be respected. Academic dishonesty cases will be dealt with severely. All exams are closed book. The final exam will be comprehensive.

What is Java? Java is a programming language Created by Sun Microsystems Often used for web programming Initially marketed as a web development system Java is not only for web programming General purpose programming language Very similar to C++ simplified!

Java Program! // Starting of the main method class HiThere { /** * This is the entry point for an application. * @param astrArgs the command line arguments. */ public static void main(String[] astrArgs) { // Starting of the main method System.out.println("Hello World!"); } // main() } // end class HiThere

Reserved words class HiThere { public static void main(String[] astrArgs) { System.out.println("Hello World!"); } // main() } // end class HiThere Reserved words or keywords are part of the language class used to define a class public access keyword - public, private, protected and ‘default’ static type related to belonging void special return type Java is case sensitive

Data Type The data type defines what kinds of values a space memory is allowed to store. All values stored in the same space memory should be of the same data type. All constants and variables used in a Java program must be defined prior to their use in the program.

Primitive Data Types

Variable/Constant Declaration When the declaration is made, memory space is allocated to store the values of the declared variable or constant. The declaration of a variable means allocating a space memory which state (value) may change. The declaration of a constant means allocating a space memory which state (value) cannot change.

Variable Declaration

More declaration examples String declaration with initial value: String word="Apple"; without initial value: String word; char declaration char symbol ='*'; char symbol; Boolean declaration: with initial value: boolean flag=false; boolean valid=true; without initial value: boolean flag;

Operators Arithmetic Unary Operators += addition -= subtract *= multiply /= divide %= remainder iNum += 2; iNum -= 2; iNum *= 2; iNum /= 2; iNum %= 2; int iNum = 7;

Operators Equality and Relational Operators == equal to if (iNum == 1) { != not equal to if (iNum != 1) { > greater than if (iNum > 1) { >= greater than or equal to if (iNum >= 7){ < less than if (iNum < 1) { <= less than or equal if (iNum <= 7) { int iNum = 7;

Decision Making Decision making uses Rational Operators == is equal to != is not equal to > is bigger than >= is bigger or equal to < is smaller than <= is smaller or equal to || logical OR && logical AND counterA == counterB counterA != counterB counterA > counterB counterA >= counterB counterA < counterB counterA <= counterB (counterA > counterB) || (counterA < counterB) (counterA > counterB) && (counterA < counterB)

Decision Making implementations switch Statement A way to simulate multiple if statements int iCounter = 0; // initialisation int iValue; ... if (iCounter == 0) { iValue = -1; } else if (iCounter == 1) { iValue = -2; } else if (iCounter == 2) { iValue = -3; } else { iValue = -4; } int iCounter = 0; // initialisation int iValue; ... switch (iCounter) { case 0: iValue = -1; break; case 1: iValue = -2; case 2: iValue = -3; default: iValue = -4; } // end switch

Switch Structures switch (expression) { case value1: statements1 break; case value2: statements2 ... case value n: statements n default: statements }

Control Structures Loops while do while for Loop Control break continue

int iIndex = 0; // initialise do { System.out.println(iIndex); iIndex += 2; } while (iIndex < 4); ...

Arrays Group of data items All items of the same type, e.g. int Items accessed by integer indexes Starting index with zero Last index is one less than the length Of pre-determinate size The length of an array is the number of items it contains The length is fixed at creation time

Arrays

Declaring Array Variables Arrays are variables Arrays must be declared <type>[] <identifier>; or <type> <identifier>[]; Examples: String[] astrCityNames; or String astrCityNames[]; int[] aiAmounts; or int aiAmounts[]; double myList[];

Creating Arrays arrayRefVar = new datatype[arraySize]; Example: Declare Arrays with reserved word NEW arrayRefVar = new datatype[arraySize]; Example: myList = new double[10]; myList[0] references the first element in the array. myList[9] references the last element in the array.

Declaring and Creating in One Step datatype[] arrayRefVar = new datatype[arraySize]; double[] myList = new double[10]; datatype arrayRefVar[] = new datatype[arraySize]; double myList[] = new double[10];

Example double[] myList = {1.9, 2.9, 3.4, 3.5}; This is equivalent to the following statements: double[] myList = new double[4]; myList[0] = 1.9; myList[1] = 2.9; myList[2] = 3.4; myList[3] = 3.5;

Initializing arrays with input values Scanner input = new Scanner(System.in); System.out.print("Enter " + myList.length + " values: "); for (int i = 0; i < myList.length; i++) myList[i] = input.nextDouble();