SlideShare a Scribd company logo
Mutable Data, Lists,
Dictionary
Array
Searching & Multidimensional Array
List Vs Array
Which is faster/efficient
? ?
• The main difference is that arrays are allocated as a
continuous block of memory
• The Array.map function knows the size of the input
array and can perform just a single allocation to get
all memory for the resulting array.
• On the other hand, the List.map function needs to
separately allocate a single "cons cell" for each
element of the input array
List Vs Array
• However, arrays are generally faster for larger data
sets.
• Using lists has other benefits - because they are
immutable
• Also, cloning a list and adding an element to the
front is super efficient
• while doing similar operation with array would be
really slow (copy the whole array).
List Vs Array
Immutable, allows new lists to
share nodes with other lists.
List literals.
Pattern matching.
Supports mapping & folding.
Linear lookup time.
No random access to
elements, just "forward-only"
traversal.
Mutability prevents arrays from sharing
nodes with other elements in an array.
Array literals.
Pattern matching.
Good special locality of reference ensures
efficient lookup time
Constant lookup time
Not resizable.
Multi-dimensional Arrays
• A multidimensional array can be defined as an
Array of an Array.
• In F# a multidimensional array is defined in two
categories
Types
Rectangular
array
Jagged
Array
Jagged Array
• A jagged array is an array of arrays
• Whose elements are array, elements can be different dimensions
and size
• i. e Every row can have a different size
Jagged Array :Syntax
Jagged Array Creation:Example
let jaggedArray : int[][] = Array.zeroCreate 3
jaggedArray.[0] <- Array.init 1 (fun x -> x)
jaggedArray.[1] <- Array.init 2 (fun x -> x)
jaggedArray.[2] <- Array.init 3 (fun x -> x)
Output
val jaggedArray : int [] [] = [|[|0|]; [|0; 1|]; [|0; 1; 2|]|]
Jagged Array :Example
> [| for a in 1 .. 5 do yield [| 1 .. a |] |];;
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Output:
val it : int array array
= [|[|1|];
[|1; 2|];
[|1; 2; 3|];
[|1; 2; 3; 4|];
[|1; 2; 3; 4; 5|]|]
Jagged Array :Example
let jagged = [| for a in 1 .. 5 do yield [| 1 .. a |] |]
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
for arr in jagged do
for col in arr do
printf "%i " col
printfn "";;
Jagged Array :Example
let jagged = [| for a in 1 .. 5 do yield [| 1 .. a |] |]
for arr in jagged do
for col in arr do
printf "%i " col
printfn "";;
val jagged : int array array
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Rectangular Array
• A rectangular is also an
array of arrays
• All row and column
contains same number
of elements
• C, C++,Java support
jagged array but not
rectangular array
Rectangular arrays are indicated by rectangular brackets with a
comma separating them for each new dimension
Rectangular Array
• A rectangular is also an
array of arrays
• All row and column
contains same number
of elements
• C, C++,Java support
jagged array but not
rectangular array
Rectangular Array :Example
let identityMatrix : float[,] = Array2D.zeroCreate 3 3
identityMatrix.[0,0] <- 1.0
identityMatrix.[1,1] <- 1.0
identityMatrix.[2,2] <- 1.0
Output
val identityMatrix : float [,] = [1.0; 0.0; 0.0]
[0.0; 1.0; 0.0]
1.o 0.0 0.0
0.0. 1.0 0.0
0.0 0.0 1.0
Rectangular Array :Example
let grid = Array2D.init<string> 3 3 (fun row col -> sprintf "row: %i,
col: %i" row col);;
Output
> grid;;
val it : string [,]
= [|[|"row: 0, col: 0"; "row: 0, col: 1"; "row: 0, col: 2"|];
[|"row: 1, col: 0"; "row: 1, col: 1"; "row: 1, col: 2"|];
[|"row: 2, col: 0"; "row: 2, col: 1"; "row: 2, col: 2"|]|]
Searching Array
Searching
Array.find
Array.findIndex
• Takes a Boolean function and
• returns the first element for
which the function returns true,
• or raises a
System.Collections.Generic.KeyN
otFoundException if no element
that satisfies the condition is
found.
• Its like Array.find,
• except that it returns the index
of the element instead of the
element itself.
Searching Array
> // Simple Boolean function
let rec isPowerOfTwo x =
if x = 2 then
true
elif x % 2 = 1 then
false
else isPowerOfTwo (x / 2);;
val isPowerOfTwo : int -> bool
> [| 1; 7; 13; 64; 32 |]
|> Array.tryFind isPowerOfTwo;;
val it : int option = Some 64
> [| 1; 7; 13; 64; 32 |]
|> Array.tryFindIndex
isPowerOfTwo;;
val it : int option = Some 3
Assignment
Example uses array indexers to change individual characters of a
character array to implement a primitive form of encryption known
as ROT13.
ROT13 works by simply taking each letter and rotating it 13 places
forward in the alphabet.
This is achieved in the example by converting each letter to an
integer, adding 13, and then converting it back to a character.
Assignment
The output of our simple program is:
Origional = THE QUICK FOX JUMPED OVER THE LAZY DOG
Encrypted
GUR DHVPX SBK WHZCRQ BIRE GUR YNML QBT
Decrypted
THE QUICK FOX JUMPED OVER THE LAZY DOG

More Related Content

What's hot

Python list
Python listPython list
Python list
Mohammed Sikander
 
L11 array list
L11 array listL11 array list
L11 array list
teach4uin
 
Java ArrayList Tutorial | Edureka
Java ArrayList Tutorial | EdurekaJava ArrayList Tutorial | Edureka
Java ArrayList Tutorial | Edureka
Edureka!
 
Data type list_methods_in_python
Data type list_methods_in_pythonData type list_methods_in_python
Data type list_methods_in_python
deepalishinkar1
 
Array data structure
Array data structureArray data structure
Array data structure
maamir farooq
 
Array vs array list
Array vs array listArray vs array list
Array vs array list
Ravi Shetye
 
02 Arrays And Memory Mapping
02 Arrays And Memory Mapping02 Arrays And Memory Mapping
02 Arrays And Memory Mapping
Qundeel
 
Collections and generics
Collections and genericsCollections and generics
Collections and generics
Muthukumaran Subramanian
 
ArrayList in JAVA
ArrayList in JAVAArrayList in JAVA
ArrayList in JAVA
SAGARDAVE29
 
Basic data structures in python
Basic data structures in pythonBasic data structures in python
Basic data structures in python
Lifna C.S
 
Algorithms: II
Algorithms: IIAlgorithms: II
Algorithms: II
Joyjit Choudhury
 
Lecture 6 - Arrays
Lecture 6 - ArraysLecture 6 - Arrays
Lecture 6 - Arrays
Syed Afaq Shah MACS CP
 
Algorithms: I
Algorithms: IAlgorithms: I
Algorithms: I
Joyjit Choudhury
 
Concept of Stream API Java 1.8
Concept of Stream API Java 1.8Concept of Stream API Java 1.8
Concept of Stream API Java 1.8
InnovationM
 
Set methods in python
Set methods in pythonSet methods in python
Set methods in python
deepalishinkar1
 
data structures and algorithms Unit 3
data structures and algorithms Unit 3data structures and algorithms Unit 3
data structures and algorithms Unit 3
infanciaj
 
Arrays Data Structure
Arrays Data StructureArrays Data Structure
Arrays Data Structure
student
 
Python set
Python setPython set
Python set
Mohammed Sikander
 
Engineering lecture ppt by venay magen
Engineering lecture ppt by venay magenEngineering lecture ppt by venay magen
Engineering lecture ppt by venay magen
venaymagen19
 
9 python data structure-2
9 python data structure-29 python data structure-2
9 python data structure-2
Prof. Dr. K. Adisesha
 

What's hot (20)

Python list
Python listPython list
Python list
 
L11 array list
L11 array listL11 array list
L11 array list
 
Java ArrayList Tutorial | Edureka
Java ArrayList Tutorial | EdurekaJava ArrayList Tutorial | Edureka
Java ArrayList Tutorial | Edureka
 
Data type list_methods_in_python
Data type list_methods_in_pythonData type list_methods_in_python
Data type list_methods_in_python
 
Array data structure
Array data structureArray data structure
Array data structure
 
Array vs array list
Array vs array listArray vs array list
Array vs array list
 
02 Arrays And Memory Mapping
02 Arrays And Memory Mapping02 Arrays And Memory Mapping
02 Arrays And Memory Mapping
 
Collections and generics
Collections and genericsCollections and generics
Collections and generics
 
ArrayList in JAVA
ArrayList in JAVAArrayList in JAVA
ArrayList in JAVA
 
Basic data structures in python
Basic data structures in pythonBasic data structures in python
Basic data structures in python
 
Algorithms: II
Algorithms: IIAlgorithms: II
Algorithms: II
 
Lecture 6 - Arrays
Lecture 6 - ArraysLecture 6 - Arrays
Lecture 6 - Arrays
 
Algorithms: I
Algorithms: IAlgorithms: I
Algorithms: I
 
Concept of Stream API Java 1.8
Concept of Stream API Java 1.8Concept of Stream API Java 1.8
Concept of Stream API Java 1.8
 
Set methods in python
Set methods in pythonSet methods in python
Set methods in python
 
data structures and algorithms Unit 3
data structures and algorithms Unit 3data structures and algorithms Unit 3
data structures and algorithms Unit 3
 
Arrays Data Structure
Arrays Data StructureArrays Data Structure
Arrays Data Structure
 
Python set
Python setPython set
Python set
 
Engineering lecture ppt by venay magen
Engineering lecture ppt by venay magenEngineering lecture ppt by venay magen
Engineering lecture ppt by venay magen
 
9 python data structure-2
9 python data structure-29 python data structure-2
9 python data structure-2
 

Similar to F# array searching

Net (f#) array
Net (f#)  arrayNet (f#)  array
Net (f#) array
DrRajeshreeKhande
 
DS Unit 1.pptx
DS Unit 1.pptxDS Unit 1.pptx
DS Unit 1.pptx
chin463670
 
CP PPT_Unit IV computer programming in c.pdf
CP PPT_Unit IV computer programming in c.pdfCP PPT_Unit IV computer programming in c.pdf
CP PPT_Unit IV computer programming in c.pdf
saneshgamerz
 
STRINGS IN JAVA
STRINGS IN JAVASTRINGS IN JAVA
arrays-120712074248-phpapp01
arrays-120712074248-phpapp01arrays-120712074248-phpapp01
arrays-120712074248-phpapp01
Abdul Samee
 
arrays in c# including Classes handling arrays
arrays in c#  including Classes handling arraysarrays in c#  including Classes handling arrays
arrays in c# including Classes handling arrays
JayanthiM19
 
Arrays in programming
Arrays in programmingArrays in programming
Arrays in programming
TaseerRao
 
Data structures
Data structuresData structures
Data structures
Manaswi Sharma
 
javascript-Array.ppsx
javascript-Array.ppsxjavascript-Array.ppsx
javascript-Array.ppsx
VedantSaraf9
 
Underscore.js
Underscore.jsUnderscore.js
Underscore.js
timourian
 
Array
ArrayArray
Array
PRN USM
 
One dimensional 2
One dimensional 2One dimensional 2
One dimensional 2
Rajendran
 
collection framework.pptx
collection framework.pptxcollection framework.pptx
collection framework.pptx
SoniaKapoor56
 
Collections
CollectionsCollections
Collections
Manav Prasad
 
22.ppt
22.ppt22.ppt
Collections in Java
Collections in JavaCollections in Java
Collections in Java
Khasim Cise
 
Arrays
ArraysArrays
Array in C# 3.5
Array in C# 3.5Array in C# 3.5
Array in C# 3.5
Gopal Ji Singh
 
Collections
CollectionsCollections
Collections
Rajkattamuri
 
Data structures arrays
Data structures   arraysData structures   arrays
Data structures arrays
maamir farooq
 

Similar to F# array searching (20)

Net (f#) array
Net (f#)  arrayNet (f#)  array
Net (f#) array
 
DS Unit 1.pptx
DS Unit 1.pptxDS Unit 1.pptx
DS Unit 1.pptx
 
CP PPT_Unit IV computer programming in c.pdf
CP PPT_Unit IV computer programming in c.pdfCP PPT_Unit IV computer programming in c.pdf
CP PPT_Unit IV computer programming in c.pdf
 
STRINGS IN JAVA
STRINGS IN JAVASTRINGS IN JAVA
STRINGS IN JAVA
 
arrays-120712074248-phpapp01
arrays-120712074248-phpapp01arrays-120712074248-phpapp01
arrays-120712074248-phpapp01
 
arrays in c# including Classes handling arrays
arrays in c#  including Classes handling arraysarrays in c#  including Classes handling arrays
arrays in c# including Classes handling arrays
 
Arrays in programming
Arrays in programmingArrays in programming
Arrays in programming
 
Data structures
Data structuresData structures
Data structures
 
javascript-Array.ppsx
javascript-Array.ppsxjavascript-Array.ppsx
javascript-Array.ppsx
 
Underscore.js
Underscore.jsUnderscore.js
Underscore.js
 
Array
ArrayArray
Array
 
One dimensional 2
One dimensional 2One dimensional 2
One dimensional 2
 
collection framework.pptx
collection framework.pptxcollection framework.pptx
collection framework.pptx
 
Collections
CollectionsCollections
Collections
 
22.ppt
22.ppt22.ppt
22.ppt
 
Collections in Java
Collections in JavaCollections in Java
Collections in Java
 
Arrays
ArraysArrays
Arrays
 
Array in C# 3.5
Array in C# 3.5Array in C# 3.5
Array in C# 3.5
 
Collections
CollectionsCollections
Collections
 
Data structures arrays
Data structures   arraysData structures   arrays
Data structures arrays
 

More from DrRajeshreeKhande

.NET F# Inheritance and operator overloading
.NET F# Inheritance and operator overloading.NET F# Inheritance and operator overloading
.NET F# Inheritance and operator overloading
DrRajeshreeKhande
 
Exception Handling in .NET F#
Exception Handling in .NET F#Exception Handling in .NET F#
Exception Handling in .NET F#
DrRajeshreeKhande
 
.NET F# Events
.NET F# Events.NET F# Events
.NET F# Events
DrRajeshreeKhande
 
.NET F# Class constructor
.NET F# Class constructor.NET F# Class constructor
.NET F# Class constructor
DrRajeshreeKhande
 
.NET F# Abstract class interface
.NET F# Abstract class interface.NET F# Abstract class interface
.NET F# Abstract class interface
DrRajeshreeKhande
 
.Net F# Generic class
.Net F# Generic class.Net F# Generic class
.Net F# Generic class
DrRajeshreeKhande
 
F# Console class
F# Console classF# Console class
F# Console class
DrRajeshreeKhande
 
.net F# mutable dictionay
.net F# mutable dictionay.net F# mutable dictionay
.net F# mutable dictionay
DrRajeshreeKhande
 
F sharp lists & dictionary
F sharp   lists &  dictionaryF sharp   lists &  dictionary
F sharp lists & dictionary
DrRajeshreeKhande
 
.Net (F # ) Records, lists
.Net (F # ) Records, lists.Net (F # ) Records, lists
.Net (F # ) Records, lists
DrRajeshreeKhande
 
MS Office for Beginners
MS Office for BeginnersMS Office for Beginners
MS Office for Beginners
DrRajeshreeKhande
 
Java Multi-threading programming
Java Multi-threading programmingJava Multi-threading programming
Java Multi-threading programming
DrRajeshreeKhande
 
Java String class
Java String classJava String class
Java String class
DrRajeshreeKhande
 
JAVA AWT components
JAVA AWT componentsJAVA AWT components
JAVA AWT components
DrRajeshreeKhande
 
Dr. Rajeshree Khande :Introduction to Java AWT
Dr. Rajeshree Khande :Introduction to Java AWTDr. Rajeshree Khande :Introduction to Java AWT
Dr. Rajeshree Khande :Introduction to Java AWT
DrRajeshreeKhande
 
Dr. Rajeshree Khande Java Interactive input
Dr. Rajeshree Khande Java Interactive inputDr. Rajeshree Khande Java Interactive input
Dr. Rajeshree Khande Java Interactive input
DrRajeshreeKhande
 
Dr. Rajeshree Khande :Intoduction to java
Dr. Rajeshree Khande :Intoduction to javaDr. Rajeshree Khande :Intoduction to java
Dr. Rajeshree Khande :Intoduction to java
DrRajeshreeKhande
 
Java Exceptions Handling
Java Exceptions Handling Java Exceptions Handling
Java Exceptions Handling
DrRajeshreeKhande
 
Dr. Rajeshree Khande : Java Basics
Dr. Rajeshree Khande  : Java BasicsDr. Rajeshree Khande  : Java Basics
Dr. Rajeshree Khande : Java Basics
DrRajeshreeKhande
 

More from DrRajeshreeKhande (19)

.NET F# Inheritance and operator overloading
.NET F# Inheritance and operator overloading.NET F# Inheritance and operator overloading
.NET F# Inheritance and operator overloading
 
Exception Handling in .NET F#
Exception Handling in .NET F#Exception Handling in .NET F#
Exception Handling in .NET F#
 
.NET F# Events
.NET F# Events.NET F# Events
.NET F# Events
 
.NET F# Class constructor
.NET F# Class constructor.NET F# Class constructor
.NET F# Class constructor
 
.NET F# Abstract class interface
.NET F# Abstract class interface.NET F# Abstract class interface
.NET F# Abstract class interface
 
.Net F# Generic class
.Net F# Generic class.Net F# Generic class
.Net F# Generic class
 
F# Console class
F# Console classF# Console class
F# Console class
 
.net F# mutable dictionay
.net F# mutable dictionay.net F# mutable dictionay
.net F# mutable dictionay
 
F sharp lists & dictionary
F sharp   lists &  dictionaryF sharp   lists &  dictionary
F sharp lists & dictionary
 
.Net (F # ) Records, lists
.Net (F # ) Records, lists.Net (F # ) Records, lists
.Net (F # ) Records, lists
 
MS Office for Beginners
MS Office for BeginnersMS Office for Beginners
MS Office for Beginners
 
Java Multi-threading programming
Java Multi-threading programmingJava Multi-threading programming
Java Multi-threading programming
 
Java String class
Java String classJava String class
Java String class
 
JAVA AWT components
JAVA AWT componentsJAVA AWT components
JAVA AWT components
 
Dr. Rajeshree Khande :Introduction to Java AWT
Dr. Rajeshree Khande :Introduction to Java AWTDr. Rajeshree Khande :Introduction to Java AWT
Dr. Rajeshree Khande :Introduction to Java AWT
 
Dr. Rajeshree Khande Java Interactive input
Dr. Rajeshree Khande Java Interactive inputDr. Rajeshree Khande Java Interactive input
Dr. Rajeshree Khande Java Interactive input
 
Dr. Rajeshree Khande :Intoduction to java
Dr. Rajeshree Khande :Intoduction to javaDr. Rajeshree Khande :Intoduction to java
Dr. Rajeshree Khande :Intoduction to java
 
Java Exceptions Handling
Java Exceptions Handling Java Exceptions Handling
Java Exceptions Handling
 
Dr. Rajeshree Khande : Java Basics
Dr. Rajeshree Khande  : Java BasicsDr. Rajeshree Khande  : Java Basics
Dr. Rajeshree Khande : Java Basics
 

Recently uploaded

The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5
sayalidalavi006
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 

Recently uploaded (20)

The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 

F# array searching

  • 2. List Vs Array Which is faster/efficient ? ? • The main difference is that arrays are allocated as a continuous block of memory • The Array.map function knows the size of the input array and can perform just a single allocation to get all memory for the resulting array. • On the other hand, the List.map function needs to separately allocate a single "cons cell" for each element of the input array
  • 3. List Vs Array • However, arrays are generally faster for larger data sets. • Using lists has other benefits - because they are immutable • Also, cloning a list and adding an element to the front is super efficient • while doing similar operation with array would be really slow (copy the whole array).
  • 4. List Vs Array Immutable, allows new lists to share nodes with other lists. List literals. Pattern matching. Supports mapping & folding. Linear lookup time. No random access to elements, just "forward-only" traversal. Mutability prevents arrays from sharing nodes with other elements in an array. Array literals. Pattern matching. Good special locality of reference ensures efficient lookup time Constant lookup time Not resizable.
  • 5. Multi-dimensional Arrays • A multidimensional array can be defined as an Array of an Array. • In F# a multidimensional array is defined in two categories Types Rectangular array Jagged Array
  • 6. Jagged Array • A jagged array is an array of arrays • Whose elements are array, elements can be different dimensions and size • i. e Every row can have a different size
  • 8. Jagged Array Creation:Example let jaggedArray : int[][] = Array.zeroCreate 3 jaggedArray.[0] <- Array.init 1 (fun x -> x) jaggedArray.[1] <- Array.init 2 (fun x -> x) jaggedArray.[2] <- Array.init 3 (fun x -> x) Output val jaggedArray : int [] [] = [|[|0|]; [|0; 1|]; [|0; 1; 2|]|]
  • 9. Jagged Array :Example > [| for a in 1 .. 5 do yield [| 1 .. a |] |];; 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 Output: val it : int array array = [|[|1|]; [|1; 2|]; [|1; 2; 3|]; [|1; 2; 3; 4|]; [|1; 2; 3; 4; 5|]|]
  • 10. Jagged Array :Example let jagged = [| for a in 1 .. 5 do yield [| 1 .. a |] |] 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 for arr in jagged do for col in arr do printf "%i " col printfn "";;
  • 11. Jagged Array :Example let jagged = [| for a in 1 .. 5 do yield [| 1 .. a |] |] for arr in jagged do for col in arr do printf "%i " col printfn "";; val jagged : int array array 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5
  • 12. Rectangular Array • A rectangular is also an array of arrays • All row and column contains same number of elements • C, C++,Java support jagged array but not rectangular array Rectangular arrays are indicated by rectangular brackets with a comma separating them for each new dimension
  • 13. Rectangular Array • A rectangular is also an array of arrays • All row and column contains same number of elements • C, C++,Java support jagged array but not rectangular array
  • 14. Rectangular Array :Example let identityMatrix : float[,] = Array2D.zeroCreate 3 3 identityMatrix.[0,0] <- 1.0 identityMatrix.[1,1] <- 1.0 identityMatrix.[2,2] <- 1.0 Output val identityMatrix : float [,] = [1.0; 0.0; 0.0] [0.0; 1.0; 0.0] 1.o 0.0 0.0 0.0. 1.0 0.0 0.0 0.0 1.0
  • 15. Rectangular Array :Example let grid = Array2D.init<string> 3 3 (fun row col -> sprintf "row: %i, col: %i" row col);; Output > grid;; val it : string [,] = [|[|"row: 0, col: 0"; "row: 0, col: 1"; "row: 0, col: 2"|]; [|"row: 1, col: 0"; "row: 1, col: 1"; "row: 1, col: 2"|]; [|"row: 2, col: 0"; "row: 2, col: 1"; "row: 2, col: 2"|]|]
  • 16. Searching Array Searching Array.find Array.findIndex • Takes a Boolean function and • returns the first element for which the function returns true, • or raises a System.Collections.Generic.KeyN otFoundException if no element that satisfies the condition is found. • Its like Array.find, • except that it returns the index of the element instead of the element itself.
  • 17. Searching Array > // Simple Boolean function let rec isPowerOfTwo x = if x = 2 then true elif x % 2 = 1 then false else isPowerOfTwo (x / 2);; val isPowerOfTwo : int -> bool > [| 1; 7; 13; 64; 32 |] |> Array.tryFind isPowerOfTwo;; val it : int option = Some 64 > [| 1; 7; 13; 64; 32 |] |> Array.tryFindIndex isPowerOfTwo;; val it : int option = Some 3
  • 18. Assignment Example uses array indexers to change individual characters of a character array to implement a primitive form of encryption known as ROT13. ROT13 works by simply taking each letter and rotating it 13 places forward in the alphabet. This is achieved in the example by converting each letter to an integer, adding 13, and then converting it back to a character.
  • 19. Assignment The output of our simple program is: Origional = THE QUICK FOX JUMPED OVER THE LAZY DOG Encrypted GUR DHVPX SBK WHZCRQ BIRE GUR YNML QBT Decrypted THE QUICK FOX JUMPED OVER THE LAZY DOG