Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,174,303 members, 7,891,393 topics. Date: Tuesday, 16 July 2024 at 12:26 PM

Thread For Nairaland Algorithm Questions - Programming (3) - Nairaland

Nairaland Forum / Science/Technology / Programming / Thread For Nairaland Algorithm Questions (5556 Views)

Forex Market Algorithm IPDA part 2 / What Is Nairaland Algorithm? / A Thread For Tutorial On Python Programming (2) (3) (4)

(1) (2) (3) (4) (5) (Reply) (Go Down)

Re: Thread For Nairaland Algorithm Questions by Deicide: 7:17pm On Jan 21, 2021
qtguru:


Dude that is some sick text based ui, what is window manager is this ? na pcguru1
That's Vim + Bspwm
Re: Thread For Nairaland Algorithm Questions by Karleb(m): 7:40pm On Jan 21, 2021
cixak95211:
Question:

1. Design an algorithm(s) for the following array operations: "push, pop, shift, unshift" using object oriented programming practices.
2. Design an algorithm that will find the longest common subsequence between two arrays, plus the time complexity for your solution.

For question 1, are slice and splice functions allowed?
Re: Thread For Nairaland Algorithm Questions by Donpre(m): 8:07pm On Jan 21, 2021
Deicide:
.
I am unable to read C++, could you explain your solution
Re: Thread For Nairaland Algorithm Questions by Deicide: 8:39pm On Jan 21, 2021
Donpre:

I am unable to read C++, could you explain your solution
Lol, what language can you read then?

Well first of all I have to say that the main solution is suppose to run in O(N) time but because of the extra input I have to deal with that is the while(n--) it makes it O(N²)

Now for the inner loop it's simple let's say you have the number 1234 if you find the modular of that number using 10 that is 1234 mod 10 you would get 4. After that you divide 1234 by 10 again then you get 123 and then you find the mod, this process goes on in a loop till that inner condition in the loop is met while(n >=1).
Re: Thread For Nairaland Algorithm Questions by Donpre(m): 9:00pm On Jan 21, 2021
Deicide:
Lol, what language can you read then?

Well first of all I have to say that the main solution is suppose to run in O(N) time but because of the extra input I have to deal with that is the while(n--) it makes it O(N²)

Now for the inner loop it's simple let's say you have the number 1234 if you find the modular of that number using 10 that is 1234 mod 10 you would get 4. After that you divide 1234 by 10 again then you get 123 and then you find the mod, this process goes on in a loop till that inner condition in the loop is met while(n >=1).

I get this part.

But does your solution solve the scenario where the first digit to be inversed is '0'?

e.g 09787 becomes 78790
Re: Thread For Nairaland Algorithm Questions by Phelumie300: 9:14pm On Jan 21, 2021
cixak95211:
Question:

1. Design an algorithm(s) for the following array operations: "push, pop, shift, unshift" using object oriented programming practices.
2. Design an algorithm that will find the longest common subsequence between two arrays, plus the time complexity for your solution.

well this is my entry.

As for the time complexity grin grin

1 Like

Re: Thread For Nairaland Algorithm Questions by cbrass(m): 10:31pm On Jan 21, 2021
qtguru:


I'll share soon

https://www.linkedin.com/groups/8873861

Thanks bro , it has been awhile. never knew you changed your moniker. There a lot of old-time-coders i don't see here anymore. i hope they are all doing fine sha
Re: Thread For Nairaland Algorithm Questions by qtguru(m): 10:33pm On Jan 21, 2021
cbrass:


Thanks bro , it has been awhile. never knew you changed your moniker. There a lot of old-time-coders i don't see here anymore. i hope they are all doing fine sha

Yeah qtguru is my name on twitter so this was an opportunity to delete that moniker and focus on tech mostly. We are still here do you do Node because there is a project on ground.
Re: Thread For Nairaland Algorithm Questions by cbrass(m): 10:55pm On Jan 21, 2021
qtguru:


Yeah qtguru is my name on twitter so this was an opportunity to delete that moniker and focus on tech mostly. We are still here do you do Node because there is a project on ground.

Ha..Thank you very brother cheesy, but i don't it is Angular and PHP i do, just trying my hands on Vue now
Re: Thread For Nairaland Algorithm Questions by cbrass(m): 11:00pm On Jan 21, 2021
but if the project is not too advanced i can give it a try . wink
Re: Thread For Nairaland Algorithm Questions by cixak95211: 12:19am On Jan 22, 2021
Karleb:


