Tutorial 9 String and Structure NUS SCHOOL OF COMPUTING CS1010E PROGRAMMING METHODOLOGY 1 CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO.

Slides:



Advertisements
Similar presentations
Review for Final Exam Dilshad M. NYU. In this review Arrays Pointers Structures Java - some basic information.
Advertisements

Fundamentals of Python: From First Programs Through Data Structures
1 HeapSort CS 3358 Data Structures. 2 Heapsort: Basic Idea Problem: Arrange an array of items into sorted order. 1) Transform the array of items into.
1 Heaps & Priority Queues (Walls & Mirrors - Remainder of Chapter 11)
Arrays Arrays are data structures consisting of data items of the same type. Arrays are ‘static’ entities, in that they remain the same size once they.
Scott Grissom, copyright 2004 Chapter 5 Slide 1 Analysis of Algorithms (Ch 5) Chapter 5 focuses on: algorithm analysis searching algorithms sorting algorithms.
Text Chapters 1, 2. Sorting ä Sorting Problem: ä Input: A sequence of n numbers ä Output: A permutation (reordering) of the input sequence such that:
Searches & Sorts V Deena Engel’s class Adapted from W. Savitch’s text An Introduction to Computers & Programming.
Discrete Math CSC151 Analysis of Algorithms. Complexity of Algorithms  In CS it's important to be able to predict how many resources an algorithm will.
More on XSLT. More on XSLT variables Earlier we saw two ways to associate a value with a variable  A variable whose value is the empty string, for example.
Arrays Data Structures - structured data are data organized to show the relationship among the individual elements. It usually requires a collecting mechanism.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 12: Arrays.
Chapter 8 Arrays and Strings
 2007 Pearson Education, Inc. All rights reserved C Arrays.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic concepts and uses of arrays ❏ To be able to define C.
Fall 2013 Instructor: Reza Entezari-Maleki Sharif University of Technology 1 Fundamentals of Programming Session 17 These.
Chapter 7: Arrays. In this chapter, you will learn about: One-dimensional arrays Array initialization Declaring and processing two-dimensional arrays.
Part 2.  Predefined  User defined  //exclusive to c++  / //c specific.
Chapter 8 Arrays and Strings
Fall 2013 Instructor: Reza Entezari-Maleki Sharif University of Technology 1 Fundamentals of Programming Session 17 These.
Chapter 12 Recursion, Complexity, and Searching and Sorting
Searching and Sorting Chapter Sorting Arrays.
Hashing Table Professor Sin-Min Lee Department of Computer Science.
LAB#7. Insertion sort In the outer for loop, out starts at 1 and moves right. It marks the leftmost unsorted data. In the inner while loop, in starts.
© 2012 EMC Publishing, LLC Slide 1 Chapter 8 Arrays  Can store many of the same type of data together.  Allows a collection of related values to be stored.
Prepared By Ms.R.K.Dharme Head Computer Department.
Tutorial 5 Arrays Basics (1D, 2D) NUS SCHOOL OF COMPUTING CS1010E PROGRAMMING METHODOLOGY 1 CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO.
© M. Gross, ETH Zürich, 2014 Informatik I für D-MAVT (FS 2014) Exercise 12 – Data Structures – Trees Sorting Algorithms.
Sorting – Insertion and Selection. Sorting Arranging data into ascending or descending order Influences the speed and complexity of algorithms that use.
Summary Algorithms Flow charts Bubble sort Quick sort Binary search Bin Packing.
Decision Maths 1 Sorting Algorithm Shuttle Sort A V Ali : 1.Compare items 1 and 2; swap them if necessary 2.Compare 2 and 3; swap.
Bubble Sort 18 th December 2014 With Mrs
New Mexico Computer Science For All Algorithm Analysis Maureen Psaila-Dombrowski.
Visual C++ Programming: Concepts and Projects Chapter 11B: Pointers (Tutorial)
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To introduce the structure, union, and enumerated types ❏ To use the type definition.
Chapter 18: Searching and Sorting Algorithms. Objectives In this chapter, you will: Learn the various search algorithms Implement sequential and binary.
Searching & Sorting Programming 2. Searching Searching is the process of determining if a target item is present in a list of items, and locating it A.
SORTING & SEARCHING - Bubble SortBubble Sort - Insertion SortInsertion Sort - Quick SortQuick Sort - Binary SearchBinary Search 2 nd June 2005 Thursday.
ALGORITHMS.
1 Searching and Sorting Searching algorithms with simple arrays Sorting algorithms with simple arrays –Selection Sort –Insertion Sort –Bubble Sort –Quick.
1 Principles of Computer Science I Honors Section Note Set 5 CSE 1341.
New Mexico Computer Science For All Search Algorithms Maureen Psaila-Dombrowski.
Course Code #IDCGRF001-A 5.1: Searching and sorting concepts Programming Techniques.
1. Searching The basic characteristics of any searching algorithm is that searching should be efficient, it should have less number of computations involved.
Pointer Lecture 2 Course Name: High Level Programming Language Year : 2010.
Experimental Study on the Five Sort Algorithms You Yang, Ping Yu, Yan Gan School of Computer and Information Science Chongqing Normal University Chongqing,
Example Algorithms CSE 2320 – Algorithms and Data Structures Alexandra Stefan University of Texas at Arlington Last updated 1/31/
Tutorial 2 Control Flow: Loops NUS SCHOOL OF COMPUTING CS1010E PROGRAMMING METHODOLOGY 1 CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO.
Sorting & Searching Geletaw S (MSC, MCITP). Objectives At the end of this session the students should be able to: – Design and implement the following.
OCR A Level F453: Data structures and data manipulation Data structures and data manipulation a. explain how static data structures may be.
CMGT/410 Project Planning & Implementation Version 13 Check this A+ tutorial guideline at 410/CMGT-410-Complete-Class-Guide.
CS1010 Discussion Group 11 Week 5 – Functions, Selection, Repetition.
Searching and Sorting Algorithms
Top 50 Data Structures Interview Questions
Chapter 12 Enumerated, Structure, and Union Types Objectives
Tutorial 8 Pointers and Strings
Lesson Objectives Aims Understand the following “standard algorithms”:
Teach A level Computing: Algorithms and Data Structures
Algorithm design and Analysis
Sorting CSCE 121 J. Michael Moore
Tree A tree is a data structure in which each node is comprised of some data as well as node pointers to child nodes
Chapter 8 Arrays Objectives
Standard Version of Starting Out with C++, 4th Edition
Chapter 8 Arrays Objectives
CS250 Introduction to Computer Science II
Tutorial 6 Array Problem Solving
CSE 206 Course Review.
EE 312 Software Design and Implementation I
Algorithms and templates
Introduction to Computer Science
Presentation transcript:

