study_2
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| study_2 [2020/06/15 00:27] – jrseti | study_2 [2020/11/03 21:32] (current) – jrseti | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ==Binary Heaps== | + | =====One hour interview Video==== |
| + | |||
| + | https:// | ||
| + | |||
| + | ====Binary Heaps==== | ||
| [[https:// | [[https:// | ||
| Line 5: | Line 9: | ||
| enqueue or dequeue items in O(logn) | enqueue or dequeue items in O(logn) | ||
| - | Priority Queues use a min heap or max heap | + | **Priority Queues** use a min heap or max heap. In Java use the Comparator: |
| - | ==Reverse Singly Linked List== | + | < |
| + | import java.util.*; | ||
| + | |||
| + | ... | ||
| + | PriorityQueue< | ||
| + | ... | ||
| + | |||
| + | |||
| + | Class StudentComparator implements Comparator< | ||
| + | |||
| + | // Overriding compare()method of Comparator | ||
| + | // for descending order of cgpa | ||
| + | public int compare(Student s1, Student s2) { | ||
| + | if (s1.cgpa < s2.cgpa) | ||
| + | return 1; | ||
| + | else if (s1.cgpa > s2.cgpa) | ||
| + | return -1; | ||
| + | return 0; | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ====Reverse Singly Linked List==== | ||
| prev = None | prev = None | ||
| cur = head | cur = head | ||
| while cur: | while cur: | ||
| - | next_node = cur.nect | + | next_node = cur.next |
| cur.next = prev | cur.next = prev | ||
| prev = cur | prev = cur | ||
| Line 21: | Line 47: | ||
| - | ==Reverse Double Linked List== | + | ====Reverse Double Linked List==== |
| + | < | ||
| + | void reverse() { | ||
| + | Node temp = null; | ||
| + | Node current = head; | ||
| + | |||
| + | /* swap next and prev for all nodes of | ||
| + | | ||
| + | while (current != null) { | ||
| + | temp = current.prev; | ||
| + | current.prev = current.next; | ||
| + | current.next = temp; | ||
| + | current = current.prev; | ||
| + | } | ||
| + | |||
| + | /* Before changing head, check for the cases like empty | ||
| + | list and list with only one node */ | ||
| + | if (temp != null) { | ||
| + | head = temp.prev; | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ====Power Sets==== | ||
| + | |||
| + | All combinations of letters in a string. | ||
| + | |||
| + | Trick = use an integer counter. | ||
| + | |||
| + | < | ||
| + | /*set_size of power set of a set | ||
| + | with set_size n is (2**n -1)*/ | ||
| + | long pow_set_size = | ||
| + | (long)Math.pow(2, | ||
| + | int counter, j; | ||
| + | |||
| + | /*Run from counter 000..0 to | ||
| + | 111..1*/ | ||
| + | for(counter = 0; counter < | ||
| + | pow_set_size; | ||
| + | { | ||
| + | for(j = 0; j < set_size; j++) | ||
| + | { | ||
| + | /* Check if jth bit in the | ||
| + | counter is set If set then | ||
| + | print jth element from set */ | ||
| + | if((counter & (1 << j)) > 0) | ||
| + | System.out.print(set[j]); | ||
| + | } | ||
| + | |||
| + | System.out.println(); | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ====Tries==== | ||
| + | |||
| + | ====N Choose K==== | ||
| + | |||
| + | n!/ | ||
| + | |||
| + | ====Knapsack==== | ||
| + | |||
| + | ====Coins==== | ||
| + | |||
| + | ====Quick Sort==== | ||
| + | |||
| + | ====Heaps==== | ||
| + | |||
| + | ====Spiral==== | ||
| - | ==Power Sets== | + | ====Quick Sort==== |
| + | ====Priority Queues==== | ||
study_2.1592180844.txt.gz · Last modified: 2020/06/15 00:27 by jrseti