For question 1, are slice and splice functions allowed?

Nope
Re: Thread For Nairaland Algorithm Questions by Karleb(m): 1:28am On Jan 22, 2021

Re: Thread For Nairaland Algorithm Questions by Deicide: 1:52am On Jan 22, 2021
Donpre:


I get this part.

But does your solution solve the scenario where the first digit to be inversed is '0'?

e.g 09787 becomes 78790
That's not a number in any programming language I know of.....numbers don't start with zero....if you think am lying create a variable and assign it 09787 and see if it'll compile
Re: Thread For Nairaland Algorithm Questions by Jummate(m): 6:02am On Jan 22, 2021
cixak95211:
Question:

1. Design an algorithm(s) for the following array operations: "push, pop, shift, unshift" using object oriented programming practices.
2. Design an algorithm that will find the longest common subsequence between two arrays, plus the time complexity for your solution.

For number 1

Re: Thread For Nairaland Algorithm Questions by Brukx(m): 6:20am On Jan 22, 2021
Deicide:
That's not a number in any programming language I know of.....numbers don't start with zero....if you think am lying create a variable and assign it 09787 and see if it'll compile
It's not an integer, but it's definitely a number.
Re: Thread For Nairaland Algorithm Questions by Karleb(m): 9:48am On Jan 22, 2021
Jummate:


For number 1

Hey man, I love your input but when you make an array item null, or undefined or you delete it using the delete keyword it does not remove the item.

If you print out the array, you'd still see undefined/null in the array and the array length is still will still include the missing values.

Trying printing out the array to understand what I'm talking about.
Re: Thread For Nairaland Algorithm Questions by Karleb(m): 9:49am On Jan 22, 2021
Phelumie300:

well this is my entry.
As for the time complexity grin grin

Look at how sexy Java is. shocked
Re: Thread For Nairaland Algorithm Questions by cbrass(m): 10:04am On Jan 22, 2021
Write a function Priority Queue that priotizies node target
eg

function prioritize_nodes($tree, $target_val) {
}


Hint: The target node will move up even if is in a child node.
Re: Thread For Nairaland Algorithm Questions by cixak95211: 10:38am On Jan 22, 2021
Jummate:


For number 1

Very nice.
The push method will always return the new length . . so there is no need put it inside in a branch
thus causing you to have multiple return statements which do exactly the same thing. You could do your conditionals
and then return the increased length at the end of the ops.

Plus it's perfectly okay to have [undefined, 3, undefined] in an array, exactly as Karleb as pointed out. Doesn't make the array house 1 item as you might have thought but rather 3.

I would use your codes anyday anytime. It's clean.

1 Like

Re: Thread For Nairaland Algorithm Questions by Springboot: 11:29am On Jan 22, 2021
Karleb:



Look at how sexy Java is. shocked

That's why I prefer it to python, clean codes, I hate the indentation in python.
Re: Thread For Nairaland Algorithm Questions by Karleb(m): 2:14pm On Jan 22, 2021
cbrass:
Write a function Priority Queue that priotizies node target
eg

function prioritize_nodes($tree, $target_val) {
}


Hint: The target node will move up even if is in a child node.

Please explain this hint more.

It seems you want a deeper level of PQ. as in, a PQ in a PQ in a PQ... undecided
Re: Thread For Nairaland Algorithm Questions by Jummate(m): 5:02pm On Jan 22, 2021
Karleb:


Hey man, I love your input but when you make an array item null, or undefined or you delete it using the delete keyword it does not remove the item.

If you print out the array, you'd still see undefined/null in the array and the array length is still will still include the missing values.

Trying printing out the array to understand what I'm talking about.

Thank you bro.

Yes, you are very correct. This was the reason I overrode the length property of the original array with my own defined length property.

This way, I had total control over that property although "undefined" would definitely still appear within the array.

Besides, JavaScript fills in empty spaces within an array with undefined value. The redefined length property in the code works according to plan within the code


Take a look at these two: the code and the ouput

Re: Thread For Nairaland Algorithm Questions by Jummate(m): 5:06pm On Jan 22, 2021
Karleb:


