Convert an array to reduced form | Set 1 (Simple and Hashing) | GeeksforGeeks

  Рет қаралды 24,073

GeeksforGeeks

GeeksforGeeks

Күн бұрын

Пікірлер: 7
@gabrielzaragoza8220
@gabrielzaragoza8220 5 жыл бұрын
On one hand your code has std:unordered_map which seems relatively modern. On the other hand you pass a C style array with the length, which seems older and error prone. Is there some reason you mix the two styles? Did you want to pass std::vector ?
@gauravkvtamboli2660
@gauravkvtamboli2660 4 жыл бұрын
An alternate thing which can be done is, after sorting elements, instead of using Hashing, we can do a binary search of the element in sorted temp array 1. After Sorting the temp array, iterate over the original array 2. pick an element of the original array and search in a sorted array 3. return index from binary search and update the same in the original array Hashing takes O(n) space and searching becomes O(1) and in Binary search, search time is O(log(n)) and space - O(1)
@sandeepvy1347
@sandeepvy1347 4 жыл бұрын
Yeah it's a nice way
@wecan2729
@wecan2729 3 жыл бұрын
void convert(int arr[], int n) { int t[n]; for(int i=0;i
@youd87
@youd87 5 жыл бұрын
Why do we need a map? Cant we just sort the array and then assign them values from 0 to n-1?
@gauravanand6937
@gauravanand6937 7 жыл бұрын
What about the duplicates??
@GeeksforGeeksVideos
@GeeksforGeeksVideos 7 жыл бұрын
It is mentioned in the problem statement that the array has distinct elements. :)
Hash Tables and Hash Functions
13:56
Computer Science Lessons
Рет қаралды 1,6 МЛН
Counter-Strike 2 - Новый кс. Cтарый я
13:10
Marmok
Рет қаралды 2,8 МЛН
How to have fun with a child 🤣 Food wrap frame! #shorts
0:21
BadaBOOM!
Рет қаралды 17 МЛН
Reversal algorithm for array rotation | GeeksforGeeks
3:29
GeeksforGeeks
Рет қаралды 43 М.
C++ Hash Table Implementation
17:41
Coding Jesus
Рет қаралды 197 М.
How To Return An Array From A Function | C Programming Tutorial
13:01
Portfolio Courses
Рет қаралды 70 М.
Convert array into Zig-Zag fashion | GeeksforGeeks
8:53
GeeksforGeeks
Рет қаралды 43 М.
Hashing Technique - Simplified
17:04
Abdul Bari
Рет қаралды 795 М.
Segregate positive and negative numbers in Array
11:10
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 69 М.
Sum the Values in an Array | C Programming Example
7:17
Portfolio Courses
Рет қаралды 29 М.
Array vs. ArrayList in Java Tutorial - What's The Difference?
17:36
Coding with John
Рет қаралды 579 М.