SlideShare a Scribd company logo
1 of 19
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

L11 array list
L11 array listL11 array list
L11 array listteach4uin
 
Java ArrayList Tutorial | Edureka
Java ArrayList Tutorial | EdurekaJava ArrayList Tutorial | Edureka
Java ArrayList Tutorial | EdurekaEdureka!
 
Data type list_methods_in_python
Data type list_methods_in_pythonData type list_methods_in_python
Data type list_methods_in_pythondeepalishinkar1
 
Array data structure
Array data structureArray data structure
Array data structuremaamir farooq
 
Array vs array list
Array vs array listArray vs array list
Array vs array listRavi Shetye
 
02 Arrays And Memory Mapping
02 Arrays And Memory Mapping02 Arrays And Memory Mapping
02 Arrays And Memory MappingQundeel
 
ArrayList in JAVA
ArrayList in JAVAArrayList in JAVA
ArrayList in JAVASAGARDAVE29
 
Basic data structures in python
Basic data structures in pythonBasic data structures in python
Basic data structures in pythonLifna C.S
 
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.8InnovationM
 
Set methods in python
Set methods in pythonSet methods in python
Set methods in pythondeepalishinkar1
 
data structures and algorithms Unit 3
data structures and algorithms Unit 3data structures and algorithms Unit 3
data structures and algorithms Unit 3infanciaj
 
Arrays Data Structure
Arrays Data StructureArrays Data Structure
Arrays Data Structurestudent
 
Engineering lecture ppt by venay magen
Engineering lecture ppt by venay magenEngineering lecture ppt by venay magen
Engineering lecture ppt by venay magenvenaymagen19
 

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 Mutable Data, Lists, Dictionaries and Arrays in F

DS Unit 1.pptx
DS Unit 1.pptxDS Unit 1.pptx
DS Unit 1.pptxchin463670
 
arrays-120712074248-phpapp01
arrays-120712074248-phpapp01arrays-120712074248-phpapp01
arrays-120712074248-phpapp01Abdul 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 arraysJayanthiM19
 
Arrays in programming
Arrays in programmingArrays in programming
Arrays in programmingTaseerRao
 
javascript-Array.ppsx
javascript-Array.ppsxjavascript-Array.ppsx
javascript-Array.ppsxVedantSaraf9
 
Underscore.js
Underscore.jsUnderscore.js
Underscore.jstimourian
 
Array
ArrayArray
ArrayPRN USM
 
One dimensional 2
One dimensional 2One dimensional 2
One dimensional 2Rajendran
 
collection framework.pptx
collection framework.pptxcollection framework.pptx
collection framework.pptxSoniaKapoor56
 
Collections in Java
Collections in JavaCollections in Java
Collections in JavaKhasim Cise
 
Data structures arrays
Data structures   arraysData structures   arrays
Data structures arraysmaamir farooq
 
12_-_Collections_Framework
12_-_Collections_Framework12_-_Collections_Framework
12_-_Collections_FrameworkKrishna Sujeer
 

Similar to Mutable Data, Lists, Dictionaries and Arrays in F (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
 
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
 
12_-_Collections_Framework
12_-_Collections_Framework12_-_Collections_Framework
12_-_Collections_Framework
 

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 overloadingDrRajeshreeKhande
 
Exception Handling in .NET F#
Exception Handling in .NET F#Exception Handling in .NET F#
Exception Handling in .NET F#DrRajeshreeKhande
 
.NET F# Class constructor
.NET F# Class constructor.NET F# Class constructor
.NET F# Class constructorDrRajeshreeKhande
 
.NET F# Abstract class interface
.NET F# Abstract class interface.NET F# Abstract class interface
.NET F# Abstract class interfaceDrRajeshreeKhande
 
.net F# mutable dictionay
.net F# mutable dictionay.net F# mutable dictionay
.net F# mutable dictionayDrRajeshreeKhande
 
F sharp lists & dictionary
F sharp   lists &  dictionaryF sharp   lists &  dictionary
F sharp lists & dictionaryDrRajeshreeKhande
 
.Net (F # ) Records, lists
.Net (F # ) Records, lists.Net (F # ) Records, lists
.Net (F # ) Records, listsDrRajeshreeKhande
 
MS Office for Beginners
MS Office for BeginnersMS Office for Beginners
MS Office for BeginnersDrRajeshreeKhande
 
Java Multi-threading programming
Java Multi-threading programmingJava Multi-threading programming
Java Multi-threading programmingDrRajeshreeKhande
 
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 AWTDrRajeshreeKhande
 
Dr. Rajeshree Khande Java Interactive input
Dr. Rajeshree Khande Java Interactive inputDr. Rajeshree Khande Java Interactive input
Dr. Rajeshree Khande Java Interactive inputDrRajeshreeKhande
 
Dr. Rajeshree Khande :Intoduction to java
Dr. Rajeshree Khande :Intoduction to javaDr. Rajeshree Khande :Intoduction to java
Dr. Rajeshree Khande :Intoduction to javaDrRajeshreeKhande
 
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 BasicsDrRajeshreeKhande
 

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

Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)Dr. Mazin Mohamed alkathiri
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 

Recently uploaded (20)

Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 

Mutable Data, Lists, Dictionaries and Arrays in F

  • 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