Hey man, I love your input but when you make an array item null, or undefined or you delete it using the delete keyword it does not remove the item.

If you print out the array, you'd still see undefined/null in the array and the array length is still will still include the missing values.

Trying printing out the array to understand what I'm talking about.

Sorry for quoting you twice bro, I wish I knew how I could upload images stacked on each other here.


Here is the second image:

Re: Thread For Nairaland Algorithm Questions by Jummate(m): 5:11pm On Jan 22, 2021
cixak95211:


Very nice.
The push method will always return the new length . . so there is no need put it inside in a branch
thus causing you to have multiple return statements which do exactly the same thing. You could do your conditionals
and then return the increased length at the end of the ops.

Plus it's perfectly okay to have [undefined, 3, undefined] in an array, exactly as Karleb as pointed out. Doesn't make the array house 1 item as you might have thought but rather 3.

I would use your codes anyday anytime. It's clean.

Thank you bro.

I didn't know push() also returns the new length of an array. I used to think only unshift() does that.

Thanks for pointing this out. Points well taken.
Re: Thread For Nairaland Algorithm Questions by cixak95211: 12:18am On Jan 23, 2021
Jummate:


Sorry for quoting you twice bro, I wish I knew how I could upload images stacked on each other here.


Here is the second image:


1 2 3 4 images

Re: Thread For Nairaland Algorithm Questions by lahp(m): 1:05am On Jan 23, 2021
Phelumie300:


well this is my entry.

As for the time complexity grin grin


bro array sizes can never be floats

stop checking if an array is <0

i also think u are to return the new length of array

u should check ur array keys
it says if the key is zero increase the key and add item

have u forgotten an array is indexed from zero?
Re: Thread For Nairaland Algorithm Questions by lahp(m): 1:22am On Jan 23, 2021
Jummate:


Sorry for quoting you twice bro, I wish I knew how I could upload images stacked on each other here.


Here is the second image:


i like wat u did with for loop the conditons are perfect

have u tried how much time it will take
Re: Thread For Nairaland Algorithm Questions by Jummate(m): 6:36am On Jan 23, 2021
cixak95211:


1 2 3 4 images

I tried it this way, it didn't work as wanted. Only one of the images was uploaded. This was I had to quote Karleb twice.

Thank you for responding though.
Re: Thread For Nairaland Algorithm Questions by Jummate(m): 6:44am On Jan 23, 2021
lahp:


i like wat u did with for loop the conditons are perfect

have u tried how much time it will take

Thanks bro.

I haven't tested how much time it would take but also I think this depends on a few things like the processor, busy status of the processor etc

Although, the complexity is surely O(n)
Re: Thread For Nairaland Algorithm Questions by naijasensei: 2:23pm On Jan 23, 2021
Karleb:
Question. Write a function that determines if a word is a palindrome.

Hint: Palindromes are words that has same spelling backward and forward.

E.g madam, racecar.

1. Kotlin
2. Python

Re: Thread For Nairaland Algorithm Questions by naijasensei: 2:32pm On Jan 23, 2021
cixak95211:
Question:

1. Design an algorithm(s) for the following array operations: "push, pop, shift, unshift" using object oriented programming practices.
2. Design an algorithm that will find the longest common subsequence between two arrays, plus the time complexity for your solution.

Question 1 only:
1. Kotlin
2. Kotlin (continued)
3. Javascript

Re: Thread For Nairaland Algorithm Questions by cixak95211: 6:00pm On Jan 23, 2021
naijasensei:


Question 1 only:
1. Kotlin
2. Kotlin (continued)
3. Javascript

* push
line 23 is not necessary
as you can return the increased length on line 22.

* unshift
line 42 is not necessary
as you can directly assign this.stack to [value, ...this.stack]

depending on some school of thought, it's best to outline each line seperately,
but you'd be wasting memory declaring variables that are really not necessary
a smart code editor e.g. any of the JetBrains family, would have also warned you about it.

Its amazing we have smart minds here, so why did y'all allow this place to be overran
by some "website for 20k" minds?

2 Likes

(1) (2) (3) (4) (5) (Reply)

Software Companies In Nigeria / Matlab: A Program For Mathematicians? / Retrieving/selecting A Particular Number Of Random Rows From A Database Table

Viewing this topic: 1 guest(s)

(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. 49
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.