Introduction and a Review of Basic Concepts

Slides:



Advertisements
Similar presentations
Chapter 1: INTRODUCTION TO DATA STRUCTURE
Advertisements

DATA STRUCTURES USING C++ Chapter 5
CSE 1302 Lecture 23 Hashing and Hash Tables Richard Gesick.
David Notkin Autumn 2009 CSE303 Lecture 13 This space for rent.
Lecture 20 Arrays and Strings
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
Elementary Data Structures: Part 2: Strings, 2D Arrays, Graphs
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
Review for Final Exam Dilshad M. NYU. In this review Arrays Pointers Structures Java - some basic information.
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
CSC401 – Analysis of Algorithms Lecture Notes 1 Introduction
Chapter 10.
1 Foundations of Software Design Fall 2002 Marti Hearst Lecture 12: Stacks and Queues.
Data Structures Introduction. What is data? (Latin) Plural of datum = something given.
CS 61C L4 Structs (1) A Carle, Summer 2005 © UCB inst.eecs.berkeley.edu/~cs61c/su05 CS61C : Machine Structures Lecture #4: Strings & Structs
Elementary Data Structures and Algorithms
© 2006 Pearson Addison-Wesley. All rights reserved10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
1 Procedural Concept The main program coordinates calls to procedures and hands over appropriate data as parameters.
Chapter 1 Introduction Definition of Algorithm An algorithm is a finite sequence of precise instructions for performing a computation or for solving.
Introduction - The Need for Data Structures Data structures organize data –This gives more efficient programs. More powerful computers encourage more complex.
CMSC 341 Introduction to Java Based on tutorial by Rebecca Hasti at
Data Structures 1- Course Syllabus. 2- Introduction about Data Structures.
Abstract Data Types (ADTs) Data Structures The Java Collections API
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 14: Pointers, Classes, Virtual Functions, and Abstract Classes.
Comp 249 Programming Methodology Chapter 15 Linked Data Structure - Part B Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia.
Review C++ exception handling mechanism Try-throw-catch block How does it work What is exception specification? What if a exception is not caught?
Unit III : Introduction To Data Structures and Analysis Of Algorithm 10/8/ Objective : 1.To understand primitive storage structures and types 2.To.
Introduction to Arrays in Java Corresponds with Chapter 6 of textbook.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
 DATA STRUCTURE DATA STRUCTURE  DATA STRUCTURE OPERATIONS DATA STRUCTURE OPERATIONS  BIG-O NOTATION BIG-O NOTATION  TYPES OF DATA STRUCTURE TYPES.
CS 206 Introduction to Computer Science II 09 / 10 / 2009 Instructor: Michael Eckmann.
Week 14 - Monday.  What did we talk about last time?  Introduction to C++  Input and output  Functions  Overloadable  Default parameters  Pass.
Pointers OVERVIEW.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Data structures Abstract data types Java classes for Data structures and ADTs.
INTRODUCTION TO DATA STRUCTURES. INTRODUCTION A data structure is nothing but an arrangement of data either in computer's memory or on the disk storage.
1 Dynamic Memory Allocation –The need –malloc/free –Memory Leaks –Dangling Pointers and Garbage Collection Today’s Material.
Sadegh Aliakbary Sharif University of Technology Spring 2011.
Data Structure Introduction.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Copyright Curt Hill Variables What are they? Why do we need them?
Data Structures Using C++ 2E
OOP using C Abstract data types How to accomplish the task??? Requirements Details Input, output, process Specify each task in terms of input.
Computer Organization and Design Pointers, Arrays and Strings in C Montek Singh Sep 18, 2015 Lab 5 supplement.
Data Structures and Algorithms IT12112
Week 5 - Wednesday.  What did we talk about last time?  Recursion  Definitions: base case, recursive case  Recursive methods in Java.
Week 2 - Friday.  What did we talk about last time?  Computing Big Oh.
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
CS6045: Advanced Algorithms Data Structures. Hashing Tables Motivation: symbol tables –A compiler uses a symbol table to relate symbols to associated.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
REEM ALMOTIRI Information Technology Department Majmaah University.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
MORE POINTERS Plus: Memory Allocation Heap versus Stack.
BITS Pilani Pilani Campus Data Structure and Algorithms Design Dr. Maheswari Karthikeyan Lecture1.
COM212 Data Structures Intro to Abstract Data Structures 4 Weeks ~7 Homework Problems Implementation of Abstract Data Structures 7 Weeks ~7 Programming.
Sections Basic Data Structures. 1.5 Data Structures The way you view and structure the data that your programs manipulate greatly influences your.
DYNAMIC MEMORY ALLOCATION. Disadvantages of ARRAYS MEMORY ALLOCATION OF ARRAY IS STATIC: Less resource utilization. For example: If the maximum elements.
Mohammed I DAABO COURSE CODE: CSC 355 COURSE TITLE: Data Structures.
Introduction toData structures and Algorithms
Week 4 - Friday CS221.
CS 215 Final Review Ismail abumuhfouz Fall 2014.
© 2016 Pearson Education, Ltd. All rights reserved.
Big-O notation.
Week 15 – Monday CS221.
Arrays in C.
Chapter 7: Strings and Characters
Dynamic Data Structures and Generics
Introduction to Data Structure
Presentation transcript:

