Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
5 views

DataStructures and Algorithms Notes

The document provides guidance on preparing for job interviews, emphasizing the importance of a well-crafted resume tailored to specific job descriptions. It discusses the significance of networking through email and platforms like LinkedIn, as well as the essential skills and knowledge needed for technical interviews, particularly in data structures and algorithms. Additionally, it covers coding principles, such as readability and scalability, and highlights common data structures like arrays and hash tables.

Uploaded by

Fatma
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

DataStructures and Algorithms Notes

The document provides guidance on preparing for job interviews, emphasizing the importance of a well-crafted resume tailored to specific job descriptions. It discusses the significance of networking through email and platforms like LinkedIn, as well as the essential skills and knowledge needed for technical interviews, particularly in data structures and algorithms. Additionally, it covers coding principles, such as readability and scalability, and highlights common data structures like arrays and hash tables.

Uploaded by

Fatma
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 42

Getting The Interview

>
- It doesn't matter how many interviews you fail or going to fail,
all that matter is the one
you succeed !
Resume
~

>
- Resume's are
way to
get interviews !
-> One
page (only)
- job description
>
- Relevant Skills (keywords)
>
- personalized >
-
different resume for different companies !

>
- online links !

>
- By looking at your resume people should know what you're applying to

include words from the job description


include you're
>
-
company name
applying to

>
- Do not use buzzwords - team leader in this , that etc .

>
- use action words

Email
~

-
Networking is the key !

- EmailHunter : used to extract email from linkedin (i. e ..

find Jos
~re
To
-
Hackernews
-
Angelist (start-up)
>
- we work remotely
Hired

3
>
-
gives You quiz to help companies
>
- Triblebyte hire developers .
>
- Whitetruffle

you should start Applying


~
?

BOB ? an
Even if

interview
you
is
do

a
not

key !
pass it,
getting

>
- lob description is what
type will
doing What jobs
of job
you be not
type of
you have

done in the Past. If


you have done it all then there is nothing to learn in there !
is good code ?
~
-
Readable -> is your code readable

Scalable
>
- -
Big D

complexity cha etorrill


~ 2) -
Bad In

#
onlogn)

Or
-
&
oclogn) ,
O(1)
-
I "
Elements good

3.
for (in + i = 0 ; i < num ; i ++ ) 2
This will be
if (i = = 5)9

ar
system .
Out . Printin ("Hello 1)
3 time

3
public static void printElem(intarr[])[ This is
going to

be
system . Out - Printin (arr(]); OC]
=

3 G constant time
-
~Rules

>
-
Rule 1 :
Big O refers to worst case

>
-
Rule 2 : Remove constants ! ocyn +
p) = o(n)

- Rule 3 : Different terms for inputs >


- most tricky one !

3
for /Box item : boxes)[
On)
system. Out Printin (item) ;

>
-

* Not O(n1 + O(n)


3 O(n + m)
=> occul =
la

3
for (Box item : boxes 2) E
OcMs
System Out-printin .

(item:
3

Rule 4 : Drop non dominant terms

3
i < arr length ; i + + ) &
for (inti 0 ;
.

OCH)

>
Printin (arr [i]);
system . Out no
dominant
.

3 ochtn2)

