Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Swift > 3
1. TSX.V V H I
CONFIDENTIAL • NOT FOR REDISTRIBUTION • August 2019
SWIFT Part I
2. TSX.V V H I
Plan for next few weeks
Part 1
• Introducing the Xcode Playground
• Introduction to the language with hashing
Part II
• Introduction to object comparison
Part III
• We’ll make a small BMI calculator app in Xcode – part A
• We’ll make a small BMI calculator in Xcode – part B ( only If !(fired by then ||
Dead) )2
3. TSX.V V H I
Hashing revisited
3
Introduction to Algorithms, 3rd Edition (The MIT Press): Thomas H Cormen
Recap of Big Theta
4. TSX.V V H I
Possible complexities
4
https://www.bigocheatsheet.com/
5. TSX.V V H I
Hashing revisited
5
https://www.bigocheatsheet.com/
6. TSX.V V H I
A practical scenario
• Finding Lolah’s contact
in my contact list
6
Hi
Handsome!
I’m from
Uzbekistan
7. TSX.V V H I
Array average case 𝜃(n)
7
Lolah
Lolah
n1
n2
n1/2
n2/2
n1 << n2
So that, in general
t ∝ n ∝ n/2
8. TSX.V V H I
Array worst case O(n)
8
Lolah
Lolah
n1
n2
n1 << n2
So that, in general
t ∝ n
9. TSX.V V H I
Hashing revisited
9
https://en.wikipedia.org/wiki/Hash_table
11. TSX.V V H I
Oh no! Collisions – what just happened
11
Assumption: Hash function evenly distributes the elements
12. TSX.V V H I
HashMap average case 𝜃(1)
12
Lolah
Lolah
n1
n2
n1 << n2
t ≃ constant
In the average case, we assume
the keys are evenly distributed
and there are no collisions
L
L
13. TSX.V V H I
HashMap worst case O(n)
13
n
L Laura Laila Lolah
14. TSX.V V H I
How Hashing enforced in Java
14
Java Object class : https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html
15. TSX.V V H I
Contract between equals() and hashcode()
15
17. TSX.V V H I
HashMap in Java
17
https://javarevisited.blogspot.com/2016/01/how-does-java-hashmap-or-linkedhahsmap-handles.html
18. TSX.V V H I
HashMap in Java
18
https://www.journaldev.com/11560/java-hashmap#how-hashmap-works-in-java
Dude, in Java 8 , we
have made Linked lists
to convert in to
Balance trees, to be
O(log n)
…
Balanced Tree
19. TSX.V V H I
HashMap in Java
19
https://www.bigocheatsheet.com/
20. TSX.V V H I
Why do we bother : Head Hunters Do!
20
Big companies like Google, FB, Uber, LinkedIn make use of these Data Structures
and do ask questions in interviews.
Here’s a small preparation exercise for your next move :
https://www.youtube.com/watch?v=7HgsS8bRvjo
21. TSX.V V H I
A second thought on Hashing : The way Swift
see
21
https://nshipster.com/hashable/
22. TSX.V V H I
How Hashing enforced in Swift
22
<protocol>
Hashable
<protocol>
Equatable
Custom Type
conforms to
https://swiftdoc.org/v3.0/protocol/equatable/#instance-methods
https://swiftdoc.org/v4.2/protocol/hashable/#instance-methods
23. TSX.V V H I
Contract in Swift for Hashable and Equatable
23
https://developer.apple.com/documentation/swift/hashable
24. TSX.V V H I
Sample Swift code
24
Hasher:
https://github.com/apple/swift/blob/master/stdlib/public/core/Hasher.swift
25. TSX.V V H I
Take and give - ඒක පට්ට
25
https://www.youtube.com/watch?v=P1ZTkhzl5j8&feature=youtu.be