1 / 21

Seattle Tech Interview

Seattle Tech Interview. Topics. Big OH Notation Basics – to cover simple interviews. Arrays Question List Question Stacks Question Queues Question. BIG OH. Goal s implify Analysis of Algorithms by removing un wanted information The basic goal is to understand

dena
Download Presentation

Seattle Tech Interview

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Seattle Tech Interview

  2. Topics • Big OH Notation • Basics – to cover simple interviews. • Arrays • Question • List • Question • Stacks • Question • Queues • Question

  3. BIG OH • Goal simplify Analysis of Algorithms by removing un wanted information • The basic goal is to understand • The limitations of a program • TIME • MEMORY • TIME • How much time does my program take as the input size increases? • Memory • How much memory will my program take as input size increases?

  4. BIG O What is the BIG O? for (inti=0;i<n;i++ ){ for (int j=0;j<n;j++){ print “hello”; } print “Hello” } • How many Hellos will we print • (N^2) + 1 • When N =1 the last hello matters as it is 50% of the answer. • When N =1000 the last hello does not matter as it is .00001% of the answer. • Big OH implies what matters for large numbers - N^2

  5. What is the Big O for (inti=0;i<n;i++ ){ for (inti=0;i<n;i++ ){ for (int j=0;j<n;j++){ print “hello”; } print “Hello” }

  6. Arrays • Contiguous location of memory. • [1,2,3,4,5,6] • In Java • int [] a = new int[20]; always allocated on heap. • In C#,C++,Java values types are allocated in stack. • Typical JVM stack memory is 64KB. • .Netstack size 1M • Great when you know the number of elements you want to store. • You can pre allocate the memory and fill the spots. • ADD • If you know the index a[0] • If your array was 1000 – a[99] – still 1 operation • REMOVE( index of I) • A[i] = 0 • REMOVE( VALUE ) • Search for that N comparisons o(N)

  7. Question on Array Find 2 numbers in an array that add up to a given number? Microsoft : Arrange the numbers in an array in alternating order. For example if the array is [a1, a2, a3, a4.. ]arrange the array such that b1<=b2>=b3<=b4 and so on. Sampe Input: 3 5 7 8 4 9 Sample Output: 3 < 5 > 4 < 8 >7 < 9

  8. Linked List • How do we deal with situation when we don’t know the length of the elements we want to store. • Arrays[] – we need to know the length because the system allocates contiguous. • New Data structure Node{ int value; Node node; }

  9. Linked List • Linked list • How do we move in the linked list? public void print(){ Node current = head; while (node.next != null){ System.out.println(node.value); }

  10. Get the nth element ? public Node get(int n){ Node n; for (inti=0;i<n;i++){ if (node == null){ return null; } node = node.next; } return node; }

  11. Linked List • Add to a linked list 1. Get the location to insert. 2. Insert. public void add(intn,int location){ PLEASE IMPLEMENT THE CODE. } Lets compare : • ADD • Since we don’t know the index – we have to traverse and then add to the end. O(N). • IF we decided to add to the head O(1). • REMOVE( index of I) • Travel to the index (i) and the remove O(N). • Compared to Array – O(1) • REMOVE( VALUE ) • Search for that N comparisons O(N). • Compared to Array O(N).

  12. Linked List FIND INDEX OF SIZE

  13. Variations Of LinkedList • Single • HEADNEXTNEXT • Double HEAD  NEXT  NEXT

  14. Questions Reverse a linked list ( very common interview question) Given an integer linked list of which both first half and second half are sorted independently. Write a function to merge the two parts to create one single sorted linked list in place [do not use any extra]space]. How will you find a loop in a linked list. e.g. if the 4th node of the list is pointing back to the 2nd node (for a list of size 6), then it will be in a loop; how will you find this node?

  15. Stacks & Queues • Using Arrays and Linked List • People decided to come up with Stacks and Queues. • Limited functionality • Only access to first element • Stack – first element is LAST entered. • Queue  First element is FIRST entered. • Typical usage • Processing postfix expression evaluation • 2 3 *

  16. Stack POP PEEK PUSH EMPTY

  17. Queue ENQUEUE DEQUEUE PEEK

  18. Stack In Action • Are the opening and closing brackets in the right order.

  19. Question • Implement a circular queue using arrays of a given size? • enqueue() • dequeue()

  20. Queues BFS Tree Traversal.

  21. Question

More Related