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.

Slides:



Advertisements
Similar presentations
Sorting algorithms Sieve of Eratosthenes
Advertisements

Lecture 6 Sept 11, 2008 Goals for the day: Linked list and project # 1 list class in STL (section 3.3) stack – implementation and applications.
One Dimensional Arrays
Order Analysis of Algorithms Debdeep Mukhopadhyay IIT Madras.
Analysis of Algorithms
Hashing as a Dictionary Implementation
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.
Dynamic Arrays Lecture 4. Arrays In many languages the size of the array is fixed however in perl an array is considered to be dynamic: its size can be.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
HST 952 Computing for Biomedical Scientists Lecture 9.
Advanced Topics in Algorithms and Data Structures Lecture 6.1 – pg 1 An overview of lecture 6 A parallel search algorithm A parallel merging algorithm.
Binary Search Visualization i j.
Simple Arrays COMP104 Lecture 11 / Slide 2 Arrays * An array is a collection of data elements that are of the same type (e.g., a collection of integers,characters,
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 12: Arrays.
Processing Sequences of Elements Telerik School Academy C# Fundamentals – Part 1.
Introducing Hashing Chapter 21 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Simple Arrays Programming COMP104 Lecture 12 / Slide 2 Arrays l An array is a collection of data elements that are of the same type (e.g., a collection.
Sanjay Goel, School of Business, University at Albany, SUNY 1 MSI 692: Special Topics in Information Technology Lecture 4: Strings & Arrays Sanjay Goel.
1.10 Strings academy.zariba.com 1. Lecture Content 1.What is a string? 2.Creating and Using strings 3.Manipulating Strings 4.Other String Operations 5.Building.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic concepts and uses of arrays ❏ To be able to define C.
ALGORITHM ANALYSIS AND DESIGN INTRODUCTION TO ALGORITHMS CS 413 Divide and Conquer Algortihms: Binary search, merge sort.
1 Efficiency of Algorithms: Logarithmic Orders Binary Search Algorithm.
CS261 Data Structures Hash Tables Concepts. Goals Hash Functions Dealing with Collisions.
Part 2. Searching Arrays Looking for a specific element in an array E.g., whether a certain score (85) is in a list of scores Linear search Binary search.
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 13 – Having Fun with Arrays in Java Webpage:
The University of Texas – Pan American
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Chapter 13 - Recursion.
Handling Lists F. Duveau 16/12/11 Chapter 9.2. Objectives of the session: Tools: Everything will be done with the Python interpreter in the Terminal Learning.
1.6 Loops academy.zariba.com 1. Lecture Content 1.While loops 2.Do-While loops 3.For loops 4.Foreach loops 5.Loop operators – break, continue 6.Nested.
1.3 Console Input And Output academy.zariba.com 1.
© 2004 Pearson Addison-Wesley. All rights reserved October 17, 2007 Searching (part 2) ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
Lecture Contents Arrays and Vectors: Concepts of array. Memory index of array. Defining and Initializing an array. Processing an array. Parsing an array.
Processing Sequences of Elements Svetlin Nakov Telerik Corporation
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
Design of Algorithms using Brute Force Approach. Primality Testing (given number is n binary digits)
5.6 Generating Permutations and Combinations Generating Permutations Many different algorithms have been developed to generate the n! permutations of this.
Topic 25 - more array algorithms 1 "To excel in Java, or any computer language, you want to build skill in both the "large" and "small". By "large" I mean.
1.5 Conditional Statements academy.zariba.com 1. Lecture Content 1.If-else statements 2.If-else-if statements 3.Switch-case statements 2.
Advanced Computer Science Lesson 4: Reviewing Loops and Arrays Reading User Input.
Chapter 8 Arrays Instructor: Kun-Mao Chao ( 台大資工 趙坤茂 )
Arrays, Lists, Stacks, Queues Processing Sequences of Elements SoftUni Team Technical Trainers Software University
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.
C Programming – Part 3 Arrays and Strings.  Collection of variables of the same type  Individual array elements are identified by an integer index 
1 Introduction  Algorithms  Data structures  Abstract data types  Programming with lists and sets © 2008 David A Watt, University of Glasgow Algorithms.
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
Processing Sequences of Elements Technical Trainer Telerik Corporation Doncho Minkov.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Elementary Data Structures Array Lists Array Lists Dale.
1.2 Primitive Data Types and Variables
COMPUTER PROGRAMMING 2 ArrayLists. Objective/Essential Standard Essential Standard 3.00Apply Advanced Properties of Arrays Essential Indicator 3.02 Apply.
Selection Sort main( ) { int a[ ] = { 17, 6, 13,12, 2 } ; int i, j, t ; for ( i = 0 ; i
Recursion and Combinatorial Algorithms academy.zariba.com 1.
CSCI 383 Object-Oriented Programming & Design Lecture 25 Martin van Bommel.
Data Handling in Algorithms. Activity 1 Starter Task: Quickly complete the sheet 5mins!
1.8 Multidimensional Arrays academy.zariba.com 1.
CSCI-383 Object-Oriented Programming & Design Lecture 30.
Introduction to JavaScript academy.zariba.com 1. Lecture Content 1.What is JavaScript? 2.JavaScript Pros and Cons 3.The weird JavaScript stuff 4.Including.
Introduction to programming in java Lecture 21 Arrays – Part 1.
C++ Memory Management – Homework Exercises
Processing Sequences of Elements
Arrays, Lists, Stacks, Queues
2.2 Defining Classes Part 2 academy.zariba.com.
Chapter 8 Arrays Objectives
Chapter 8 Arrays Objectives
Introduction To Programming Information Technology , 1’st Semester
CS2011 Introduction to Programming I Arrays (I)
Chapter 8 Arrays Objectives
Object Oriented Programming
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays – Exercises UTPA – Fall 2012 This set of slides is revised from lecture slides of Prof.
Presentation transcript:

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 Arrays 2

What is an Array 3 An array is a sequence of elements of the same type. It has a fixed order of the elements and a fixed size.

1. Basic Operations with Arrays 4 Declaring, initializing, accessing elements with examples.

2. Console Input Output of Arrays 5

3. Iterating Over Arrays 6 Iteration using for and foreach.

4. List 7 List is a dynamically resizable array. “T” stands for any data type, e.g. int, string, char…

5. Cloning arrays 8

Homework 9 1.Write a program that allocates array of 20 integers and initializes each element by its index multiplied by 5. Print the obtained array on the console. 2.Write a program that reads two arrays from the console and compares them element by element. char 3.Write a program that compares two char arrays lexicographically (letter by letter). 2, 2, 2 4.Write a program that finds the maximal sequence of equal elements in an array. Example: {2, 1, 1, 2, 3, 3, 2, 2, 2, 1}  {2, 2, 2}. 2, 3, 4 5.Write a program that finds the maximal increasing sequence in an array. Example: {3, 2, 3, 4, 2, 2, 4}  {2, 3, 4}. 6.Write a program that reads two integer numbers N and K and an array of N elements from the console. Find in the array those K elements that have maximal sum. 7.Sorting an array means to arrange its elements in increasing order. Write a program to sort an array. Use the "selection sort" algorithm. Hint: Search on Google.

Homework 10 2, -1, 6, 4 8.Write a program that finds the sequence of maximal sum in given array. Example: {2, 3, -6, -1, 2, -1, 6, 4, -8, 8}  {2, -1, 6, 4} Can you do it with only one loop (with single scan through the elements of the array)? 9.Write a program that finds the most frequent number in an array. Example: {4, 1, 1, 4, 2, 3, 4, 4, 1, 2, 4, 9, 3}  4 (5 times) Write a program that finds in given array of integers a sequence of given sum S (if present). Example: {4, 3, 1, 4, 2, 5, 8}, S=11  {4, 2, 5} 11.Write a program that finds the index of given element in a sorted array of integers by using the binary search algorithm (find it in Wikipedia).binary search 12.Write a program that creates an array containing all letters from the alphabet (A-Z). Read a word from the console and print the index of each of its letters in the array. 13.Write a program that sorts an array of strings using the quick sort algorithm. Search on Google.quick sort

Homework Write a program that finds all prime numbers in the range [ ]. Use the sieve of Eratosthenes algorithm (find it in Wikipedia).sieve of Eratosthenes * We are given an array of integers and a number S. Write a program to find if there exists a subset of the elements of the array that has a sum S. Example: arr={2, 1, 2, 4, 3, 5, 2, 6}, S=14  yes ( ) 16. * Write a program that reads three integer numbers N, K and S and an array of N elements from the console. Find in the array a subset of K elements that have sum S or indicate about its absence. 17. * Write a program that reads an array of integers and removes from it a minimal number of elements in such way that the remaining array is sorted in increasing order. Print the remaining sorted array. Example: {6, 1, 4, 3, 0, 3, 6, 4, 5}  {1, 3, 3, 4, 5} 18. * Write a program that reads a number N and generates and prints all the permutations of the numbers [1 … N]. Example: n = 3  {1, 2, 3}, {1, 3, 2}, {2, 1, 3}, {2, 3, 1}, {3, 1, 2}, {3, 2, 1}

Homework Write a program that reads two numbers N and K and generates all the variations of K elements from the set [1..N]. Example: N = 3, K = 2  {1, 1}, {1, 2}, {1, 3}, {2, 1}, {2, 2}, {2, 3}, {3, 1}, {3, 2}, {3, 3} 20. Write a program that reads two numbers N and K and generates all the combinations of K distinct elements from the set [1..N]. Example: N = 5, K = 2  {1, 2}, {1, 3}, {1, 4}, {1, 5}, {2, 3}, {2, 4}, {2, 5}, {3, 4}, {3, 5}, {4, 5}

13 References

14 Zariba Academy Questions