Introduction and a Review of Basic Concepts Syllabus and goals of the course Object oriented programming contrasting to C programming Objects, classes, methods Instantiation, references Polymorphism, inheritance Constructor, destructor, garbage collection Encapsulation Public, private, protected Data structures already introduced: Stacks, queues, linked lists Recursion and induction Understanding data structures and algorithms is a major difference separating computer scientists from one who reads a manual and begins to program.

C versus Java The dot in Java is equivalent to the -> C; there is no Java equivalent to the C dot operator. Generally, use -> in most cases and declare variables using the ‘*’ (indicating pointer) There is no Boolean in C. Many programmers declare TRUE and FALSE using #define C has no garbage collection. To avoid memory leaks, make sure to free whatever you malloc. Use NULL in C, instead of the null in Java Use scanf for input, but make sure to clear the input buffer after an error (scanf("%s*")) C has no methods (it has functions), so dot notation makes no sense. Replace: object.method by function(data There is no length property in arrays and strings. Array sizes must be stored in a separate variable. Be careful with pointers and memory management. C doesn’t catch all errors at compile time.

Strings in C There is no String type, use an array of characters (char *data). C has no “+” operator for string concatenation. Use strcat, but make sure you have an allocated area in memory to hold the larger string. To truncate a string, store '\0' in the appropriate index. To format output, use printf. For both puts and printf, make sure to follow the output with fflush(stdout);. Otherwise, output only occurs when the accumulated print buffer gets large enough. There are many string functions in C, all starting with str. There is also memory manipulation functions, all starting with mem. Make sure your strings end with a null. Java has the length in the front of a string; C has a null at the end.

Analysis of Algorithms Definition of Algorithm. Why study data types and algorithm? Step-by-step solution to a problem Often the problem can be specified in terms of the size of the data set (n). Algorithm performance (The technical term is complexity) A good algorithm implemented by a bad programmer will beat a bad algorithm implemented by a good programmer A time function, f, of the dataset size is often used to measure effectiveness as the data set size grows. For example, f(n) <= c*n, where c is a constant > 0. Other examples of the growth rate are c*n2, c*lg n, c, lg2 n, etc. Big Oh notation. How to determine if an algorithm is a good one? How fast does it work on a given data set? What is the Relationship between time and data set size? How does it perform on different data set sizes? Growth is more important than a given run’s performance

Big Oh Notation Measurement of algorithm efficiency in terms of memory or time as the problem size increases Formal Definition: f(n) = O(g(n)) means there are positive constants c and z, such that 0 ≤ f(n) ≤ cg(n) for all n ≥ z. The values of c and z must be fixed for the function f and must not depend on n. Explanation of terms: g(n) is a well known function to which we want to compare our algorithm. f(n) is how our algorithm performs on different size data sets z is an integer. For all data set sizes smaller than z, we don’t consider the algorithm’s efficiency c is a positive constant . By multiplying g by this constant, all functions with equal or smaller slopes will satisfy the Big Oh definition requirements. Review of logarithms. Conversion of logarithms Logn x = logq x / logq n

Pictorial View of Big Oh Time or memory z Data set size

Allocate Unique Random Numbers Declare the free list int freeList[MAX]; Initialize the free list for (i=0; i<MAX; i++) freeList[i] = i; freeCount = MAX; Allocate an entry from the free list Find a random index into the free list: index = (int)(rand() * freeCount); Get the value from the free list (key = freeList[index];) Replace the index with the last value in the freeList freeList[index] = freeList[--freeCount]; Release an entry back to the free list Put the value to the end of the free list freeList[freeCount++] = key;

Abstract Data Type A general-purpose data structure encapsulated from the user through a well-defined set of operation Design Design the operations that are to be used Design the data structure to be used Examples (What operations? What data-structure?) Java’s primitive floating point number Stacks, queues, and linked lists. To be covered: Trees, priority queues, hash tables, graphs. Arrays (Ordered and Unordered) Array operations and complexities (insert, delete, find, expand,sort,access,traverse) Advantages and disadvantages