3
= or (in + i = 0 ; i < arr length ; i + + 15
O(n2
.

for (in + 1 = 0; > < arr .


length; j ++ )E
if (i ! =
j)[ OCH2S
System .
Out .
Printin (arrcij + arr(3]);
3
3

) Nested input element we have (which is hard to encoun-


O (n ! ,
>
-
loop for every

when you think !


ter

Readable -> clean code

SpeeTimecomplexity 3 is usually trade-off been a


T Big-o-there
Scalable
Heap- Where we store variables that we to values
assign :

stack- where we keep track of our function calls .

3
public void boo (n) E

for (inti i < i / & Withit this function


=
0 ; n .
length ; ++

System- Out-printin /"boo !


"
); are we adding anything in

3 Space P

boo /[1 ,
2, 3 , 4 , 5]) ; +What is the space complexity of this

function ? O(1) -
no adding in memory !

Public void arrayOfHiNTimes (n) E

let hiArray =
[J ; //0()

for lint i = 0 ; i < n; i + + ) E

hiArray [i] = "hi ! "j/0CN)


3
return Nitrray ;
3
arrayOfHinTimes(s) ; ll- >
Space complexity is Ons

You got an interview , what you will do ?


-

mmm
to solve problems ?

>
-
interview is not about how well have memorized Data structure
you
& Algorithms ! (Biggest mistake ! (

& What are companies


-
Analytic
Skills
for >
>
-
coding
communications ↓ Skills
Skills
Technical
Skills
What do you Need
To Learn ?
-

~
orithms
structur as

Data
is

>
- Trees T Dynamic Programming
↑ StackS - Tries >
- BFS + DfS (searching)
-> Queues - Graphs >
- Recursion
>
- Linked Lists + Hash Tables

Data structure >


-
collection of values ·

it speci-

I
Each data structure is good for the thing that

alized to do !

think of them as containers .

>
- How to build a data structure ?

a
>
- How to use one ? A most important ! -

you can access the


data in RAM a

·
rea
-
computer
lot faster

& CPU STORAGE

Y information
When we turn off
you do not lose
we lose the data
in RAM

E
insertion
common
A
operation >
- d election How do we access
that is going
- traversal the data we have ?
to be performed
on data searching
structures
sorting
Access
rays

organizes items
sequentially
>
-

>
- If all you need is storing items and iterate over it one by One then

are best choice .


arrays

int[] arr = 1 ,
2 ,
3 , 43; 100kup : 0(1)

arr[2] ; /13 0(1) Push : O(1)

arr-add (5) ; /1 O(1) insert : O(n

delete : On

Static Arrays : fixed in size , you must specify the length beforehand and you cannot exceed the

length you specified.

Dynamic Arrays : When you want to add item to the dynamic array which is full, dynamic
array !
copy the array to
bigger array in size

primitive variables- determined by programming itself and


type they are the
language they are always

the same !'

inta = 1;

in+ b = 1;

System . Out .
Printin (a == b) ; // true

Reference type variables - created by the developer and reference to an address ,


not a value

Student Std1 = new Student ("Alice") ;

Student Std2 = Std1 ;

Student Std3 =
new Student ("Bob") ;

System. Out .
Printin)Std1 == Stdz); is true

System . Out .
Printin (Std1 == Std3) ; /l false

* you should look each string questions as array questions ! Because at the end ,

characters .
strings are array of
nuerview
~
Questions

>
- Reverse a string

public Static String reverse /string strlG

String reversed =
"
;

for (i = Str i )5
·
length -
1; < =
0 ; i
--

reversed += Str chara + (i);


.

3
return reversed;
3

>
- sorted
Merge Arrays

public static intt] mergesorted Array (ints] arr1 ,


in+ [Jarr215

int index z = 0;

int len = arr1 .


Size() + arr2 . Size (); * Be careful about the

caseswhichshouldbechecked. .
int /len] sorted ;
-

for (int elem : arr115

if telem > arr (index z](5 the cases which checking is

Sorted. add (arr2 [index 2]) ; necessary !


index 2 + +;
3
else if /elem <arrz [index z])[
* let interviewer know
you can
sorted Add (elem) ;
.

3 that can make your function


you
essed
sorted add seems; more readable by creating functions
sorted add (arr2[index 25);
.

index 2 ++;
for
checking purposes !
3
3
return sorted ;
3

When you should use an Array ? Why you shouldn't use Arrays

3
>
- fast look ups - Slow inserts because we need
cepy the
to push or
1
>
- fast push , pop slow deletes entire array in Worste !

↑ fixed size (if you are


using static
arrays !
Hash Tables

Hash-generates a value for each input it


gets .

insert +
OCI) Main problems With Hash Table
~

100kup- O(1) Collision- Since hash tables randomly assign


delete + OCI names into
memory without caring Whether

searche OC11 the spot is already occupied of not ,

it is inevitable to assign more than two


100 101 102 103104105106 107 values into same address which referred
A(In/ as collision .

*is look a let like linked list -


slows down reading &
right ! Writing into high table since

to reach to the value you will


need element
to
go through every
stored in same address .

* look Java map & set !

n
table implementation
~

public class Hashtables


public void Hauntable (size) // constructor

+ his .
data = new Array (size) ;

this. size = size;

private String hasn (key) [


int hash = 0;

for (inti = 0 ; i < key length 1) ; it +


· /
nash += Key ChatAtcode (i)
.
% thissize;

return hash; /Giving the address

3
Public void Set /key value) ,

int loc . = this hash (key) ;

if 1 ! this data [loc] )[


this data [address] = &3 ; llempty array;
3
this. data [10c] add ·

(S key ,
value 3);
3

public int get (keyld

int 10c = this. hash (key);


ArrayList <> curr = this dataDloc];

I curr) <
if // if curr's length ! =
0

for (inti = 0
; i < curr size() ;
. i ++ /

if (curr[o](0] = = key) E

return curr[O](17 ;
3
Y

3
return 0;

public ArrayList)) keys (19

ArrayList (Strings) Keylist = new Arraylist > I ;


for (int i = 0; i <this size ; it + ) &

if ( this, data [i]) E


for (in+ T = 0 ; 1 < this data [i] Size () ;
. .
B ++ ) E

key List - add (this data [i] [J]/0] (;


3
Y
Y

return Keylist;
3
Interview Question You need to use hash table
to optimize
Given the first character naive method !
an array ,
tell me recurring -

code :
u

public static int recurring Num (intC] arr)E


if (arr length (1
. < 119

for (int i = 0; i < arr length() ; i ++) [


·
lists
med
>
-
problems With arrays were the following

Static Array - has a certain size, to be able to add element to an array we need to

the into a bigger array time we add new element !


copy array every

Dynamic Array - double its size When the limit has been passed !
Y
generate double size array and copy each element into that array in worst

case

- Delete is same

hand deletion
->
Hashmaps on the other are great for insertion and but
they are

UNORDERED ! (which is a problem)


-

6 this is where linked lists came to rescue !

>
- Does this means that linked lists are the best data structures therefore we should

always
head
used them
? ↓
Fail
X prepend O(1)

littl
Append+ O(1)
100kup - On

next even insert - Ocn(


end deletee(n)
I
to the beginning and the

- Insertion and deletion Carrays (


?
Why linked list beginning
-
ordered Inash table)

linked List
my
head +ail
prepend - O(1)

nunerdatalnexin
datakexidets/next->
searching
nu Append OC through doubly
-
-
linked List
100kup >
- O(n(
a bit more
insert >
- On ( efficient
delete- on then linked
Downsides more memory ! vis + (0(EI)
althoug techically
OL1 is on I therefore we

still use ol runtime !


Singly Vs Doubly
Linked List
see
i
less
-
memory
pres- > lessoperation to delete or insert

singly linked list (fasters

>
- cannot be iterated through back
cons -
lost forever)
(if we lest head reference
, list can be

pross can be iterate through back

-
- Effective search

Doubly linked list - core -> more memory

d
-
more operation

-
complex !

second
>
-
Reversing linked list first
L J temp
public Node

if (this head) <


reverse ()[
nu IT
&A
return nul ;
3
if ( this head , , next == null)[
return this;
7

Node Second= this head. next;

Node first = this head;

While (second) 9
Node temp = second next;

second. next = first;

first = second
,
second-temp ;

3
Node last = This head;

this head. next-null;

this head = first;

this. tail = last


;

3
Linked List
we need to
Prol Cons - reversed
u -
Through
>
- fast insertion + Slow lookup List !

fast deletion Mere


-
- memory
- ordered
>
-
flexible size

As
>
- Last in first out (LIFO)

- most programming architecture


designed stack on mind .

100kup >
- O(n)

Push >
- 011)

Pop-O(l)

Peeke 0(1)

mes
>
-
first in first out (fIfO)

100kup 1 On

enqueue >
- Ol

dequeue - all

peek >
- OC)

Questionsd you want to implement stack as linked lister


dya as
Arrays .
>
- element array would be beneficial Since all side
getting in an more elements are
by
side it would be easier to get on element .
Also less memory.

would add to end


- flexible size of a linked list make it better to an element the

Since there will be no need to deuble the size when array is full.
to linked
: Why would you want implement queues as an
dynamic Array or

List ?

>
-
implementing queues as an array wouldn't be
practical at all since to delete

the first item we need to switch places for all the others which takes (ocnl/runtime

Therefore I would use linked lists.

How javascript work ?


understanding stack overflow

what is program
?
-
-
Program alatememoryexecute crun s commands .

memory leak : Happen When I have unused memory /unused variable etc . ) that is
laying around

and fulls up the memory heap. this is


why global variables are bad !

Single threaded : One call stack,


you can do cust one thing at a time .

* issues with multithreading is such as "Deadlocks"


~

Stack Overflow
e
i

Seowed!
Call stack ge biga
and
bigger bigger until there

is no space left !
&
How this happen

call stack No base case in recursion

function

predictable
T
synchronue programming - But it can get slow since it does everything one by one and

if there is some function which takes longer to run, it might cause

longer wait time for other to be executed.

Asynchronus programming - we can do it by Setting Timeout


.
⑧ >Printin (U);
stem. out
-

&
.

④ =stem Out printin(s); - ,

-
code Execute -② meout()
# this is going to execute now
(1) Printin

(
① -
out .
system
System. Out Printin (1); -
call stack

public static void timeout() < Check

stac itemp y
③ timeout)) - wait I see is

Thread Sleep (2001 , wep Ap1 Call +

&
.

new
or not
After that

eioalback
System. Out . Printf (4); to cana
-
goes
z queue

&
time out () ;

System. out .
Printf (6);
continuous check but let say 6
Event loop - Check if the callstack empty
if it is not going to chelk
Butput callback

5
Y

&:Implement a queue using stacks

es-vierarchal data structure

① -
single root node
root : I

d Parent

child :
:

234
13

67

↓J leaf : 2674

⑧ sibling : 23467

Each node can have max I child


-

Ary
Tree

there is double amount


~ Of node each below nock
Perfect Binary Tree Full Binary Tree

1 1

11) 1)
- 1
G at better node level 0 : 20 1
we have =

half of the node (nearly) level 1 : 21 = 2

level 2 : 2 =
4
3 : 23 8
level =

level h : 2 = n + total number of nodes

height of - = logn
the tree = n +1
Great for searching , comparing things
-
Binary Search Tree >
- right child is bigger than the node
e
i
left child is smaller than the node

Binary Search tree


101

/ Yos lookup :
OClogn)
Average
33
insert O(logn)
case
· on Biggest
:

delete : O Clogn)

smallest

Problems With binary Trees


mem

-you can have unbalanced binary trees which is similar to linked list which
takes
lookup : O(n( worst

Case !
insert : O(n)

*
dete : on

ne cons

con
M um

>
-
operations
most are >
- No Ocls operations
better than O(n)

- ordered
>
- flexible size
BinarySearchTree
usin

Public Node remove (intval) [


int value;
if(this root nul)[
Node right ;
==

Node left ;
return nul ;
public Node (int datald 3
this Value . = data ; Node cur= this root
3
Node parent null
;
3

1 While (cur)[
Public Binary Tree &
③ G if luak sur. value)[

d
Node root
parent = cur ;

public Binary Tree 115 cur-cur ,


right ;
3
this root-null; else if (val (cur values ·

3 cur = cur left;


.

insert (int valla


public void Parent =
cur;
3
else// means we catch
Node new Node = new Node(vall;
Node head= this root; if (cur. right--nulls// means no right node
if (this roof == nu) 9 if (parent nulls a ==

this root = new Node; this. roof = Cur . left ;


3 3
else E
boolean cont = true ; if (parent Value > cur .
Value) [
while (cont) E Parent-left = cur left ;
-

if (head. value > val) < 3


if (head . left ! nuu) < if I parent. Value < Cur value) [
else
.

head-head left ;
parent right cur right;
,
=
.

Y
esses 3
head left = new Node;
.

Cont = false;
else if (cur right. left == nulls
3
.

3
if ( Parent = nuu)a
else if( head. value < val) E
if (nead right - nulls .
!

head-head right;
3
else
head. right = new Node;
3 cont = false;

else
system . Out . Printin ) "There is already" val) ;
+

3
public Node lookup (intral) [

Node cur-this root;

While (Cur) &


if (cur - value == val)[
return cur ;
3
else if (cur value - > valls
cur-cur . left;
3
else E
cur = Cur .

right;
3
3
return nun;

3
AVL Tree
T
Balanced Binary Trees
- Tree
Red-Black

Heaps (Binary Heaps (


lookup O(n)- Because it is not truly

root-root
-
max heap
ordered
is the maximu a insert >
-
O(logn)
>
- value !
33 delete Ollogn)
72
>
-

XX
5 f
2 30

*
Only guarantee that binary heap is parent is (if max heap) childeren.
gives bigger then

Quelles Each
Priority -
element in queve has priority and elements with higher priority
~ served first.
(if it is high prierity queue)

Binary Heaps-Balanced trees


I because -
Pros cons
-
~
4

& + here is

left to
an

right
erdet of

insertion
insertion . Better
/insert, delete
than O(n(

priority
Slow lookup
you know the

flexible size
fast insert

Tries >
- specialized tree used in searching

Start Example Usage : Auto compilation

4
A 2 lookup : 0 (length of the word (
B ---

- ↓ &
I
R
E
S

I E
E I N

A
A

Ephs

·
Directed graph undirected Graph

you can't and fort go back and for

·
>
-
go back you can

·
cunless there is two edge (

weighted graph unweighted graph cyclic A cyclic

y 4
2 2

11 1
"
- -

*
7

implementation :
mu

public class Graph /)[ public Class Edge &

public int nymNodes = 0; // public String value ; if needed might added


public Noch from ;
public List(Node > Vertexlist ;
Public Node to ;

Public (Node nodel , Node node2)s


Public List (Edge > edgelist; Edge
this from nodel ;

this. to = node 2 ;
public void add vertex (Node node)5
3
Vertex list . add (node);

is
3

Public void addEdge (Node nodel ,


Node node 21d
scaling
Edge newedge = new Edge (nodel , Nodez);

edgelist Add (newEdge) ;


hard
.

3
Algorithms
num

>
- Algorithms helps us to create actions using data structures .

3 What a
sorting

in
>
-

Algorithms
>
-
>
- Dynamic programming we
BFS + DFS (searching (
Recursion

Recursion -
when you define something in terms of itself
.

w
U Good if there are repeated subtasks

StackOverflow >
- Happens When function get called over & over again .

i . .
e

public void
StackOverflow (1j stackoverflow(s] SECASE !

public main()E
? &

This StackOverflow();
.
>
- this will create stack overflow

public string recursive()s

int count = 0
; Rule 1 : Identify the base case

pount-3525
if
-
- -

"done !
"
return ;

count ++; recursive


~
Rule 2 : Identify the case

wonrecursive
- -

·
---
3
IMPORTANT
-
find factorial

Public int factorial Recursive (int num)G

if( num == 1)S

return 1 ;
3

return factorial Recursive (num-1) * num ;

public int factorial Iterative (int num)[

int answer = 1;

while (num ! = 1(E


answer =
* num ;

num--;

return answer;

3
acci

public int fibonaccipecursive (in + indexis//0(24) exponential


time
if
( index = = 01 G

return O ;

else if (index == 11[

return 1;

esse G

return fibonacci Recursive (index-2) + fibonacciRecursive (index-1) ;

public int fibonacci Iterative (int index/s//O(n) time

int answer = 0;

if (index = = 01 [
return o;
Y
else if (index == 119
return 1;
Y
elses
List <int > fibonacci = new ArrayList()();
fibonacci . Add (0) ;
fibonacci- add (1);
for (inti = 2
; i < index ; j ++ ) &
fibonacci - add (fibonacci . get (i-2) +
fibonacci get (i-1)) ;

return fibonacci .
get (index 1 ;

3
Anything you do recursively
Can be done iteratively .

Pro cons
~ ~

simple code Large stack

readability

When To use Recursion

>
-
Bread first search & depth first search , recursion is useful then

iterative approaches .

In
>
- serting cases recursion also better .

* Every time tree or converting something into a tree ,


you are using a

consider recursion .

① Divide problems into subproblems .

② Each instance of subproblem should be identical .

③ The solution should be able to help to solve the problem

Divide & conquer using recursion

Traverse function using recursion


root
public Node traverse (Node nodel5
Y
9
Node

if (cur :
cur=tree. root;

nuu)'s
=
3
if (cur data . == node , datal 5

return cur ;
3
else if (cur. data <node-data) E

return traverse (cur .


right) ;
Y

eise E
return traverse (cur -
left);
3
3
return nun;
3
Eing
Why do we learn about sorting while we can use the ones already there ?

?
What is the issue With Sort)) -
Different implimentation in each programming languages
h
Do not sort as
you expect for different input types
So would need modification depending on the input you get
.

Bubble sort
-
ElementarySorting Insertion
-
Sort

Bubble Sort
- least efficient
-
Algorithms
Selection sort

wi
sor t
merge
155
-
318724 Complex Algorithms
sort
- Quick
65 bubble
(switch)

515631872 16721815)

·
53
Y
63 - Switch
u switch

15131672 u 15- max


continue
from top
-

Best case space complexity : O(n(

Average Space complexity : O(M2

Worst case space complexity : O(n2)

space complexity O(l)


:

code
u

public List /Integer] bubbleSort /List (Integer] arr 15

(intiarrlength
int length =

for gth ; i + + 12

for (in + ( = 0
; /length ; j ++ 1 &

if ( arr .
get (3) > arr .
get ( + 1)[
int temp = arr .
get(j + 1) ;

arr Set . (5 + 1 , arr .


get (jy) ;

arr . Set (i , temp);

3
3
length-- ;
3
return arr
;
3
tionor
~
e

· ·
5

Public List <Integer) SelectionSort (List <Integer > arr)2

int
-
length = arr .
length;
Int min ;
for , int i
= o; i < length ; i + + 12
min =
is
for (intj = 0 ; ) (length -
1
; c + 19

if (arrget (2 + 1) < arr get (minl


.

;
min = 1+ 1 ;

3
3
int temp = arr .
get(i);
arr . Set (i , arr .
get (min 1;
arr . Set /min , temp);

Y
return arr ;

Best case
O(n2)(

Average case O(n2)


Worst case
O(n2)
space complexity O(1)
Insertion Sort-Efficient when list is already sorted
- or Sort a sorted .

switch add to top again


& tonmaller than 5 6
I I
.

1055 318724 - 883318724 -


BBB8 724
t
&
& &
#T - TBBTTAEY - ABBBBTOSA2
8
4
AJSBSBLSE2is (bigger +an all
3
between between

IISEBSISESS1715

>
-
performs very very well on small in put sizes .

Public List <Integer> insertionSort /List <Integer] arr79


int len =
atr ·
length ;

for (in + i =
0 ; i < len ; it + S

i (arr+i] < ari [0]) <

int temp = att so] ;

arr Joj = arrsi] ;

arr[ij = temp ;
3

else3

# or (in+ c = 0 ; +(ijj + + )5

if (arr(i] < arr]] && arr(i] > arr[5-1D) E

int temp = ari[i];

arr/i] = arr (J];

arr [J] =
temp;

Best case O(n)

Average case
O(n2S
Worst case O(n2)
space complexity O(1)
MergeSert use divide and conquer technic a

Age
sort

6 5
t 31 87 24
DIVIDE

L Y 1 d - L x

I 872 Y
6 S 3

Y [ -4 -X

I

56 1 .3 78 2 Y
- L Y L
Conquer
1356 2/478
- I

1234 5678

Best case Onlogn)


-

Average case Ochlogn)


=>

Worst case Ochlogh)


-

Space complexity O(n)


>
Public List <Integer] MergeSort) List <Integer > array )S
if (array length = =
0 15
return array ;
3
List <Integer > left =
new ArrayList > 11 ;
List (Integer) right =
new ArrayList < )();
int len =
array length;

3 for (inti i ++ S
<i
= 0 ;

left-add (array .

get (i) ;

right .
add Carray. get (i + len/2) ;
3

return merge (mergesort (left), mergesort(right (1)


3
Public List (Inleger] Merge /List Integers left , List <Integet> rightl &

List Integer) merged =


new Arrayrist < ();
List <Integery Merged =
new ArrayList()) ;

int lenc left


= .

length ;
int lenr =
right. length;
int left Num = left get (0) ;
-

int rightNum =
right-get(o) ;
boolean cont = true
;
int index 1 0; =

int index R = 0 ;
while (cont);
if (index ( < lenL && index &ClenR 15

if (leftNum> right Num )E


merged add ( right Num) ;
.

index R + +j
Y

elses

merged- add CleftNum)'s


index ( ++;
3
Sant = false;
*
return merged;
3
Stable a unstable Algorithm

* An Algorithm said to be Stable if two object with equal keys appear

in the order in the output in the input


same array as they appear

I
put -
Output

peach apple

raw peach

apple -raw-since straw comes first

it is an top of spark
Spork Spark

Ex : Merge Sort, Insertion Sort , selection Sort , Bubble sert

* An unstable algorithm, straw and spark may be


interchange

Quick Sort
wir
nothing needs to change
&
&

378521954- pick a randem Pivot


-all
7) 4 so it should numbers that are less thanU should
be Lett !
on
be at left and more thanI should

be at right

dgsau/create zoacetatechange
3)
is
with

be on left

I
31112/5Tu10/9/s/z 2/1/2
Nothing ~
divice the
a
3 (1 (2 (4/5/8/9/s/7
rightand
continue doing a

ad
Best case ocniogn)
Average case Oinlogn)
Worst case & (n2) - When Pivot is either smallest or biggest
Space complexity Ollogn) - Better than
Merge sert

sort is best ?
h
Easy to implement

Cy
>
-

Insertion Sort - if input is smaller ? - fast (with provided constraints

array is almost sorted Y smaller space complexity

Bubble Sor t - Not very efficient in any cases

Since it is it used
very simple might fer
educational purposes

selection sort
- same as bubble sort !

merge sort-guarantee Onlogn) running time

divide and conquer

If
you are considering space complexity

then this might not be the best option .

Quick sort - It has a better space complexity than


merge sort but

If you're worried about running time then


you need to

be careful about choosing the pilot

Non-comparison sort
eme
us

Radix
Sort only work With fixed length integers

counting Sort
Searching
nu

Linear
Search-searching in an input one by one until finding the object
.
-

worst case - O(n)

best case - 0(1)(

But is there a better way ? - Ollogn

If we know the list is serted then we can use Binary Seaich.

Binary search

let say I'm searching for -


44

<
/4/0(9(12/34/45245 ↓ so
: =

uu is not
u4

44 > 34 in the List !


4479
so go right so go right

Breadth-first search
Tree & S
But what if we want to visit all the nodes + Graph - Depth-first search
Traversal

Breadth-first Search - we need to track every node and its children in order
~
meaning that it uses
memory (
G
②X ③

① 2 ①
1 # 34 45

first Search
& - Not
necessarly need to remember each node and its children in order

(less memory usage


9
② ⑤
6 12

③ 34 45
>
-
eath-first ee-first
shortest
search

path
us

>
- Does
search

path exist ?

>
- Closet Nodes >
- Less memory

memory can get slow


more
usage
-
>
-

if you know what you are looking If


you know that what
you
for like in upper layer of the
looking fet is
likely to be on

tree then breadth-first search better lower layers of the tree the

depth first search is better

#1 solution is BFS
If you how not far from tree : is better

#2 If the tree is very deep and solution are rare : BFS because

DFS take)
very long time to search in depth. Although with Bfs

We would have memery constraints

# 3 If the tree is very wide : Then BFS takes a long time and memory the

DFS SO DFS .

# Y If the solutions are frequent but located deep in the free :

DFS Since the solution is located deep .

# 5 Determining whether path exist between two nodes ! DfS since it

Will look down to road until there is no successors .


left

#6 finding the Shortest path BFS


Breadth-firstSearch Breadth-first Search Recursively
seem umm

public List /Integer] breadthfirst Search (19

Node curr = this root; public List <Integer] breaden first Search Reg (List (Integer> list , Queue queued

List ArrayList()(); if /queue


(Integer> list = new . Size == nue IS
return List ;

Queue queue Queuel) ;


Mode
=
new

(curr) ;
cur =
queue pop();
.

queue. push
list add (cur);
While (queue -
size ( > 01 &
if ( cur left ! = null E
curr = queue Pop() ;
-

queue push (cur left); .

list add (cur) ;


.

if
.

if (curr · left != nuu)d/ if there is a left successer ( cur -


right ! = null a

queue .
push (curr left);
. queue .
Push /Cur .
right) ;
3 3
if return breadth first Search Reg) queue , list);
curr ·
right != null &

queue- push (curr .


right);
3
Y

return list;

3
in order
>
-
three way that
first Search -
Depth pre-order
You can impliment
umm post-order

① ⑦
9 9 9
[ 6 ② ③

04 20
=
20
+ ⑦0 " +
20


16 150 170 ↓ 6 150 170 ↓ 6 15 178

in -
order Pre-order Post-order
traversal traversal traversal

in order
u

Public List <Integers DFSInorder()[

List Integer > list = new ArrayList < () ;

return traverse Inorder (this root , list) ;

public List (Integer) traverseznorder (Node List list 19


Cur , <Integer >

if (cur - left != null)[

traverse In order /Cur left, . list) ;

3
list-add / cur) ;

if
( cur right ! = nuul &
+ raverse In order (Cur right , list) ;
Y
return list;
3
public List /Integer > Afspreorder () [

List [Integer) list = new Array List <> (1 ;

return traverse preorder (this root , list) ;

Ey

public List /Integer) traverse preorder (Node cur , List Integer > list) &

list-add (cur) ;

if ( cur . left ! = nuel s

traverse preorder (cur . left ,


list);

if (cur right ! = null

Traverse preorder (cur . right ,


list) ;

3
return list ;
3

Public List (Integer) Dispostader(1G

ListInteger) list = new ArrayList < () ;

return traverse postordet (this root , list);

Public List <Integer> traverse postorder (Node Cur , List list) G


<Integer)

if( cur. left ! = nul) <

traverse post order (Cur left , list) ; .

if ( kar-right ! -null

traverse post order (cur .


right, List);

list add (cur) ;


.

return list;
3
Algorithms & Bellman-Ford
~
Stra

To
figure out shortest path problem

But since we breadth-firstSearch , why do need these algorithms ?


already know we

Because breadth-first search will not look for weight of the edge !

We need special algorithms for those .

Bellman-ford Algorithme Better at


solving the Shortest path problem

when there is weight In of


Negative weight Dijkstra
negative case
.
,

cannot solve the shortest path problem

Then when to use Dijkstra ? Bellman-ford takes a


long time to run

but Dijkstra algorithm takes sherter time .

namic
programminga optimization
~
one

memorization
Caching used to speed
~ programs
up our

(
Storing values from the function to not run a function that

take long time


instead
could , store it in somewhere .

remember solution from sub-problem .

* clausers in Javascript is important for caching

fibonacci
u s e
a

Recup
&
fibonacci
& Dynamic

with
programing

recursion
Divided
ization
Dynamic programming

3
public int fibonacci (n)[

if (n < 2)4 This is not because


great
increase exponentially With the
return u ;
number of inputs .

3
fibonacci (n-1) + fibonacci (n-2);
return

3
using dynamic programming though decrease O(n) ! cusing
, we could the time from On to
memorization (

How to program dynamically ?

① can problem divided into sub-problems ? (then divide

② Think of the recursive solution

③ Are there
any repetitive sub-problems ?

④ If there is , then memoize subproblems

Dynamic fibonacci
- programming of

public class fibonaccia

ArrayList (Integer > fibonaccilist;

public void fibonaccil)[// construction

this fibonaccilist = new ArrayList ( > (1 ;

Public int fibonacciNum (in+ n)[

if (GS2)[

this fibonaccilist[n] = h ;

if (this fibonaccilist[m ! = nul)E


return this. fibonaccilist[n];

3
else
this fibonacci List [n] = this fibonaccilist[n-1] +
this fibonaccilist[n-2] ;

return fibonaccilist[n];
3
3

3
Technical Questions
un

set
#
issue
Thinking
:
that this is your only chance

4 TREAT EVERYTHING AS LEARNING EXPERIENCE ! THIS IS NOT YOUR

ONLY CHANCE

Be happy there . These interview decide


>
- to be people who
you are
going to

Whether they want to work with hot Made them


enjoy the interview !
you of .

Interviewer has 3 >


- can you do the job ?

Questions mind - can I work with ?


on their
you
Are you going to improve ?

① & here
must be
story
prepared
-
-
O
Challenge
f about very difficult
& problem and your solution
>
-
Technical
J ③ to overcome it
.

Leadership
Difficult protect ② -

that will success Do you have


impress
leadership
the interviewer (etc ) .

Story that shows qualities

you are successful

① Even tho h
i

- or of women
group
-

ectoratethansite as they desired . It was the first project I have

ever done With real dient that


z
enjoy a let - I worked alone
although
=> was in communication with client all the time .
my


In our school there was an Al computation of Vestel and me

and my team won the computation . It was my first timeerate


=> Won as a group and we had so much fun working read protect
.
③ There was a campy lab
program opened by Vodafone . Me

and my friends attened the and showcase our product


program
although j which we
kes
failed at seinheien

be able to make dow


We were not
going to any progress the

Top in
equal parts and ask each and every one of them what do they
want to ob and gave the Lob -

Tell me about yourself


>
- your triggers of success

I Mention things you want to get asked


- Skills should be relevant to jeb

YOU SHOULD ANSWER THIS QUESTION ABOUT A MINUTE-TOO SHORT

THEY WILL NOT LEARN ABOUT U !

WHAT DID YOU DO TO

SAND
OUT !
write your own
why us ?

- Make the interviewer feel special . Make them feel that this is

your first choice . You see full career.

· SHOW YOU WANT TO GROW

· DEMONSTRATE WHY YOU ARE THE BEST !


· WHY THIS COMPANY IS INTERESTING

WHAT DID YOU WORKED OUT WITH SIMILAR PROBLEMS

Why did job ?


you leave your

MONEGATIVITY They don't about


-
want to hear

the occurred at
problems your Tob .

They want to see the desire for .


improvement
you want to grow .

&
* Tell me about Problem how you solved it
Situation -

SAR Y
method
Result
How you solved

is
scaling ,
performance

Action and security really . All


important

Companies looking for those !

While answering this


question care about what company is

looking for and does this solve their problem .

What is your biggest weakness ?


>
- you need real answers not
silly ones like I work too much .

>
- snow now you improved it .
Any Question for me ?

out !
Key points-stand
>
- focus on them , not company
mention mentioned
something they
-

Exi
-

What is the in the first


·
greates mistake
you made month of the lob

and what did do ?


you
· where do
you see this
company going in next three years ?

Why did coin this


company ?
·
you
· Have skills
growing in the ?
your past year
· Time they massed up and now did they nandue it ?

EVEN If YOU MASSED UP ON ALONG THE


NEVER GAVE UP !
INTERVIEW ,

SECRET WEAPONS

-
Simplicity over complexity
>
- premature Optimization is the root of all evil

- Overall
goal , myopic !
not (focus on what is important not what
-

you think is important (

- Not
complaining about client/code etc.

·Goffensive about feedbacks . Be ope to


get feedbacka

After the interview


-
Be positive , energetic , pleasant
>
- Ask for feedback
>
- Ask When should you accept to hear back
-
Don't overuse "I" Talk about interviewer
, , express now

you the ideal candidate without !


are
braging
Offer & Negotiation

Handling Rejection -
After receiving rejection do not
gave
up ! It doesn't mean you lack of skills .

If you fail 10 times, try 10 times more .

All you need is one acceptance

Negotiation

What
·
salary you would expect
+ Since I know
average software

makes up (num) in a year/menth on particular area


engineer
1 would expect this

· Give reason fer


everything- I need to think about the offer since

i is a
big decision for me at the mement etc .

·
Always negotiate

· Be positive

· Have stakes 1
show company that
you have other options !

Handling an offer

>
- Don't end the conversation by saying this sound good. This close the doer

for negotiation !
>
-
say you need to think this offer since there are other companies that you

for
are
waiting
>
- BE POSITIVE

>
- ASK FOR TIME

>
- AFTER YOU DECIDE WHAT ARE YOU GRING TO CONTINUE WITH ,
LET OTHER

COMPANIES know !
Handling Multiple Offers

⑦ IS there an offer that you feel you are under qualified for ?

Go to that
company
② long term
growth potential
Then yes
-

③ will you respect people around you ?


④ salary & benefit

⑤ is
your decision based on desperation ?

Getting a Raise
St
1 Step : Be a good employee
-
Before Starting , know your career path in advance !

A rais.
-

If you never ask the answer is


always
#0 !

You might also like