Project 1 Sequence CS 211 – Fall 2017.

Slides:



Advertisements
Similar presentations
Back to Sorting – More efficient sorting algorithms.
Advertisements

Basic Algorithms on Arrays. Learning Objectives Arrays are useful for storing data in a linear structure We learn how to process data stored in an array.
June Searching CE : Fundamental Programming Techniques 16 Searching1.
 2003 Prentice Hall, Inc. All rights reserved. 1 Sorting Arrays Sorting data –Important computing application –Virtually every organization must sort.
CS 106 Introduction to Computer Science I 03 / 07 / 2008 Instructor: Michael Eckmann.
Array Must declare a variable to reference the array double [] mylist; // cannot double list[20]; Or double mylist[]; The declaration doesn’t allocate.
Sorting and Searching Algorithms Week 11 DSA. Recap etc. Arrays are lists of data 1-D, 2-D etc. Lists associated with searching and sorting Other structures.
CS 106 Introduction to Computer Science I 10 / 16 / 2006 Instructor: Michael Eckmann.
Discussion Section: HW1 and Programming Tips GS540.
1.7 Arrays academy.zariba.com 1. Lecture Content 1.Basic Operations with Arrays 2.Console Input & Output of Arrays 3.Iterating Over Arrays 4.List 5.Cloning.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic concepts and uses of arrays ❏ To be able to define C.
Chapter Complexity of Algorithms –Time Complexity –Understanding the complexity of Algorithms 1.
 2004 Prentice Hall, Inc. All rights reserved. 1 Chapter 11 - JavaScript: Arrays Outline 11.1 Introduction 11.2 Arrays 11.3 Declaring and Allocating Arrays.
MIPS coding. SPIM Some links can be found such as:
STRINGS & STRING HANDLING FUNCTIONS STRINGS & STRING HANDLING FUNCTIONS.
1 Searching. 2 Searching Searching refers to the operation of finding an item from a list of items based on some key value. Two Searching Methods (1)
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 12: Pointers continued, C strings.
CIS250 OPERATING SYSTEMS Memory Management Since we share memory, we need to manage it Memory manager only sees the address A program counter value indicates.
1 Lecture 5: Part 1 Searching Arrays Searching Arrays: Linear Search and Binary Search Search array for a key value Linear search  Compare each.
Arrays.
MEMORY ORGANIZTION & ADDRESSING Presented by: Bshara Choufany.
1 Section 2.1 Algorithms. 2 Algorithm A finite set of precise instructions for performing a computation or for solving a problem.
Week # 2: Arrays.  Data structure  A particular way of storing and organising data in a computer so that it can be used efficiently  Types of data.
1 CSCD 326 Data Structures I Hashing. 2 Hashing Background Goal: provide a constant time complexity method of searching for stored data The best traditional.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Searching When we maintain a collection of data,
CS 106 Introduction to Computer Science I 03 / 02 / 2007 Instructor: Michael Eckmann.
CS Fall 2009 Sorted List Sets. What is the use of sorting? Remember we sorted a dynamic array so that we could use binary search. There would seem.
Data Structure and Algorithms
 2008 Pearson Education, Inc. All rights reserved JavaScript: Arrays.
Searching and Sorting Arrays Shirley Moore CS 1401 Spring 2013 cs1401spring2013.pbworks.com April 15-16, 2013.
Searching and Sorting Searching algorithms with simple arrays
Chapter 11 - JavaScript: Arrays
Growth of Functions & Algorithms
Pointers & Arrays 1-d arrays & pointers 2-d arrays & pointers.
Indexing Goals: Store large files Support multiple search keys
Data Structure Interview Question and Answers
Lecture – 2 on Data structures
Hashing CSE 2011 Winter July 2018.
Data Structures Interview / VIVA Questions and Answers
C++ Interlude 2 Pointers, Polymorphism, and Memory Allocation
Review Graph Directed Graph Undirected Graph Sub-Graph
Chapter 8 Arrays Objectives
Algorithms + Data Structures = Programs -Niklaus Wirth
Arrays An Array is an ordered collection of variables
Chapter 6 - Arrays Outline 6.1 Introduction 6.2 Arrays
Arrays and Linked Lists
Hw 5 Hints.
CS Week 9 Jim Williams, PhD.
كلية المجتمع الخرج البرمجة - المستوى الثاني
Chapter 8 Arrays Objectives
searching Concept: Linear search Binary search
CISC181 Introduction to Computer Science Dr
Algorithms + Data Structures = Programs -Niklaus Wirth
Lecture 15 Reading: Bacon 7.6, 7.7
25 Searching and Sorting Many slides modified by Prof. L. Lilien (even many without an explicit message indicating an update). Slides added or modified.
Binary Trees (and Big “O” notation)
CS2011 Introduction to Programming I Arrays (I)
Linear Search Binary Search Tree
24 Searching and Sorting.
Data Structures (CS212D) Week # 2: Arrays.
Given value and sorted array, find index.
7 Arrays.
EECE.2160 ECE Application Programming
Chapter 8 Arrays Objectives
A Wide Array of Possibilities
Arrays.
Priority Queues & Heaps
Linear and Binary Search
C Structures and Commands
Algorithm Course Algorithms Lecture 3 Sorting Algorithm-1
Presentation transcript:

Project 1 Sequence CS 211 – Fall 2017

Step 1 – read in data & store in array Data file contains multiple integers with two values of -999 7537 8410 3756 7667 5312 2062 4136 6846 9902 -999 4136 129 6846 902 -999

Step 1 – read in data & store in array Data file contains multiple integers with two values of -999 7537 8410 3756 7667 5312 2062 4136 6846 9902 -999 4136 129 6846 902 -999 Data to be stored in the array

Step 1 – read in data & store in array Data file contains multiple integers with two values of -999 7537 8410 3756 7667 5312 2062 4136 6846 9902 -999 4136 129 6846 902 -999 Data to be stored in the array Data to use for searching

Step 1 – read in data & store in array First read in values until first -999 is encountered Store these values into an array arr1: 7537 8410 3756 7667 5312 2062 4136 6846 9902 Dynamic Memory Allocation discussed a bit later

Step 2 – Make of copy of the array Allocated enough space for the copy Call arrayCopy() to transfer values arr1: 7537 8410 3756 7667 5312 2062 4136 6846 9902 arr2: 7537 8410 3756 7667 5312 2062 4136 6846 9902

Step 3 – Sort one of the arrays Call myFavorateSort() “Write your own function….” i.e. you can’t call a library routine arr1: 7537 8410 3756 7667 5312 2062 4136 6846 9902 arr2: 2062 3756 4136 5312 6846 7537 7667 8410 9902

Step 4 – read in the search data Loop until second value of -999 is encountered For each value, call both linearSearch() and binarySearch() Print our results in main() or whichever function calls the searches 7537 8410 3756 7667 5312 2062 4136 6846 9902 -999 4136 129 6846 902 -999 Data to use for searching

Step 4 – Doing the Search First value is 4136 Linear Search: Found at position: 6 Number of Comparisons: 7 0 1 2 3 4 5 6 7 8 arr1: 7537 8410 3756 7667 5312 2062 4136 6846 9902 arr2: 2062 3756 4136 5312 6846 7537 7667 8410 9902

Step 4 – Doing the Search First value is 4136 Binary Search: Found at position: 2 Number of Comparisons: 3 0 1 2 3 4 5 6 7 8 arr1: 7537 8410 3756 7667 5312 2062 4136 6846 9902 arr2: 2062 3756 4136 5312 6846 7537 7667 8410 9902 Positions visited: 4 (l: 0, h: 8, m: 4), 1 (l: 0, h: 3, m: 1), 2 (l: 2, h: 3, m: 2)

Step 4 – Doing the Search Second value is 129 Linear Search: Not Found at position: -1 Number of Comparisons: 9 0 1 2 3 4 5 6 7 8 arr1: 7537 8410 3756 7667 5312 2062 4136 6846 9902 arr2: 2062 3756 4136 5312 6846 7537 7667 8410 9902

Step 4 – Doing the Search Second value is 129 Binary Search: Not Found at position: -1 Number of Comp: 4 0 1 2 3 4 5 6 7 8 arr1: 7537 8410 3756 7667 5312 2062 4136 6846 9902 arr2: 2062 3756 4136 5312 6846 7537 7667 8410 9902 Positions visited: 4 (l: 0, h: 8, m: 4), 1 (l: 0, h: 3, m: 1), 0 (l: 0, h: 0, m: 0) , NF (l: 0, h: -1, m: NF)