Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,194,341 members, 7,954,392 topics. Date: Friday, 20 September 2024 at 06:00 PM |
Nairaland Forum / Science/Technology / Programming / Algorithm And Data Structure Study Section (7597 Views)
Data Structure And Algorithm With Php / Is It Possible To Learn Algorithm And Data Structures? / Nigerian Developers How Did You Master Algorithm And Problem Solving (2) (3) (4)
(1) (2) (3) (4) (5) (6) (7) (Reply) (Go Down)
Re: Algorithm And Data Structure Study Section by qtguru(m): 9:38pm On Feb 26, 2023 |
No vex, been busy with life, as election dey go, seems like we will resume this thread 4 Likes |
Re: Algorithm And Data Structure Study Section by Tenrack: 10:31am On Mar 06, 2023 |
truthCoder:bros..can I talk to you in private please? Good morning |
Re: Algorithm And Data Structure Study Section by truthCoder: 10:41am On Mar 06, 2023 |
Tenrack: truthcoder@protonmail.com |
Re: Algorithm And Data Structure Study Section by Tenrack: 10:43am On Mar 06, 2023 |
truthCoder:thanks boss |
Re: Algorithm And Data Structure Study Section by Tenrack: 10:47am On Mar 06, 2023 |
truthCoder:already sent you a mail sir. |
Re: Algorithm And Data Structure Study Section by richebony: 4:04pm On Mar 15, 2023 |
Please can anyone come up with an optimized solution for solving this PS? Design an algorithm to find all the common elements in two sorted lists of numbers. For example, for the lists 2, 5, 5, 5 and 2, 2, 3, 5, 5, 7, the output should be 2, 5, 5. Time complexity should be 0(n) or better NB : am terrible with algos so any contribution would be highly appreciated namikaze truthcoder qtguru tensazangetsu20 |
Re: Algorithm And Data Structure Study Section by namikaze: 8:21pm On Mar 15, 2023 |
richebony:Have you tried using an Hashmap/Set? For example:
1 Like |
Re: Algorithm And Data Structure Study Section by richebony: 7:49am On Mar 16, 2023 |
namikaze: Thanks a lot man !! function commonElements(first, second) { const res = []; const map = {}; for (let element of first) { map[element] = (map[element] || 0) + 1; } for (element of second) { if (map[element]) { res.push(element); map[element]--; } } return res } Hope u don't mind my asking, but how many languages do you actually know because I have seen your code in golang, I once confused you with another handle ( decide ) 1 Like |
Re: Algorithm And Data Structure Study Section by namikaze: 10:14am On Mar 16, 2023 |
richebony:I mostly use golang for my side projects, js(nodejs) because I gotta get a job , python for DSA . I also know Java, C and C++ but I don't use them anymore. 2 Likes |
Re: Algorithm And Data Structure Study Section by Ayrastarr(f): 9:12pm On May 30, 2023 |
@qtguru Hi! Please, how do I join your class? |
Re: Algorithm And Data Structure Study Section by qtguru(m): 9:24pm On May 30, 2023 |
Ayrastarr: Do you write PHP ? |
Re: Algorithm And Data Structure Study Section by Edipet(m): 10:05pm On May 30, 2023 |
Tobedated:please guide me on javascript |
Re: Algorithm And Data Structure Study Section by Ayrastarr(f): 3:10am On May 31, 2023 |
qtguru: Still learning |
Re: Algorithm And Data Structure Study Section by qtguru(m): 4:25am On May 31, 2023 |
Ayrastarr: that's enough I'll share the resources here and meeting for the next class 1 Like |
Re: Algorithm And Data Structure Study Section by Ayrastarr(f): 5:14am On May 31, 2023 |
Re: Algorithm And Data Structure Study Section by Tobedated(m): 8:55pm On Jun 01, 2023 |
Edipet:sorry boss me sef still dey learn am i'll recommend you check out a youtube video or a book on it |
Re: Algorithm And Data Structure Study Section by drDoom3(m): 2:03am On Jul 30, 2023 |
richebony: The most efficient way to solve this is two pointers in O(n) time and O(k) space where k is the number of common elements. Using a set or hashmap might be O(n) time, but O(n) space so is less efficient. |
Re: Algorithm And Data Structure Study Section by drDoom3(m): 3:20am On Jul 31, 2023 |
Longest Palindromic Substring Textbook dynamic programming problem. The key is recognizing that for any palindrome s, adding the same letter to its start and end also gives a palindrome. For instance, "aba" is a palindrome. Add "c" to it's beginning and end gives "cabac", which is also a palindrome. Now, for the base case, every string of length 1 is a palindrome. Also, every string of length two with the same letters (i.e "bb" is also a palindrome. Then, the recurrence is given two indices i and j in string s such that s[i] and s[j] contain the same letters, find the longest palindrome in the substring s[i + 1 : j - 1], then add 2 to the length of this longest palindrome to find the length of the longest palindrome in the substring s[0: n] where n is the size of string s. In the case where s[i] != s[j], the longest palindrome must be from either increasing i or decreasing j. This is because picking i and j together does not form a palindrome, therefore we must make a choice to drop one. Thus, the full recurrence relation becomes: s[i:j] = 2 + s[i+1:j-1] if s[i] == s[j] s[i:j] = max(s[i+1 : j], s[i : j-1] if s[i] != s[j] Knowing the base case(s) and recurrence relation for a dp problem makes the code implementation trivial, so I will not bother to write it down here. |
Re: Algorithm And Data Structure Study Section by drDoom3(m): 3:31am On Jul 31, 2023 |
drDoom3: In python: def common_elements(arr1, arr2): i, j = 0, 0 # pointers for arr1 and arr2 respectively res = [] # result array while i < len(arr1) and j < len(arr2): # first skip all recurring values in both arrays while i + 1 < len(arr1) and arr1[i] == arr1[i + 1]: i += 1 while j + 1 < len(arr2) and arr2[j] == arr2[j + 1]: j += 1 if arr1[i] == arr2[j]: # both are the same, so add to res res.append(arr1[i]) i, j += 1 elif arr[i] < arr2[j]: # move i pointer i += 1 else: # move j pointer j += 1 return res This should solve it with O(n) time and O(k) extra space where k is the size of res. We don't need a hashmap/set to store every single value in this case. |
(1) (2) (3) (4) (5) (6) (7) (Reply)
Reusable Object-oriented Patterns In Banking Applications / Embedded Systems / Were Can I Download Free Video Tutorials On Javascript Or Ruby
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 34 |