Tutorial 9 String and Structure NUS SCHOOL OF COMPUTING CS1010E PROGRAMMING METHODOLOGY 1 CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO

Quick Summary 1.Structure introduces the concept of an Object. The Object can contain many attributes. (Person: Gender, Age, etc.) 1.Two ways to declare a structure: typedef struct{…}[identifier]; struct [identifier]{…}; 2.To retrieve the attributes of a structure use “.” operator: Person.Gender = “male”; Person.Age = 20; 3.For Structures with pointers: Person->Gender = “male”; Person->Age = 20; 2 CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO

Q1: Self Implementation of 3 CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO

4 Q1: Self Implementation of RADAR\0Left Right strlen = right – left; CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO

5 Q1: Self Implementation of RADAR\0 s1s1 s2s2 t CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO

6 Q1: Self Implementation of RADAR\0 RA s1s1 s2s2 t my_strcpy(s1,s2); RARADAR\0 CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO

7 Q1: Self Implementation of RADAR\0 RADAR s1s1 s2s2 Loop until (s1 becomes \0) or (a difference is found): Return the difference CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO

Q2: Christmas Carol 8 CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO

Q2: Christmas Carol 9 On any particular day: CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO Constant strings: “On the ” “day of Christmas,\n” “my true…\n” “and ”

10 Q2: Christmas Carol CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO

11 Q2: Christmas Carol CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO

12 Q2: Christmas Carol Because a word ends with either of the following: Space, Comma, Fullstop. CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO

13 Q2: Christmas Carol CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO

Q3: Overlapping Rectangles 14 CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO

Q3: Overlapping Rectangles 15 CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO

Q3: Overlapping Rectangles 16 If the points do not fulfil the pre-condition required, we just need to swap the two points. CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO

17 Q3: Overlapping Rectangles CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO

18 Q3: Overlapping Rectangles CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO It is easier to check if the two rectangles do not overlap:

19 Q3: Overlapping Rectangles CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO

Q4: Snapback Problem 20 CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO

21 Q4: Snapback Problem CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO

22 Q4: Snapback Problem CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO

23 Q4: Snapback Problem Bubble sort algorithm is used. This is an improved version of the bubble sort. What is the difference? CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO

24 Q4: Snapback Problem CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO

25 Q4: Snapback Problem CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO

26 Q4: Snapback Problem CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO 10011…110 In the binary sequence, 1 means take the item number j, 0 means omit the item number j. We use this binary sequence approach to enumerate all the possible ways to take the items available and compare the value.